Beispiel #1
0
        public static void SelectObjects(AcDb.ObjectIdCollection objectIds)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcEd.PromptSelectionResult psr = ed.GetSelection();
                if (psr.Status == AcEd.PromptStatus.OK)
                {
                    AcEd.SelectionSet SSet = psr.Value;
                    foreach (AcEd.SelectedObject SObj in SSet)
                    {
                        if (SObj != null)
                        {
                            AcDb.Entity entityObject = tr.GetObject(SObj.ObjectId, AcDb.OpenMode.ForWrite) as AcDb.Entity;

                            if (entityObject != null)
                            {
                                foreach (AcDb.ObjectId idObj in objectIds)
                                {
                                    if (idObj.Equals(entityObject.ObjectId))
                                    {
                                        entityObject.Highlight();
                                    }
                                }
                            }
                        }
                    }
                    // Save the new object to the database
                    tr.Commit();
                }
            }
        }
Beispiel #2
0
        public void renameBlockFields(string find, string replace)
        {
            foreach (_Db.ObjectId btrId in _c.blockTable)
            {
                _Db.BlockTableRecord btr = _c.trans.GetObject(btrId, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

                _Db.ObjectIdCollection blockRefIds = btr.GetBlockReferenceIds(true, true);

                foreach (_Db.ObjectId btRfId in blockRefIds)
                {
                    _Db.BlockReference br = _c.trans.GetObject(btRfId, _Db.OpenMode.ForWrite) as _Db.BlockReference;

                    if (br != null)
                    {
                        foreach (_Db.ObjectId arId in br.AttributeCollection)
                        {
                            _Db.DBObject           obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite);
                            _Db.AttributeReference ar  = obj as _Db.AttributeReference;

                            if (ar != null)
                            {
                                ar.TextString = ar.TextString.Replace(find, replace);
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
 public static void DeleteObjects(AcDb.ObjectIdCollection objectIds)
 {
     foreach (AcDb.ObjectId objectId in objectIds)
     {
         DeleteObject(objectId);
     }
 }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        private _Db.Viewport layoutViewportGetter(_Db.Layout lay)
        {
            _Db.ObjectIdCollection viewIds = lay.GetViewports();
            _Db.Viewport           vp      = null;

            foreach (_Db.ObjectId id in viewIds)
            {
                _Db.Viewport vp2 = _c.trans.GetObject(id, _Db.OpenMode.ForWrite) as _Db.Viewport;
                if (vp2 != null && vp2.Number == 2)
                {
                    vp = vp2;
                    break;
                }
            }

            if (vp == null)
            {
                _Db.BlockTableRecord btr = _c.trans.GetObject(lay.BlockTableRecordId, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

                vp = new _Db.Viewport();

                btr.AppendEntity(vp);
                _c.trans.AddNewlyCreatedDBObject(vp, true);

                vp.On     = true;
                vp.GridOn = false;
            }

            return(vp);
        }
Beispiel #6
0
        public static void DrawOrder_MoveToTop(AcDb.ObjectIdCollection collection)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable       bt  = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(bt[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForWrite);

                AcDb.DrawOrderTable dot = (AcDb.DrawOrderTable)tr.GetObject(btr.DrawOrderTableId, AcDb.OpenMode.ForWrite);
                dot.MoveToTop(collection);
            }
        }
Beispiel #7
0
        private bool getBlockFromMaster(ref List <string> missingBlocks)
        {
            _Db.Database sourceDb       = new _Db.Database(false, true);
            string       sourceFileName = @"C:\Brics_pealeehitus\master.dwg";

            if (!File.Exists(sourceFileName))
            {
                sourceFileName = @"C:\Users\aleksandr.ess\Dropbox\DMT\Brics_testimine\master.dwg";
                if (!File.Exists(sourceFileName))
                {
                    sourceFileName = @"C:\Users\Alex\Dropbox\DMT\Brics_testimine\master.dwg";
                }
            }

            sourceDb.ReadDwgFile(sourceFileName, System.IO.FileShare.Read, true, "");
            _Db.ObjectIdCollection blockIds = new _Db.ObjectIdCollection();


            using (_Db.Transaction sourceTrans = sourceDb.TransactionManager.StartTransaction())
            {
                _Db.BlockTable sourceBlockTable = sourceTrans.GetObject(sourceDb.BlockTableId, _Db.OpenMode.ForRead, false) as _Db.BlockTable;

                foreach (_Db.ObjectId sourceObject in sourceBlockTable)
                {
                    _Db.BlockTableRecord btr = sourceTrans.GetObject(sourceObject, _Db.OpenMode.ForRead, false) as _Db.BlockTableRecord;

                    if (!btr.IsAnonymous && !btr.IsLayout)
                    {
                        if (missingBlocks.Contains(btr.Name))
                        {
                            blockIds.Add(sourceObject);
                            missingBlocks.Remove(btr.Name);
                            write("[SETUP] " + btr.Name); // TODO REMOVE
                        }
                    }

                    btr.Dispose();
                }
            }

            if (missingBlocks.Count > 0)
            {
                return(false);
            }

            _Db.IdMapping mapping = new _Db.IdMapping();
            sourceDb.WblockCloneObjects(blockIds, _c.blockTable.Id, mapping, _Db.DuplicateRecordCloning.Replace, false);
            sourceDb.Dispose();

            write("[SETUP] Kõik puuduvad blockid on lisatud 'master' failist");
            return(true);
        }
 protected _OdDb.ObjectIdCollection BakeGhGeometry(File3dm tmpFile)
 {
     _OdDb.ObjectIdCollection dbObjects = null;
     if (tmpFile.Objects.Count != 0)
     {
         string tmpPath = Path.Combine(Path.GetTempPath(), "BricsCAD", "fromrhino.3dm");
         tmpFile.Write(tmpPath, new File3dmWriteOptions());
         using (var objects = Bricscad.Rhino.RhinoUtilityFunctions.ImportRhinoFile(tmpPath, true))
         {
             foreach (var entity in objects.OfType <_OdDb.Entity>())
             {
                 AssignTraits(entity);
             }
             dbObjects = DatabaseUtils.AppendObjectsToDatabase(objects, GhDrawingContext.LinkedDocument.Database, false);
         }
     }
     return(dbObjects);
 }
Beispiel #9
0
        public static AcDb.Hatch CreateHatch(AcDb.ObjectIdCollection objectIds, bool removeBoundaries)
        {
            AcDb.Hatch    oHatch = new AcDb.Hatch();
            AcGe.Vector3d normal = new AcGe.Vector3d(0.0, 0.0, 1.0);
            oHatch.Normal       = normal;
            oHatch.Elevation    = 0;
            oHatch.PatternScale = 1;
            oHatch.SetHatchPattern(AcDb.HatchPatternType.UserDefined, "ANSI31");
            oHatch.ColorIndex  = 1;
            oHatch.Associative = true;
            oHatch.AppendLoop((int)AcDb.HatchLoopTypes.Default, objectIds);
            oHatch.EvaluateHatch(true);

            if (removeBoundaries)
            {
                ServiceCAD.DeleteObjects(objectIds);
            }

            return(oHatch);
        }
Beispiel #10
0
        public static AcDb.ObjectIdCollection ImportSymbolTableRecords <T>(
            /*this Database db,*/
            string sourceFile,
            params string[] recordNames)
            where T : AcDb.SymbolTable
        {
            using (AcDb.Database sourceDb = new AcDb.Database())
            {
                sourceDb.ReadDwgFile(sourceFile, System.IO.FileShare.Read, false, "");

                AcDb.ObjectId sourceTableId;
                AcDb.ObjectId targetTableId;

                switch (typeof(T).Name)
                {
                case "BlockTable":
                    sourceTableId = sourceDb.BlockTableId;
                    targetTableId = db.BlockTableId;
                    break;

                case "DimStyleTable":
                    sourceTableId = sourceDb.DimStyleTableId;
                    targetTableId = db.DimStyleTableId;
                    break;

                case "LayerTable":
                    sourceTableId = sourceDb.LayerTableId;
                    targetTableId = db.LayerTableId;
                    break;

                case "LinetypeTable":
                    sourceTableId = sourceDb.LinetypeTableId;
                    targetTableId = db.LinetypeTableId;
                    break;

                case "RegAppTable":
                    sourceTableId = sourceDb.RegAppTableId;
                    targetTableId = db.RegAppTableId;
                    break;

                case "TextStyleTable":
                    sourceTableId = sourceDb.TextStyleTableId;
                    targetTableId = db.TextStyleTableId;
                    break;

                case "UcsTable":
                    sourceTableId = sourceDb.UcsTableId;
                    targetTableId = db.UcsTableId;
                    break;

                case "ViewTable":
                    sourceTableId = sourceDb.ViewportTableId;
                    targetTableId = db.ViewportTableId;
                    break;

                case "ViewportTable":
                    sourceTableId = sourceDb.ViewportTableId;
                    targetTableId = db.ViewportTableId;
                    break;

                default:
                    throw new ArgumentException("\nImportSymbolTableRecords > Потрібен конкретний тип, похідний від SymbolTable");
                }

                using (AcDb.Transaction tr = sourceDb.TransactionManager.StartTransaction())
                {
                    T sourceTable = (T)tr.GetObject(sourceTableId, AcDb.OpenMode.ForRead);
                    AcDb.ObjectIdCollection idObjects = new AcDb.ObjectIdCollection();
                    foreach (string name in recordNames)
                    {
                        if (sourceTable.Has(name))
                        {
                            idObjects.Add(sourceTable[name]);
                        }
                    }
                    if (idObjects.Count == 0)
                    {
                        return(null);
                    }
                    AcDb.IdMapping idMap = new AcDb.IdMapping();
                    sourceDb.WblockCloneObjects(idObjects, targetTableId, idMap, AcDb.DuplicateRecordCloning.Replace, false);
                    tr.Commit();
                    AcDb.ObjectIdCollection retVal = new AcDb.ObjectIdCollection();
                    foreach (AcDb.ObjectId id in idObjects)
                    {
                        if (idMap[id].IsCloned)
                        {
                            retVal.Add(idMap[id].Value);
                        }
                    }
                    return(retVal.Count == 0 ? null : retVal);
                }
            }
        }
Beispiel #11
0
 public static AcDb.Hatch CreateHatch(AcDb.ObjectId objectId)
 {
     AcDb.ObjectIdCollection objectIds = new AcDb.ObjectIdCollection(new AcDb.ObjectId[] { objectId });
     return(CreateHatch(objectIds, true));
 }
Beispiel #12
0
 public static AcDb.Hatch CreateHatch(AcDb.ObjectId objectId, bool removeBoundaries)
 {
     AcDb.ObjectIdCollection objectIds = new AcDb.ObjectIdCollection(new AcDb.ObjectId[] { objectId });
     return(CreateHatch(objectIds, removeBoundaries));
 }
Beispiel #13
0
 public static AcDb.Hatch CreateHatch(AcDb.ObjectIdCollection objectIds)
 {
     return(CreateHatch(objectIds, true));
 }
Beispiel #14
0
        public static void ImportLayout(string layoutName, string filename)
        {
            // Get the current document and database
            _AcAp.Document acDoc   = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database acCurDb = acDoc.Database;

            // Specify the layout name and drawing file to work with
            //string layoutName = "MAIN AND SECOND FLOOR PLAN";
            //string filename = "C:\\AutoCAD\\Sample\\Sheet Sets\\Architectural\\A-01.dwg";

            // Create a new database object and open the drawing into memory
            _AcDb.Database acExDb = new _AcDb.Database(false, true);
            acExDb.ReadDwgFile(filename, Autodesk.AutoCAD.DatabaseServices.FileOpenMode.OpenForReadAndAllShare, true, "");

            // Create a transaction for the external drawing
            using (_AcDb.Transaction acTransEx = acExDb.TransactionManager.StartTransaction())
            {
                // Get the layouts dictionary
                _AcDb.DBDictionary layoutsEx = acTransEx.GetObject(acExDb.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;

                // Check to see if the layout exists in the external drawing
                if (layoutsEx.Contains(layoutName) == true)
                {
                    // Get the layout and block objects from the external drawing
                    _AcDb.Layout           layEx       = layoutsEx.GetAt(layoutName).GetObject(_AcDb.OpenMode.ForRead) as _AcDb.Layout;
                    _AcDb.BlockTableRecord blkBlkRecEx = acTransEx.GetObject(layEx.BlockTableRecordId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTableRecord;

                    // Get the objects from the block associated with the layout
                    _AcDb.ObjectIdCollection idCol = new _AcDb.ObjectIdCollection();
                    foreach (_AcDb.ObjectId id in blkBlkRecEx)
                    {
                        idCol.Add(id);
                    }

                    // Create a transaction for the current drawing
                    using (_AcDb.Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                    {
                        // Get the block table and create a new block
                        // then copy the objects between drawings
                        _AcDb.BlockTable blkTbl = acTrans.GetObject(acCurDb.BlockTableId, _AcDb.OpenMode.ForWrite) as _AcDb.BlockTable;
                        using (_AcDb.BlockTableRecord blkBlkRec = new _AcDb.BlockTableRecord())
                        {
                            int layoutCount = layoutsEx.Count - 1;

                            blkBlkRec.Name = "*Paper_Space" + layoutCount.ToString();
                            blkTbl.Add(blkBlkRec);
                            acTrans.AddNewlyCreatedDBObject(blkBlkRec, true);
                            acExDb.WblockCloneObjects(idCol, blkBlkRec.ObjectId, new _AcDb.IdMapping(), _AcDb.DuplicateRecordCloning.Ignore, false);

                            // Create a new layout and then copy properties between drawings
                            _AcDb.DBDictionary layouts = acTrans.GetObject(acCurDb.LayoutDictionaryId, _AcDb.OpenMode.ForWrite) as _AcDb.DBDictionary;
                            using (_AcDb.Layout lay = new _AcDb.Layout())
                            {
                                lay.LayoutName = layoutName;
                                lay.AddToLayoutDictionary(acCurDb, blkBlkRec.ObjectId);
                                acTrans.AddNewlyCreatedDBObject(lay, true);
                                lay.CopyFrom(layEx);

                                _AcDb.DBDictionary plSets = acTrans.GetObject(acCurDb.PlotSettingsDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;

                                // Check to see if a named page setup was assigned to the layout,
                                // if so then copy the page setup settings
                                if (lay.PlotSettingsName != "")
                                {
                                    // Check to see if the page setup exists
                                    if (plSets.Contains(lay.PlotSettingsName) == false)
                                    {
                                        plSets.UpgradeOpen();

                                        using (_AcDb.PlotSettings plSet = new _AcDb.PlotSettings(lay.ModelType))
                                        {
                                            plSet.PlotSettingsName = lay.PlotSettingsName;
                                            plSet.AddToPlotSettingsDictionary(acCurDb);
                                            acTrans.AddNewlyCreatedDBObject(plSet, true);

                                            _AcDb.DBDictionary plSetsEx = acTransEx.GetObject(acExDb.PlotSettingsDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;

                                            _AcDb.PlotSettings plSetEx = plSetsEx.GetAt(lay.PlotSettingsName).GetObject(_AcDb.OpenMode.ForRead) as _AcDb.PlotSettings;

                                            plSet.CopyFrom(plSetEx);
                                        }
                                    }
                                }
                            }
                        }

                        // Regen the drawing to get the layout tab to display
                        acDoc.Editor.Regen();

                        // Save the changes made
                        acTrans.Commit();
                    }
                }
                else
                {
                    // Display a message if the layout could not be found in the specified drawing
                    acDoc.Editor.WriteMessage("\nLayout '" + layoutName +
                                              "' could not be imported from '" + filename + "'.");
                }

                // Discard the changes made to the external drawing file
                acTransEx.Abort();
            }

            // Close the external drawing file
            acExDb.Dispose();
        }
Beispiel #15
0
        private static void ImportNestedFilters(

            _AcLm.LayerFilter srcFilter,
            _AcLm.LayerFilter destFilter,
            _AcDb.Database srcDb,
            _AcDb.Database destDb,
            bool copyLayer,
            _AcEd.Editor ed)
        {
            using (_AcDb.Transaction tr = srcDb.TransactionManager.StartTransaction())
            {
                _AcDb.LayerTable lt = tr.GetObject(srcDb.LayerTableId, _AcDb.OpenMode.ForRead, false) as _AcDb.LayerTable;

                foreach (_AcLm.LayerFilter sf in srcFilter.NestedFilters)
                {
                    _AcDb.IdMapping idmap = new _AcDb.IdMapping();
                    if (copyLayer)
                    {
                        // Get the layers to be cloned to the dest db.
                        // Only those that are pass the filter
                        _AcDb.ObjectIdCollection layerIds = new _AcDb.ObjectIdCollection();
                        foreach (_AcDb.ObjectId layerId in lt)
                        {
                            _AcDb.LayerTableRecord ltr = tr.GetObject(layerId, _AcDb.OpenMode.ForRead, false) as _AcDb.LayerTableRecord;
                            if (sf.Filter(ltr))
                            {
                                layerIds.Add(layerId);
                            }
                        }

                        // clone the layers to the dest db
                        if (layerIds.Count > 0)
                        {
                            srcDb.WblockCloneObjects(
                                layerIds,
                                destDb.LayerTableId,
                                idmap,
                                _AcDb.DuplicateRecordCloning.Replace,
                                false);
                        }
                    }

                    // Find if a destination database already
                    // has a layer filter with the same name
                    _AcLm.LayerFilter df = null;
                    foreach (_AcLm.LayerFilter f in destFilter.NestedFilters)
                    {
                        if (f.Name.Equals(sf.Name))
                        {
                            df = f;
                            break;
                        }
                    }

                    if (df == null)
                    {
                        if (sf is _AcLm.LayerGroup)
                        {
                            // create a new layer filter group
                            // if nothing found
                            _AcLm.LayerGroup sfgroup = sf as _AcLm.LayerGroup;
                            _AcLm.LayerGroup dfgroup = new _AcLm.LayerGroup();
                            ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nImportiere Layerfilter-Gruppe {0}.", sf.Name));
                            dfgroup.Name = sf.Name;
                            df           = dfgroup;
                            if (copyLayer)
                            {
                                _AcLm.LayerCollection lyrs = sfgroup.LayerIds;
                                foreach (_AcDb.ObjectId lid in lyrs)
                                {
                                    if (idmap.Contains(lid))
                                    {
                                        _AcDb.IdPair idp = idmap[lid];

                                        dfgroup.LayerIds.Add(idp.Value);
                                    }
                                }
                            }
                            destFilter.NestedFilters.Add(df);
                        }
                        else
                        {
                            // create a new layer filter
                            // if nothing found
                            ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nImportiere Layerfilter {0}.", sf.Name));
                            df                  = new _AcLm.LayerFilter();
                            df.Name             = sf.Name;
                            df.FilterExpression = sf.FilterExpression;
                            destFilter.NestedFilters.Add(df);
                        }
                    }
                    // Import other filters
                    ImportNestedFilters(sf, df, srcDb, destDb, copyLayer, ed);
                }
                tr.Commit();
            }
        }
        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));
            }
        }