Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Loop Cad Elements

14 REPLIES 14
Reply
Message 1 of 15
sanjaymann
851 Views, 14 Replies

Loop Cad Elements

Hi,

 

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

 

Thanks & Regards

14 REPLIES 14
Message 2 of 15
atiefenbach
in reply to: sanjaymann

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
Message 3 of 15
sanjaymann
in reply to: sanjaymann

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

Message 4 of 15
atiefenbach
in reply to: sanjaymann

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
Message 5 of 15
sanjaymann
in reply to: atiefenbach

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.

Message 6 of 15
R.van.den.Bor
in reply to: sanjaymann

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

Kind regards,
Remy van den Bor
ICN Solutions B.V.
Liked this post or found it usefull, don't forget the Kudo It won't hurt (at least not me).
Message 7 of 15
sanjaymann
in reply to: R.van.den.Bor

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.

Message 8 of 15
R.van.den.Bor
in reply to: sanjaymann

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.
Kind regards,
Remy van den Bor
ICN Solutions B.V.
Liked this post or found it usefull, don't forget the Kudo It won't hurt (at least not me).
Message 9 of 15
sanjaymann
in reply to: R.van.den.Bor

Auto-Center to center

Message 10 of 15
R.van.den.Bor
in reply to: sanjaymann

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.
Kind regards,
Remy van den Bor
ICN Solutions B.V.
Liked this post or found it usefull, don't forget the Kudo It won't hurt (at least not me).
Message 11 of 15
sanjaymann
in reply to: R.van.den.Bor

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.

Message 12 of 15
sanjaymann
in reply to: R.van.den.Bor

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.

Message 13 of 15
atiefenbach
in reply to: R.van.den.Bor

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
Message 14 of 15
sanjaymann
in reply to: atiefenbach

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.

Message 15 of 15
sanjaymann
in reply to: sanjaymann

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community