Hi,
I have a linked cad file with blocks in revit. How do I loop all these blocks using revit api.
Thanks & Regards
I wanted to do something like this before and I was told by @jeremytammik that you'd have to launch AtuoCAD from your add-in and go through them that way. Here's his blog to that: http://thebuildingcoder.typepad.com/blog/2013/04/launching-autocad-within-a-revit-add-in.html
However, that was a bit over my head at the time, so I decided to use DATAEXTRACTION within AutoCAD first to export the CAD data into a TAB delimited txt file, which I then read with my Revit add-in using a StreamReader.
I successfully "converted" my CAD blocks to Revit families, including copying the the attributes to parameters and rotating the families to the correct orientation.
Even if i read the x,y,z form autocad they won't serve the purpose because the x,y,z that I get in Autocad is entirely different in revit say for example for a block x,y,z in autocad are X=1841.1889 Y=1843.3123 Z= 0.0000 but for the same block in revit its X=187.577361553139 Y=154.246439927836 Z= 0.0000.
But if I could transform the autocad x,y,z to revit x,y,z then maybe I could try for some other way round. There is a transform class in revit but I am unable to apprehend how to use it convert autocad x,y,z to revit x,y,z.
Revit does have a projects x,y,z 0,0,0 point.
ProjectLocation plCurrent = CurrDocument.Document.ActiveProjectLocation; //this is the current 0,0,0 point
ProjectPosition newPosition = new ProjectPosition(10,10,0,0); //here you can move this point and even rotate it if you like 🙂
XYZ CurrPosition = new XYZ(plCurrent.GetTransform().Origin.X, plCurrent.GetTransform().Origin.Y, plCurrent.GetTransform().Origin.Z);
plCurrent.set_ProjectPosition(CurrPosition, newPosition);
Maybe this helps..
The soultion suggested by R.van.den.Bor converts every xyz to 000.no matter what. Let me explain again I have a block in autocad whose x,y,z are X=1841.1889 Y=1843.3123 Z= 0.0000 when I link that dwg in revit and find its xyz I should not get 0,0,0 but the actual x,y where its in revit.
No luck. Another way I am trying to do is that I am looping the elements of linked dwg and when I encounter a Solid while looping and I try to get its centroid via Solid.ComputeCentroid() it fails in doing so.
Its so frustaring all I want is to get the centroid of linked dwg blocks and unable to do so. Feeling tired.
Not going right. Is it so difficult to loop linked cad elements[blocks] and find their centroids. I feel I should give it a miss.
Ok here goes. For simplicity I drew a simple circle in a dwg. I linked that dwg in revit[origin to origin]. The centroid that i am getting in revit is different than autocad. for tetsing purpose I took the autocad circle's center x,y and using those placed an instance of a tree family . The tree didn;t fell on the circle's centroid it was out of the circle.