public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication app = commandData.Application;
UIDocument uidoc = app.ActiveUIDocument;
Document doc = uidoc.Document;
//Element column = null;
//Selection sel = uidoc.Selection;
//
//if( 1 == sel.GetElementIds().Count )
//{
// foreach( Element e in sel.Elements )
// {
// column = e;
// }
// if( !IsColumn( column ) )
// {
// column = null;
// }
//}
//
//if( null == column )
//{
//
//#if _2010
// sel.Elements.Clear();
// sel.StatusbarTip = "Please select a column";
// if( sel.PickOne() )
// {
// ElementSetIterator i
// = sel.Elements.ForwardIterator();
// i.MoveNext();
// column = i.Current as Element;
// }
//#endif // _2010
//
// Reference r = uidoc.Selection.PickObject( ObjectType.Element,
// "Please select a column" );
//
// if( null != r )
// {
// // 'Autodesk.Revit.DB.Reference.Element' is
// // obsolete: Property will be removed. Use
// // Document.GetElement(Reference) instead.
// //column = r.Element; // 2011
//
// column = doc.GetElement( r ); // 2012
//
// if( !IsColumn( column ) )
// {
// message = "Please select a single column instance";
// }
// }
//}
Result rc = Result.Failed;
Element column = Util.SelectSingleElementOfType(
uidoc, typeof( FamilyInstance ), "column", true );
if( null == column || !IsColumn( column ) )
{
message = "Please select a single column instance";
}
else
{
Options opt = app.Application.Create.NewGeometryOptions();
GeometryElement geo = column.get_Geometry( opt );
GeometryInstance i = null;
//GeometryObjectArray objects = geo.Objects; // 2012
//foreach( GeometryObject obj in objects ) // 2012
foreach( GeometryObject obj in geo ) // 2013
{
i = obj as GeometryInstance;
if( null != i )
{
break;
}
}
if( null == i )
{
message = "Unable to obtain geometry instance";
}
else
{
bool isCylindrical = false;
geo = i.SymbolGeometry;
//objects = geo.Objects; // 2012
//foreach( GeometryObject obj in objects ) // 2012
foreach( GeometryObject obj in geo )
{
Solid solid = obj as Solid;
if( null != solid )
{
foreach( Face face in solid.Faces )
{
if( face is CylindricalFace )
{
isCylindrical = true;
break;
}
}
}
}
message = string.Format(
"Selected column instance is{0} cylindrical",
( isCylindrical ? "" : " NOT" ) );
}
rc = Result.Succeeded;
}
return rc;
}