Community
hi!
currently i try to insert blocks from a Folder.
there comes no mistake but at the end no block will be visible. Select all will not filter any block!
could someone help me? the code follows now.
regards Jan
Public Function CreateInsertNoAttribut(ByVal InsertPoint As Point3d, ByVal TbDoc As Autodesk.Map.IM.Forms.Document, ByVal AlternativeBlockFolder As String, ByVal AlternativeBlockName As String, ByVal Orientation As Double, ByVal BlockName As String) As Integer ' ------ http://ma22-wiki-001/eblwiki/index.php?title=Acad_(Klasse_von_EBL.MapService)#Block ------ '' Get the current document and database Dim acDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Dim ErrDetail As String = "" Dim Options As EBL.Optionen.Options = New EBL.Optionen.Options(TbDoc) Dim BlockFilePath As String = "" BlockName = BlockName & ".dwg" BlockFilePath = Path.Combine(Options.GetPathFolderBlockDM, BlockName) ' wenn Block nicht verfügbar, dann Dummyblock If System.IO.File.Exists(BlockFilePath) = False Then BlockFilePath = Path.Combine(Options.GetPathFolderBlockDM, AlternativeBlockName) BlockName = AlternativeBlockName End If Dim br As BlockReference Dim id As ObjectId Try ErrDetail = "Start a transaction" Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() ErrDetail = "Open the Block table for read" Dim acBlkTbl As BlockTable ErrDetail = "lock document" Using acDoc.LockDocument Using TempDB As New Database(False, True) 'Get block table acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, False) 'check if block already exists If Not acBlkTbl.Has(BlockName) Then 'check if file exists If IO.File.Exists(BlockFilePath) Then 'read in the file into the temp database TempDB.ReadDwgFile(BlockFilePath, IO.FileShare.Read, True, Nothing) 'insert the tempdb into the current drawing db, id is the new block id id = acCurDb.Insert(BlockName, TempDB, True) End If Else id = acBlkTbl.Item(BlockName) End If 'create a new block reference br = New BlockReference(New Point3d(0, 0, 0), id) End Using End Using 'acDoc.LockDocument ErrDetail = "Save the changes and dispose of the transaction" acTrans.Commit() End Using 'acTrans Catch ex As Exception _TryReport.Show("unerwarteter Fehler in EBL.MapService > cls_Acad > CreateInsertNoAttribut", "ErrDetail: " & ErrDetail & vbCrLf & vbCrLf & _ "Orientation: " & Orientation.ToString & vbCrLf & _ vbCrLf & ex.ToString) Return 1 End Try Return 0 End Function
Solved! Go to Solution.
Solved by _gile. Go to Solution.
hi !
thanks - now it works!
regards Jan
Public Function CreateInsertNoAttribut(ByVal InsertPoint As Point3d, ByVal TbDoc As Autodesk.Map.IM.Forms.Document, _ ByVal AlternativeBlockFolder As String, ByVal AlternativeBlockName As String, _ ByVal Orientation As Double, ByVal BlockName As String) As Integer '' Get the current document and database Dim acDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Dim ErrDetail As String = "" Dim Options As EBL.Optionen.Options = New EBL.Optionen.Options(TbDoc) Dim BlockFilePath As String = "" BlockName = BlockName & ".dwg" BlockFilePath = Path.Combine(Options.GetPathFolderBlockDM, BlockName) ' wenn Block nicht verfügbar, dann Dummyblock If System.IO.File.Exists(BlockFilePath) = False Then BlockFilePath = Path.Combine(Options.GetPathFolderBlockDM, AlternativeBlockName) BlockName = AlternativeBlockName End If Dim br As BlockReference Dim id As ObjectId Try ErrDetail = "Start a transaction" Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() ErrDetail = "Open the Block table for read" Dim acBlkTbl As BlockTable ErrDetail = "lock document" Using acDoc.LockDocument 'use a temporary database Using TempDB As New Database(False, True) 'Get block table acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, False) Dim acBlkTblRec As BlockTableRecord acBlkTblRec = CType(acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite), BlockTableRecord) 'check if block already exists If Not acBlkTbl.Has(BlockName) Then 'check if file exists If IO.File.Exists(BlockFilePath) Then 'read in the file into the temp database TempDB.ReadDwgFile(BlockFilePath, IO.FileShare.Read, True, Nothing) 'insert the tempdb into the current drawing db, id is the new block id id = acCurDb.Insert(BlockName, TempDB, True) End If Else id = acBlkTbl.Item(BlockName) End If 'create a new block reference br = New BlockReference(InsertPoint, id) acBlkTblRec.AppendEntity(br) acTrans.AddNewlyCreatedDBObject(br, True) End Using End Using 'acDoc.LockDocument ErrDetail = "Save the changes and dispose of the transaction" acTrans.Commit() End Using 'acTrans Catch ex As Exception _TryReport.Show("unerwarteter Fehler in EBL.MapService > cls_Acad > CreateInsertNoAttribut", "ErrDetail: " & ErrDetail & vbCrLf & vbCrLf & _ "AlternativeBlockFolder: " & AlternativeBlockFolder & vbCrLf & _ "AlternativeBlockName: " & AlternativeBlockName & vbCrLf & _ "BlockName: " & BlockName & vbCrLf & _ "Orientation: " & Orientation.ToString & vbCrLf & _ vbCrLf & ex.ToString) Return 1 End Try Return 0 End Function
Can't find what you're looking for? Ask the community or share your knowledge.