Esempio n. 1
0
        static public GeometryBase ToRhino(this _OdDb.ObjectId id)
        {
            if (DatabaseUtils.isCurve(id))
            {
                var geometry = (id.GetObject(_OdDb.OpenMode.ForRead) as _OdDb.Curve).ToRhino();
                if (geometry != null)
                {
                    return(geometry);
                }
            }
            var aId = new _OdDb.ObjectIdCollection()
            {
                id
            };
            string tmpPath = Path.Combine(Path.GetTempPath(), "BricsCAD", "torhino.3dm");

            if (_OdRx.ErrorStatus.OK != Bricscad.Rhino.RhinoUtilityFunctions.ExportRhinoFile(aId, tmpPath))
            {
                return(null);
            }
            aId.Dispose();
            return(ExtractGeometryFromFile(tmpPath));
        }
Esempio n. 2
0
        public static void ToGrasshopper()
        {
            if (PlugIn.LinkedDocument == null && Application.DocumentManager.MdiActiveDocument != PlugIn.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 Face(); break;

            case SubentityType.Edge:
                monitor = new Edge(); break;

            case SubentityType.Vertex:
                monitor = new Vertex(); break;
            }
            if (monitor == null)
            {
                return;
            }

            monitor.InitBy(selectedObjects, PlugIn.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);
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (!_needBake || !PlugIn.LinkedDocument.IsActive)
            {
                return;
            }

            /*Extract input parameters*/
            IGH_GeometricGoo geometry = null;

            if (!DA.GetData("Geometry", ref geometry))
            {
                return;
            }

            var elementType = Bricscad.Bim.BimTypeElement.BimGenericBuildingElt;

            Types.ElementType type = null;
            if (DA.GetData("ElementType", ref type))
            {
                elementType = type.Value;
            }

            Bricscad.Bim.BIMSpatialLocation spatialLocation = null;
            Types.SpatialLocation           location        = null;
            if (DA.GetData("SpatialLocation", ref location))
            {
                spatialLocation = location.Value;
            }

            var objIds = BakeGhGeometry(geometry);

            if (objIds == null)
            {
                return;
            }

            Bricscad.Bim.BIMProfile bimProfile = null;
            Types.Profile           profile    = null;
            if (DA.GetData("Profile", ref profile))
            {
                var dummy = new Bricscad.Bim.BIMProfile(profile.Value);
                if (dummy.SaveProfile(PlugIn.LinkedDocument.Database) == Bricscad.Bim.BimResStatus.Ok)
                {
                    bimProfile = dummy;
                }
            }

            var createdProfileId = _OdDb.ObjectId.Null;

            _OdDb.ObjectEventHandler objAppended = (s, e) => createdProfileId = e.DBObject.ObjectId;
            PlugIn.LinkedDocument.Database.ObjectAppended += objAppended;
            var curvesToDelete = new _OdDb.ObjectIdCollection();

            for (int i = 0; i < objIds.Count; ++i)
            {
                var id = objIds[i];
                spatialLocation?.AssignToEntity(id);
                Bricscad.Bim.BIMClassification.ClassifyAs(id, elementType);
                bimProfile?.ApplyProfileTo(id, 0, true);
                //replace curve with created solid profile
                if (DatabaseUtils.isCurve(id) && !createdProfileId.IsNull)
                {
                    curvesToDelete.Add(id);
                    objIds[i]        = createdProfileId;
                    createdProfileId = _OdDb.ObjectId.Null;
                }
            }
            DatabaseUtils.EraseObjects(curvesToDelete);
            PlugIn.LinkedDocument.Database.ObjectAppended -= objAppended;
            var res = new List <Types.BcEntity>();

            foreach (_OdDb.ObjectId objId in objIds)
            {
                DA.SetData("BuildingElement",
                           new Types.BcEntity(new _OdDb.FullSubentityPath(new _OdDb.ObjectId[] { objId }, new _OdDb.SubentityId()), PlugIn.LinkedDocument.Name));
            }
        }