Loop Cad Elements

Loop Cad Elements

Anonymous
Not applicable
1,373 Views
14 Replies
Message 1 of 15

Loop Cad Elements

Anonymous
Not applicable

Hi,

 

I have a linked cad file with blocks in revit. How do I loop all these blocks using revit api.

 

Thanks & Regards

0 Likes
1,374 Views
14 Replies
Replies (14)
Message 2 of 15

atiefenbach
Advocate
Advocate

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.

Anthony Tiefenbach
BIM Manager
HuntonBrady Architects
0 Likes
Message 3 of 15

Anonymous
Not applicable

My only objective is to loop the blocks to find their x,y,z centroid.

0 Likes
Message 4 of 15

atiefenbach
Advocate
Advocate
All blocks, or only certain blocks? If it's all blocks, then you might have to run AutoCAD inside Revit and then postcommand a DATAEXTRACTION, then have revit read that extraction. If it's certain blocks you might be able to use postcommand to select those blocks and then cycle through that selection to get their x,y,z.
Anthony Tiefenbach
BIM Manager
HuntonBrady Architects
0 Likes
Message 5 of 15

Anonymous
Not applicable

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.

0 Likes
Message 6 of 15

Anonymous
Not applicable

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..

0 Likes
Message 7 of 15

Anonymous
Not applicable

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.

0 Likes
Message 8 of 15

Anonymous
Not applicable
How are you placing the dwg link ? There are several options like origing to origin ect. these affect the way a drawing is placed in the revit project.
0 Likes
Message 9 of 15

Anonymous
Not applicable

Auto-Center to center

0 Likes
Message 10 of 15

Anonymous
Not applicable
okay, you should use auto - origin to origin. When you use the lightbulb in revit to show all, you will see the project base point of revit.
0 Likes
Message 11 of 15

Anonymous
Not applicable

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.

0 Likes
Message 12 of 15

Anonymous
Not applicable

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.

0 Likes
Message 13 of 15

atiefenbach
Advocate
Advocate
If you do Origin-to-Origin, then the xyz is identical in Revit as it is in AutoCAD. The only transformation you then have to do is make sure your converting the AutoCAD units to Revit units. I use Imperial and so my AutoCAD was in inches and Revit is in feet, so it was a matter of Revit_x= AutoCAD_x / 12, etc..
Anthony Tiefenbach
BIM Manager
HuntonBrady Architects
0 Likes
Message 14 of 15

Anonymous
Not applicable

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.

0 Likes
Message 15 of 15

Anonymous
Not applicable

Sorry. forgot to mention both autocad and revit are in inches.

0 Likes