static public GeometryBase ToRhino(this _OdDb.ObjectId id) { if (DatabaseUtils.IsCurve(id)) { using (var dbCurve = id.GetObject(_OdDb.OpenMode.ForRead) as _OdDb.Curve) { var geometry = dbCurve?.ToRhino(); if (geometry != null) { return(geometry); } } } string tmpPath = Path.Combine(Path.GetTempPath(), "BricsCAD", "torhino.3dm"); using (var aId = new _OdDb.ObjectIdCollection() { id }) { if (_OdRx.ErrorStatus.OK != Bricscad.Rhino.RhinoUtilityFunctions.ExportRhinoFile(aId, tmpPath)) { return(null); } } return(ExtractGeometryFromFile(tmpPath)); }
public static void ToGrasshopper() { if (GhDrawingContext.LinkedDocument == null && Application.DocumentManager.MdiActiveDocument != GhDrawingContext.LinkedDocument) { return; } var editor = Application.DocumentManager.MdiActiveDocument.Editor; var ghDoc = Grasshopper.Instances.ActiveCanvas.Document; if (ghDoc == null) { editor.WriteMessage("No active gh document\n"); return; } var pso = new PromptSelectionOptions(); pso.AllowSubSelections = true; var selection = editor.GetSelection(pso); if (selection.Status != PromptStatus.OK) { return; } var selectedObjects = new List <FullSubentityPath>(); for (int i = 0; i < selection.Value.Count; ++i) { var subents = selection.Value[i].GetSubentities(); if (subents != null) { foreach (var subent in subents) { selectedObjects.Add(subent.FullSubentityPath); } } else { selectedObjects.Add(new FullSubentityPath(new ObjectId[] { selection.Value[i].ObjectId }, new SubentityId(SubentityType.Null, 0))); } } if (selectedObjects.Count == 0) { return; } var type = selectedObjects[0].SubentId.Type; bool theSameType = selectedObjects.All(fsp => fsp.SubentId.Type == type); if (!theSameType) { editor.WriteMessage("Mixed selection set is not allowed\n"); return; } IGH_GeometryBcParam monitor = null; switch (type) { case SubentityType.Null: bool isCurve = selectedObjects.All(fsp => DatabaseUtils.IsCurve(fsp.InsertId())); if (isCurve) { monitor = new BcCurve(); } else { monitor = new BcEntity(); } break; case SubentityType.Face: monitor = new Parameters.Face(); break; case SubentityType.Edge: monitor = new Parameters.Edge(); break; case SubentityType.Vertex: monitor = new Parameters.Vertex(); break; } if (monitor == null) { return; } monitor.InitBy(selectedObjects, GhDrawingContext.LinkedDocument.Name); var ghDocObj = (Grasshopper.Kernel.GH_DocumentObject)monitor; if (ghDocObj != null) { var bounds = Grasshopper.Instances.ActiveCanvas.Viewport.VisibleRegion; ghDocObj.CreateAttributes(); ghDocObj.Attributes.Selected = true; ghDocObj.Attributes.Pivot = new PointF(bounds.Left + ghDocObj.Attributes.Bounds.Width, bounds.Top + ghDocObj.Attributes.Bounds.Height); ghDoc.AddObject(ghDocObj, true); } }