start
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
cmd : IExternalCommand
{
GetPath(List<> listPath, strKey)
{
( strPath listPath)
{
(strPath.Contains(strKey))
strPath;
}
;
}
Result Execute(ExternalCommandData cmdData, msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
UIApplication uiApp = cmdData.Application;
Document doc = uiDoc.Document;
Selection selection = uiDoc.Selection;
Transaction ts = Transaction(doc, );
ts.Start();
FilteredElementCollector collector = FilteredElementCollector(doc); collector.OfClass((Instance)).OfCategory(BuiltInCategory.OST_RvtLinks); List<> listPath = GetLinkFilePaths(doc);
(Element elDoc collector)
{
Instance ins = elDoc Instance;
(ins != )
{
Transform transForm = ins.GetTransform();
strKey = elDoc.Name.Substring(, elDoc.Name.IndexOf()); Document docLink = uiApp.Application.OpenDocumentFile(GetPath(listPath, strKey));
FilteredElementCollector collectorLink = FilteredElementCollector(docLink);
collectorLink.OfCategory(BuiltInCategory.OST_Rooms);
(Element el collectorLink)
{
Room room = el Room;
LocationPoint roomPoint = room.Location LocationPoint;
UV uv = UV();
(room.Location != )
{
uv = UV(roomPoint.Point.X + transForm.Origin.X, roomPoint.Point.Y + transForm.Origin.Y);
}
doc.Create.NewSpace(room.Level, uv);
}
}
}
ts.Commit();
Result.Succeeded;
}
List<> GetLinkFilePaths(Document doc)
{
List<> listPath = List<>();
(ElementId elId ExternalFileUtils.GetAllExternalFileReferences(doc))
{
(doc.get_Element(elId).IsExternalFileReference())
{
ExternalFileReference fileRef = doc.get_Element(elId).GetExternalFileReference();
( == fileRef.ExternalFileReferenceType.ToString())
listPath.Add(ModelPathUtils.ConvertModelPathToUserVisiblePath(fileRef.GetAbsolutePath()));
}
}
listPath;
}
}url:http://greatverve.cnblogs.com/p/revit-create-space.html