Autocad Block Net -
Added to the individual BlockReference (Instance).
tr.Commit();
else
If your .NET application needs to find out what the original block template name was, querying br.Name might return *U12 . Instead, use the dynamic block properties:
Start with a single repetitive object in your next drawing, turn it into a well-built block, and begin building your own efficient AutoCAD block net. Your future self (and your project deadlines) will thank you. autocad block net
To write AutoCAD .NET plugins, you need an Integrated Development Environment (IDE) like Visual Studio and the correct API libraries.
using (Transaction tr = db.TransactionManager.StartTransaction()) Added to the individual BlockReference (Instance)
[CommandMethod("InsertMyBlock")] public void InsertBlockInstance() Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction trans = db.TransactionManager.StartTransaction()) BlockTable blkTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; string blockName = "Custom_Rectangle"; if (blkTable.Has(blockName)) // Get the Model Space record BlockTableRecord modelSpace = trans.GetObject(blkTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // Get the Object ID of our block definition ObjectId blockDefId = blkTable[blockName]; // Define insertion properties Point3d insertPoint = new Point3d(20, 20, 0); Scale3d scale = new Scale3d(1.0, 1.0, 1.0); double rotation = 0.0; // In Radians // Create the Block Reference using (BlockReference blkRef = new BlockReference(insertPoint, blockDefId)) blkRef.ScaleFactors = scale; blkRef.Rotation = rotation; // Append the instance to Model Space modelSpace.AppendEntity(blkRef); trans.AddNewlyCreatedDBObject(blkRef, true); doc.Editor.WriteMessage($"\nInstance of 'blockName' inserted."); else doc.Editor.WriteMessage($"\nBlock definition not found. Run 'CreateMyBlock' first."); trans.Commit(); Use code with caution. Working with Block Attributes
Use a structured naming convention (e.g., Furniture-Sofa-3Seat rather than Block1 ), which makes searching through large files effortless. Your future self (and your project deadlines) will thank you
Fleetwood Mac - Best Of 1969 - 1974 2LP - Coloured