Ejemplo n.º 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Types.SpatialLocation building = null;
            if (!DA.GetData("Building", ref building))
            {
                return;
            }

            var stories = Bricscad.Bim.BIMBuilding.AllObjectStories(GhDrawingContext.LinkedDocument.Database, building.Value.Name)
                          .Select(story => new Types.SpatialLocation(story)).ToList();

            if (stories.Count != 0)
            {
                DA.SetDataList("Story", stories);
            }
        }
        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));
            }
        }