.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

try to insert blocks without attributes - nothing to see

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jan_tappenbeck
379 Views, 2 Replies

try to insert blocks without attributes - nothing to see

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
2 REPLIES 2
Message 2 of 3
_gile
in reply to: jan_tappenbeck

Hi,

 

You neither append the newly created block reference to a block table record (e.g. model space) nor add it to the transaction...



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
jan_tappenbeck
in reply to: _gile

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.

Post to forums  

Technology Administrators


Autodesk Design & Make Report