Esempio n. 1
0
        public static List <FullSubentityPath> SelectEntity(SubentityType subentType, SelectionFilter selectionFilter, bool multiple)
        {
            var                    editor  = Application.DocumentManager.MdiActiveDocument.Editor;
            const string           selMode = "SELECTIONMODES";
            PromptSelectionOptions pso     = null;
            var                    oldVal  = Application.GetSystemVariable(selMode);

            if (DatabaseUtils.IsSubentity(subentType))
            {
                pso = new PromptSelectionOptions();
                switch (subentType)
                {
                case SubentityType.Face:
                    Application.SetSystemVariable(selMode, 2);
                    break;

                case SubentityType.Edge:
                    Application.SetSystemVariable(selMode, 1);
                    break;

                case SubentityType.Vertex:
                    Application.SetSystemVariable(selMode, 3);
                    break;
                }
                pso.ForceSubSelections = true;
            }
            else
            {
                Application.SetSystemVariable(selMode, 0);
            }

            if (!multiple)
            {
                if (pso == null)
                {
                    pso = new PromptSelectionOptions();
                }
                pso.SingleOnly        = true;
                pso.SinglePickInSpace = true;
            }
            var selFiler = selectionFilter;
            PromptSelectionResult selection = null;

            if (pso != null && selFiler != null)
            {
                selection = editor.GetSelection(pso, selFiler);
            }
            else if (pso != null)
            {
                selection = editor.GetSelection(pso);
            }
            else if (selFiler != null)
            {
                selection = editor.GetSelection(selFiler);
            }
            else
            {
                selection = editor.GetSelection();
            }

            Application.SetSystemVariable("SELECTIONMODES", oldVal);
            if (selection.Status != PromptStatus.OK)
            {
                return(null);
            }

            List <FullSubentityPath> selectedSubents = null;

            for (int i = 0; i < selection.Value.Count; ++i)
            {
                if (DatabaseUtils.IsSubentity(subentType))
                {
                    var subents = selection.Value[i].GetSubentities();
                    if (subents == null)
                    {
                        continue;
                    }

                    foreach (var subent in subents)
                    {
                        if (subent.FullSubentityPath.SubentId.Type != subentType)
                        {
                            continue;
                        }

                        if (selectedSubents == null)
                        {
                            selectedSubents = new List <FullSubentityPath>();
                        }
                        selectedSubents.Add(subent.FullSubentityPath);
                    }
                }
                else
                {
                    selectedSubents = selection.Value.GetObjectIds().Select(objId =>
                                                                            new FullSubentityPath(new ObjectId[] { objId },
                                                                                                  new SubentityId(SubentityType.Null, 0))).ToList();
                }
            }
            return(selectedSubents);
        }
Esempio n. 2
0
        public GhDataManager GrasshopperDataManager(_OdDb.Database database, bool createIfNotExist = false)
        {
            var bcDoc = DatabaseUtils.FindDocument(database);

            return(GrasshopperDataManager(bcDoc, createIfNotExist));
        }
        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));
            }
        }