有时间再研究,先记录下来。
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class CreateSpace : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
try
{
Transaction ts = new Transaction(uiDoc.Document, " space " );
ts.Start();
// Level
Level level = null ;
FilteredElementIterator levelsIterator = ( new FilteredElementCollector(uiDoc.Document)).OfClass( typeof (Level)).GetElementIterator();
levelsIterator.Reset();
while (levelsIterator.MoveNext())
{
level = levelsIterator.Current as Level;
break ;
}
// Phase面域
Parameter para = uiDoc.Document.ActiveView.get_Parameter(BuiltInParameter.VIEW_PHASE);
ElementId phaseId = para.AsElementId();
Phase phase = uiDoc.Document.get_Element(phaseId) as Phase;
if (phase == null )
{
System.Windows.Forms.MessageBox.Show( " The phase of the active view is null, you can't create spaces in a null phase " );
}
// CreateSpace
if (uiDoc.Document.ActiveView.ViewType == ViewType.FloorPlan)
{
uiDoc.Document.Create.NewSpaces(level, phase, uiDoc.ActiveView);
}
else
{
System.Windows.Forms.MessageBox.Show( " You can not create spaces in this plan view " );
}
ts.Commit();
}
catch (Exception ex)
{
TaskDialog.Show( " ex " , ex.ToString());
}
return Result.Succeeded;
}
}
[Regeneration(RegenerationOption.Manual)]
public class CreateSpace : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
try
{
Transaction ts = new Transaction(uiDoc.Document, " space " );
ts.Start();
// Level
Level level = null ;
FilteredElementIterator levelsIterator = ( new FilteredElementCollector(uiDoc.Document)).OfClass( typeof (Level)).GetElementIterator();
levelsIterator.Reset();
while (levelsIterator.MoveNext())
{
level = levelsIterator.Current as Level;
break ;
}
// Phase面域
Parameter para = uiDoc.Document.ActiveView.get_Parameter(BuiltInParameter.VIEW_PHASE);
ElementId phaseId = para.AsElementId();
Phase phase = uiDoc.Document.get_Element(phaseId) as Phase;
if (phase == null )
{
System.Windows.Forms.MessageBox.Show( " The phase of the active view is null, you can't create spaces in a null phase " );
}
// CreateSpace
if (uiDoc.Document.ActiveView.ViewType == ViewType.FloorPlan)
{
uiDoc.Document.Create.NewSpaces(level, phase, uiDoc.ActiveView);
}
else
{
System.Windows.Forms.MessageBox.Show( " You can not create spaces in this plan view " );
}
ts.Commit();
}
catch (Exception ex)
{
TaskDialog.Show( " ex " , ex.ToString());
}
return Result.Succeeded;
}
}