Community
Hi, is there a way to insert a block in a drawing already exploded, similar to the way the INSERT "*blockname" command line would work? (exploding it after insert wouldn't work in my case because I need to retain links between attributes and cells in a table, this is for a specific need)
I have a sub that I use to insert blocks. I just pass it the needed info (insertion point, blockname, basename, ...)
InsertBlock(NewPoint3d(Xval, Yval, 0), datumADwg, "Datum_A_FC", True, 0, dwg_scale)
Public Sub InsertBlock(ByVal InsPt As Point3d, ByVal BlockName As String, ByVal basename As String, _ ByVal explode As Boolean, ByVal rotation As Double, ByVal scale As Double) Dim myTransMan As DatabaseServices.TransactionManager Dim myTrans As DatabaseServices.Transaction Dim myDwg As Document Dim myBT As BlockTable Dim myBTR As BlockTableRecord myDwg = Application.DocumentManager.MdiActiveDocument myTransMan = myDwg.TransactionManager myTrans = myTransMan.StartTransaction myBT = myDwg.Database.BlockTableId.GetObject(OpenMode.ForRead) If myBT.Has(basename) Then myBTR = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite) Dim myBlockRef As New DatabaseServices.BlockReference(InsPt, myBT(basename)) myBlockRef.Rotation = rotation myBlockRef.ScaleFactors = New Geometry.Scale3d(scale, scale, scale) myBTR.AppendEntity(myBlockRef) myTrans.AddNewlyCreatedDBObject(myBlockRef, True) If explode Then myBlockRef.ExplodeToOwnerSpace() myBlockRef.Erase() myBlockRef.DisableUndoRecording(False) myBlockRef.DowngradeOpen() End If myTrans.Commit() Else Dim myDB As Database myDB = myDwg.Database Try Using db As Database = New Database(False, True) db.ReadDwgFile(BlockName, IO.FileShare.Read, True, "") Dim BlkId As ObjectId BlkId = myDB.Insert(BlockName, db, True) Dim bt As BlockTable = myTrans.GetObject(myDB.BlockTableId, OpenMode.ForRead, True) Dim btr As BlockTableRecord = myTrans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, True) Dim bref As BlockReference bref = New BlockReference(InsPt, BlkId) bref.Rotation = rotation bref.ScaleFactors = New Scale3d(scale, scale, scale) btr.AppendEntity(bref) myTrans.AddNewlyCreatedDBObject(bref, True) If explode Then bref.ExplodeToOwnerSpace() bref.Erase() bref.DisableUndoRecording(False) bref.DowngradeOpen() End If If bt.Has("") And Not bt.Has(basename) Then Dim bad As BlockTableRecord = myTrans.GetObject(bt(""), OpenMode.ForWrite, True) bad.Name = basename bad.Dispose() End If myTrans.Commit() End Using Catch ex As Autodesk.AutoCAD.Runtime.Exception MsgBox(ex.ToString) End Try End If myTrans.Dispose() myTransMan.Dispose()
I hope that helps.
Mark
Hi,
How about inserting a block reference and then using BlockReference.ExplodeToOwnerSpace ?
Regards,
Balaji