Selecting CAD Lines

Selecting CAD Lines

atiefenbach
Advocate Advocate
3,687 Views
3 Replies
Message 1 of 4

Selecting CAD Lines

atiefenbach
Advocate
Advocate

I'm trying to create an add-in where the user is given the option to select a line within a CAD file.  I assume the first step is having them select which CAD file (which I've done), but now that the CAD file is selected, how do I access all it's geometry to all them to be able to select a line within it?

 

Thanks!

Anthony Tiefenbach
BIM Manager
HuntonBrady Architects
0 Likes
3,688 Views
3 Replies
Replies (3)
Message 2 of 4

Joe.Ye
Alumni
Alumni
Hi

Revit didn't expose the API to allow end users to pick elements within imported/linked dwg file. Before Revit 2014, Revit didn't expose the API to pick elements within linked Rvt model. From Revit 2014, PickObject() and PickObjects() now allow selection of elements in RVT Links.

As a workaround, you can pick the target import instance. Then you can loop all the sub-elements in the linked dwg and test which sub-elements in the DWG is picked.

Via the ImportInstance.Geometry() method, you can get all the visible elements in the dwg. Then loop all these sub-elements and test if the pick point hits any lines, arcs.....

From the sub-elements retrieved from Geometry property, you may not get all the sub-elements' property. So there may be some properties you cannot get.


Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 4

atiefenbach
Advocate
Advocate

Thanks for your reply.  I understand what you're saying, but unfortunaly, I'm not familiar enough with the API to be able to figure this one out on my own.


@Joe.Ye wrote:
Via the ImportInstance.Geometry() method, you can get all the visible elements in the dwg. Then loop all these sub-elements and test if the pick point hits any lines, arcs..... 

If I used PickPoint() to have them pick a point, how would I determine what line, arc,etc., it is on?  Would it be better to use PickObject(ObjectType.PointOnElement)?

 

Thanks!

Anthony Tiefenbach
BIM Manager
HuntonBrady Architects
0 Likes
Message 4 of 4

Joe.Ye
Alumni
Alumni

Hi

You can use the PickPoint() method to get a point coordinates. Then determine which object within the dwg file is under the picked point.

The following code shows how to get the coordinates of objects within dwg file.

 

<code>
using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

 

using Autodesk.Revit .DB;

using Autodesk.Revit.UI;

using Autodesk.Revit .ApplicationServices;

using Autodesk.Revit.Attributes ;

using Autodesk.Revit.UI.Selection;

 

 

[TransactionAttribute(TransactionMode.Manual)]

public class RevitCommand : IExternalCommand

{

public Result Execute(ExternalCommandData commandData,

ref string messages, ElementSet elements)

{

 

UIApplication app = commandData.Application;

Document doc = app.ActiveUIDocument.Document;

 

Autodesk.Revit.UI.Selection.Selection sel = app.ActiveUIDocument.Selection;

Reference ref1 = sel.PickObject(ObjectType.Element, "please pick an import instance");

ImportInstance dwg = doc.GetElement(ref1) as ImportInstance;

if (dwg == null)

return Result.Failed;

 

Options opt = new Options();

Transform transf = null;

string output = null;

foreach (GeometryObject geoObj in dwg.get_Geometry(opt))

{

if (geoObj is GeometryInstance)

{

GeometryInstance inst = geoObj as GeometryInstance;

transf = inst.Transform;

 

foreach (GeometryObject geoObj2 in inst.SymbolGeometry)

{

if (geoObj2 is Line)

{

//get the revit model coordinates.

Line l = geoObj2 as Line;

XYZ ptStartInRevit = transf.OfPoint(l.get_EndPoint(0));

XYZ ptEndInRevit = transf.OfPoint(l.get_EndPoint(1));

 

}

else if (geoObj2 is Arc)

{

Arc a = geoObj2 as Arc;

XYZ ptCenterInRevit = transf.OfPoint(a.Center);

output += "Center = " + ptCenterInRevit.X.ToString()

+ "; " + ptCenterInRevit.Y.ToString() + "; "

+ ptCenterInRevit.Z.ToString() + "\r\n";

}

else

{

// And so on using the same way to convert

// coordinate system of the Revit model.

}

}

 

}

}

 

TaskDialog.Show("center of circle/arc", output);

return Result.Succeeded ;

}

}

<code>

 

 

PickObject() method cannot be used to pick objects in Imported/linked DWG files.



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
0 Likes