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