Message 1 of 6
Not applicable
01-11-2012
03:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
As stated, when I use VB.NET to insert a block it has no name, thus making it behave oddly. Is there a way to define the block name properly since it apparently doesn't use the name of the file I am importing? I have tried defining the block manually and have the same result so my code must be missing something:
Public Function InsertBlock(ByVal InsPt As Point3d, ByVal BlockName As String, ByVal expl As Boolean, ByVal rotation As Double, ByVal schaal As Integer) As ObjectId
If Not File.Exists(BlockName) Then
MsgBox("File does not exist?")
Return ObjectId.Null
End If
Dim myDB As Database
Dim myDwg As Document
myDwg = Application.DocumentManager.MdiActiveDocument
Using docloc As DocumentLock = myDwg.LockDocument
myDB = myDwg.Database
Dim ed As Editor = myDwg.Editor
Using tr As Transaction = myDwg.TransactionManager.StartTransaction
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 = tr.GetObject(myDB.BlockTableId, OpenMode.ForRead, True)
Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, True)
Dim bref As BlockReference = New BlockReference(InsPt, BlkId)
bref.Rotation = rotation
bref.ScaleFactors = New Scale3d(schaal, schaal, schaal)
btr.AppendEntity(bref)
tr.AddNewlyCreatedDBObject(bref, True)
If expl Then
bref.ExplodeToOwnerSpace()
bref.Erase()
End If
tr.Commit()
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.ToString)
End Try
End Using
End Using
End FunctionThanks for any tips that may be offered!
Solved! Go to Solution.