Start
[Transaction (TransactionMode. Manual)]
[Regeneration (RegenerationOption. Manual)]
Cmd: IExternalCommand
{
GetPath (List <> listPath, strKey)
{
(StrPath listPath)
{
(StrPath. Contains (strKey ))
StrPath;
}
;
}
Result Execute (ExternalCommandData upload data, msg, ElementSet elements)
{
UIDocument uiDoc = upload data. Application. ActiveUIDocument;
UIApplication uiApp = response data. 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