What I’m trying to achive is to get location of some Cad blocks from a Cad file inserted as a link in Revit.
Right now, I’m using an Excel file got from AutoCad and then I use dynamo to insert a family instance by point.
I would like sth without using Excel, because those Cad blocks have geometry parameters with the location, so if I could read them, it’s gonna be faster than create an Excel file and…
I’ve tried with ActiveX package ans DynamoCad package, but nothing works.
If so, here is the python script to get the origin of a CAD import.
import clr
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
#Custom tolist definition provided by Dimitar Venkov
#https://github.com/dimven/SpringNodes
def tolist(x):
if hasattr(x,'__iter__'): return x
else : return [x]
#unwrap all elements to use with API
items = tolist(UnwrapElement(IN[0]))
#lists to append results to
locations = list()
#iterate through the cad imports
for i in items:
transform = i.GetTotalTransform()
locations.append(transform.Origin.ToPoint())
#Assign your output to the OUT variable
OUT = locations
As you can see, there are some blocks in the same cad. They are some ligthing fixture, each block has a geometry with the location, so, I just need to read them in order to set my objects in Revit.
@john_pierson
I would need to know the location of blocks inside the Cad file instead of the origin of a cad file.
I would need to find for each block named “blablabla” the location “XYZ”.
[quote=“MOJTABA256, post:12, topic:22538, full:true”]
Thanks John for your solution but unfortunately it doesn’t work for me your python script. I imported the CAD geometry (for lighting fixtures) in Revit and tried to use your code but it didn’t work. I want to replace them with a lighting fixture Revit Family, but the script couldn’t find the CAD blocks coordinates. Could u please help me to solve this solution? Thanks
Thanks Alban. It helped a lot. But when I ran the script I saw that the direction of my Revit elements are not correct according to the angle of my CAD Blocks as shown below.
I did a simple model to test from the scratch. I opened a new Revit file, placed some lighting fixtures, exported it as DWG, and then opened a new Revit project (ELEC Template), imported the DWG file, and ran the script. They are still OFF although, as shown below, the location coordinates of CAD Blocks and Revit Elements are the same.
Double check the origin of your fixture family. It is not possible that there is an offset with identical location coordinates unless the origins of CAD block and family are different.
It is working fine with the french Revit Electrical template.