Revit二次开发之“创建空间Newspace”
这里涉及到一些专业知识,没有成功,但是代码是从示例中取出来的,示例可以创建空间。
有时间再研究,先记录下来。
from:http://revit.5d6d.com/thread-1252-1-1.html
有时间再研究,先记录下来。
[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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。