public void EmitPipeData(DataNode data) { try { _receivedObjects = new List <object>(); if (data == null) { return; } foreach (var child in data.ChildrenList) { var converted = PipeForRevit.ConvertFromPipe(child.Data); if (converted.GetType().IsArray) { foreach (var obj in (Array)converted) { _receivedObjects.Add(obj); } } else { _receivedObjects.Add(converted); } } } catch (PipeDataModel.Exceptions.PipeConversionException e) { RevitPipeUtil.ShowMessage("Pipe Pull Failed!", "Conversion Error - Unsupported Types", e.Message + "\nPlease try bringing this geometry as one of the supported types, or try bringing it via Dynamo since ThePipe extension" + "for Dynamo supports more types than the revit add-in."); } }
private List <ElementId> AddObjectsToDocument(List <object> objs, bool deleteExisting = false) { List <ElementId> elems = new List <ElementId>(); _previousRefs = new List <Reference>(); Transaction trans = new Transaction(_document); trans.Start("pipe_pull"); if (deleteExisting) { List <ElementId> _oldStuff = _previousIds.Where((id) => _document.GetElement(id) != null).ToList(); _document.Delete(_oldStuff); } foreach (var geom in _receivedObjects) { if (typeof(Curve).IsAssignableFrom(geom.GetType())) { Reference geomRef; elems.Add(RevitPipeUtil.AddCurveToDocument(ref _document, (Curve)geom, out geomRef)); _previousRefs.Add(geomRef); } if (typeof(Mesh).IsAssignableFrom(geom.GetType())) { //now add the mesh elems.Add(RevitPipeUtil.AddMeshToDocument(ref _document, (Mesh)geom)); } } trans.Commit(); return(elems); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { string pipeId = PipeForRevit.PipeIdentifier; UIApplication uiApp = commandData.Application; _document = uiApp.ActiveUIDocument.Document; PipeForRevit.ActiveDocument = uiApp.ActiveUIDocument.Document; Selection sel = uiApp.ActiveUIDocument.Selection; Pipe pipe = null; Action callBack = () => { if (pipe != null) { pipe.ClosePipe(); } RevitPipeUtil.ShowMessage("Success", "Pushed data to the pipe."); }; if (PipeDataUtil.IsValidUrl(pipeId)) { pipe = new MyWebPipe(pipeId, callBack); } else { pipe = new LocalNamedPipe(pipeId, callBack); } pipe.SetEmitter(this); pipe.Update(); if (GeometryTypeMatch()) { bool deleteExisting; bool updateGeom = UserDecidedToUpdateGeometry(out deleteExisting); if (updateGeom) { UpdateGeometry(_receivedObjects); } else { _previousIds = AddObjectsToDocument(_receivedObjects, deleteExisting); } } else { _previousIds = AddObjectsToDocument(_receivedObjects, false); } return(Result.Succeeded); } catch (Exception e) { RevitPipeUtil.ShowMessage("Error", "The following error occured. Aborting operation.", e.Message); return(Result.Failed); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { string pipeId = PipeForRevit.PipeIdentifier; UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; PipeForRevit.ActiveDocument = uiApp.ActiveUIDocument.Document; Selection sel = uiApp.ActiveUIDocument.Selection; //List<Reference> pickedCurves = sel.PickObjects(ObjectType.Edge, "Select the curves to send through the pipe or click finish to select" + // "elements").ToList(); List <Reference> picked = sel.PickObjects(ObjectType.Element, "Select the elements to send through the pipe").ToList(); _selectedObjects = new List <GeometryObject>(); Options opt = new Options(); foreach (var objRef in picked) { GeometryElement geom = doc.GetElement(objRef).get_Geometry(opt); _selectedObjects.AddRange(geom.Where((g) => g is Solid || g is Mesh)); } //foreach (var objRef in pickedCurves) //{ // Edge edge = (Edge)doc.GetElement(objRef).GetGeometryObjectFromReference(objRef); // _selectedObjects.Add(edge); //} Pipe pipe = null; Action callBack = () => { if (pipe != null) { pipe.ClosePipe(); } RevitPipeUtil.ShowMessage("Success", "Pushed data to the pipe."); }; if (PipeDataUtil.IsValidUrl(pipeId)) { pipe = new MyWebPipe(pipeId, callBack); } else { pipe = new LocalNamedPipe(pipeId, callBack); } pipe.SetCollector(this); pipe.Update(); return(Result.Succeeded); } catch (Exception e) { RevitPipeUtil.ShowMessage("Error", "The following error occured. Aborting operation.", e.Message); return(Result.Failed); } }