Ejemplo n.º 1
0
        public static BlockDrawingObject Create(Database target, string blockName)
        {
            Transaction trans = target.TransactionManager.TopTransaction;
            BlockTable  bt    = (BlockTable)trans.GetObject(target.BlockTableId, OpenMode.ForRead);

            SymbolUtilityServices.ValidateSymbolName(blockName, false);
            if (bt.Has(blockName))
            {
                throw  new InvalidOperationException("Block name exists");
            }

            BlockTableRecord btr = new BlockTableRecord();

            btr.Name = blockName;

            bt.UpgradeOpen();
            ObjectId btrId = bt.Add(btr);

            trans.AddNewlyCreatedDBObject(btr, true);

            BlockDrawingObject blockDrawingObject = new BlockDrawingObject(target);

            blockDrawingObject.BaseObject = btrId;
            return(blockDrawingObject);
        }
Ejemplo n.º 2
0
        // TODO: Add test
        public BlockDrawingObject GetBlock()
        {
            BlockDrawingObject blockDrawingObject = new BlockDrawingObject();

            blockDrawingObject.BaseObject = _database.GetBlockDefinition(BlockName).ObjectId;
            return(blockDrawingObject);
        }
Ejemplo n.º 3
0
        public BlockDrawingObject TransferToDocument(Document targetDocument)
        {
            Transaction        sourceTrans            = this._database.TransactionManager.TopTransaction;
            Transaction        destinatiopnTrans      = targetDocument.Database.TransactionManager.TopTransaction;
            BlockTableRecord   sourceBlockTableRecord = sourceTrans.GetObject(this.BaseObject, OpenMode.ForRead) as BlockTableRecord;
            ObjectIdCollection sourceObjects          = new ObjectIdCollection();

            /*foreach (ObjectId objectId in sourceBlockTableRecord)
             * {
             *  sourceObjects.Add(objectId);
             * }*/
            sourceObjects.Add(sourceBlockTableRecord.ObjectId);
            IdMapping mapping = new IdMapping();

            // TODO: Confirm ignore is correct option
            _database.WblockCloneObjects(sourceObjects, targetDocument.Database.BlockTableId, mapping, DuplicateRecordCloning.Ignore, false);

            BlockDrawingObject blockDrawingObject = new BlockDrawingObject(targetDocument);

            blockDrawingObject.BaseObject = mapping.Lookup(sourceBlockTableRecord.ObjectId).Value;
            return(blockDrawingObject);
        }
Ejemplo n.º 4
0
        public static BlockRefDrawingObject Create(Database target, Point3d insertionPoint, BlockDrawingObject sourceBlock)
        {
            ObjectId       newRefId;
            Transaction    trans         = target.TransactionManager.TopTransaction;
            BlockReference acadReference = new BlockReference(insertionPoint, sourceBlock.BaseObject);

            newRefId = target.GetModelSpace(true).AppendEntity(acadReference);
            trans.AddNewlyCreatedDBObject(acadReference, true);

            // TODO: Figure out why the belwo throws an exception when the modified handler is active
            // Exception is thrown when the object is attempted to be opened, during the modified event handler
            BlockRefDrawingObject newRef = new BlockRefDrawingObject();

            newRef.BaseObject = newRefId;
            return(newRef);
        }