<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Inserted blocks disapear. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12612276#M5259</link>
    <description>&lt;P&gt;It looks like your ReadBOM sub is not committing the transaction that it starts. The nested transactions in the other sub that it calls repeatedly are probably not necessary. Try refactoring your code to pass the transaction as an argument instead of starting a nested transaction on each Loop iteration.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Mar 2024 17:53:43 GMT</pubDate>
    <dc:creator>ActivistInvestor</dc:creator>
    <dc:date>2024-03-04T17:53:43Z</dc:date>
    <item>
      <title>Inserted blocks disapear.</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12593500#M5258</link>
      <description>&lt;P&gt;I have a block of code that inserts a block and populates 2 attributes.&lt;/P&gt;&lt;P&gt;If i run the code directly it inserts the block and populates the atts fine.&lt;/P&gt;&lt;P&gt;if i run the same block of code while iterating through a table, to pass a value for the atts,&amp;nbsp;&lt;/P&gt;&lt;P&gt;the blocks appear to insert. once the table read completes the blocks all disapear.&lt;/P&gt;&lt;P&gt;Thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;  Public Sub ReadBOM()
        'Read table populate the atts array
        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim acBlkTbl As BlockTable
        Dim acBlkTblRec As BlockTableRecord
        Dim TagV As String    'Atts(1)
        ' Dim cntx As Int16


        Dim acTbl As Table = Nothing
        Using doc.LockDocument
            Using acTrans As Transaction = db.TransactionManager.StartTransaction()
                acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead)
                acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForRead)


                Dim Res As PromptSelectionResult = ed.GetSelection
                Dim acSSet As SelectionSet = Res.Value
                '' Step through the objects in the selection set
                For Each acSSObj As SelectedObject In acSSet

                    Dim ent As Entity = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead)
                    Try
                        If TypeOf ent Is Table Then
                            acTbl = ent
                            ' MsgBox("before loop  " &amp;amp; acTbl.Cells)
                            Dim TbName As String = acTbl.Cells(0, 0).Value.ToString
                            'MsgBox(TbName)

                            'iterate through table
                            For cnt1 = 1 To acTbl.Rows.Count - 2
                                TagV = acTbl.Cells(cnt1 + 1, 0).Value.ToString 'looking in row no 3 (4th actual row)

                                InsertElecTagBlock(TagV) ' works kinda but block disapears
                            Next
                        End If
                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        MsgBox("F#%K!!! " &amp;amp; ex.Message)
                    End Try
                Next
            End Using
        End Using
    End Sub
 Public Sub InsertElecTagBlock(TagVal As String)
        Dim BlkN As String = "C:\Vault\CADD Standards\CADD Support Files\Symbols\Electrical\Elect GA Symbols\ITag.dwg"
        'insert the block and populate attribute.
        Using lock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument
            Dim DOC As Document = Application.DocumentManager.MdiActiveDocument
            Dim acDatabase As Database = DOC.Database
            Using acTrans As Transaction = DOC.TransactionManager.StartTransaction()
                Dim ed As Editor = DOC.Editor
                ed.UpdateScreen()
                Dim blktable As BlockTable = acTrans.GetObject(acDatabase.BlockTableId, OpenMode.ForWrite)
                Dim pprSpace As BlockTableRecord = CType(acTrans.GetObject(acDatabase.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                Dim blkRec As BlockTableRecord
                Dim blkRef As BlockReference
                InsPoint = New Point3d(0, 0, 0)

                'Try to find electrical tag exists:
                If Not blktable.Has(TagName) Then
                    Dim extDB As New Database(False, True)
                    extDB.ReadDwgFile(BlkN, IO.FileShare.Read, True, "")
                    Dim name As String = SymbolUtilityServices.GetBlockNameFromInsertPathName(BlkN)
                    Dim objID As ObjectId = acDatabase.Insert(name, extDB, True)
                    blkRef = New BlockReference(InsPoint, objID)
                    blkRec = acTrans.GetObject(blkRef.BlockTableRecord, OpenMode.ForWrite)
                Else
                    blkRec = acTrans.GetObject(blktable(TagName), OpenMode.ForWrite)
                    blkRef = New BlockReference(InsPoint, blkRec.ObjectId)
                End If

                DOC.Window.Focus()
                Dim ppr As PromptPointResult
                blkRef.Layer = "0"
                pprSpace.AppendEntity(blkRef)

                'Get and activate atts:
                For Each attID As ObjectId In blkRec
                    Dim obj As DBObject = acTrans.GetObject(attID, OpenMode.ForRead)
                    Try
                        Dim attdef As AttributeDefinition = CType(obj, AttributeDefinition)
                        Dim attref As New AttributeReference
                        attref.SetAttributeFromBlock(attdef, blkRef.BlockTransform)
                        blkRef.AttributeCollection.AppendAttribute(attref)
                        acTrans.AddNewlyCreatedDBObject(attref, True)
                    Catch
                    End Try

                Next

                For Each attID As ObjectId In blkRef.AttributeCollection
                    Dim attRef As AttributeReference = acTrans.GetObject(attID, OpenMode.ForWrite)
                    If attRef.Tag = "P_ITEM" Then
                        attRef.TextString = TagVal 'change after split
                    ElseIf attRef.Tag = "P_TEXT" Then
                        attRef.TextString = TagVal 'change after split
                    End If

                Next

                'Rotate Block?:
                If RotateBool = True Then
                    blkRef.TransformBy(Matrix3d.Rotation(DegToRad(90), blkRef.Normal, blkRef.Position))
                Else
                    blkRef.TransformBy(Matrix3d.Rotation(DegToRad(0), blkRef.Normal, blkRef.Position))
                End If

                acTrans.AddNewlyCreatedDBObject(blkRef, True)
                ed.UpdateScreen()

                ''Drag the block: =======================================================
                Dim psr As PromptSelectionResult = ed.SelectLast
                If (psr.Status = PromptStatus.OK) Then
                    Dim pdo As New PromptDragOptions(psr.Value, "", New DragCallback(AddressOf MyDragCallback))
                    With pdo
                        .Message = CommandPrompt
                        .Keywords.Add("ROTATE", "R", "Rotate", True, True)
                    End With
                    pdo.Keywords.Default = "ROTATE"

                    'Drag
                    ppr = ed.Drag(pdo)
                    'Insertion Point picked:
                    If ppr.Status = PromptStatus.OK Then
                        Dim mat As Matrix3d = Matrix3d.Displacement(InsPoint.GetVectorTo(ppr.Value))
                        blkRef.TransformBy(mat)

                    ElseIf ppr.Status = PromptStatus.Keyword Then

                        'Rotate and start again:
                        If ppr.StringResult.ToUpper() = "ROTATE" Then
                            blkRef.Erase()
                            RotateBool = Not RotateBool
                            'RepeatBool = True
                            'newPrefix = True
                            GoTo QuickExit

                        End If
                    Else
                        blkRef.Erase()
                        GoTo QuickExit
                    End If

                End If
QuickExit:
                'Commit Transaction:
                acTrans.Commit()
                ed.Regen()
                ed.UpdateScreen()

            End Using 'End trans
        End Using 'end lock

    End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 01 Mar 2024 16:16:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12593500#M5258</guid>
      <dc:creator>Ender157</dc:creator>
      <dc:date>2024-03-01T16:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Inserted blocks disapear.</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12612276#M5259</link>
      <description>&lt;P&gt;It looks like your ReadBOM sub is not committing the transaction that it starts. The nested transactions in the other sub that it calls repeatedly are probably not necessary. Try refactoring your code to pass the transaction as an argument instead of starting a nested transaction on each Loop iteration.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 17:53:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12612276#M5259</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-03-04T17:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: Inserted blocks disapear.</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12616555#M5260</link>
      <description>&lt;P&gt;i can try it&amp;nbsp; &amp;nbsp;but, everything in readbom is OpenMode.ForRead so there is nothing to commit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 15:03:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12616555#M5260</guid>
      <dc:creator>Ender157</dc:creator>
      <dc:date>2024-03-05T15:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Inserted blocks disapear.</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12616567#M5261</link>
      <description>I will look through the insert sub to see if it can be simplified. (it is a copy from a different app where it worked) but i did change it .&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 05 Mar 2024 15:05:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12616567#M5261</guid>
      <dc:creator>Ender157</dc:creator>
      <dc:date>2024-03-05T15:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Inserted blocks disapear.</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12617877#M5262</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2095342"&gt;@Ender157&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;i can try it&amp;nbsp; &amp;nbsp;but, everything in readbom is OpenMode.ForRead so there is nothing to commit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You Insert the bocks inside the Transaction in ReadBOM so these will not remain if you don't commit the transaction.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 21:16:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12617877#M5262</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2024-03-05T21:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Inserted blocks disapear.</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12617948#M5263</link>
      <description>you are correct, Thank you. I have been looking at that for 2 days made me crazy, thanks again</description>
      <pubDate>Tue, 05 Mar 2024 21:37:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12617948#M5263</guid>
      <dc:creator>Ender157</dc:creator>
      <dc:date>2024-03-05T21:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Inserted blocks disapear.</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12618918#M5264</link>
      <description>&lt;P&gt;See my other reply&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 06:05:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12618918#M5264</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-03-06T06:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Inserted blocks disapear.</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12618943#M5265</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2095342"&gt;@Ender157&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;i can try it&amp;nbsp; &amp;nbsp;but, everything in readbom is OpenMode.ForRead so there is nothing to commit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Yes, there is something to commit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any changes made to the database during the life of the &lt;STRONG&gt;&lt;EM&gt;outermost&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;transaction will be &lt;EM&gt;rolled-back&lt;/EM&gt; if that outermost transaction is not committed (e.g., it aborts). That includes any changes made to objects that were obtained from any nested transactions, regardless of whether they were committed or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, in order for the changes you make in the sub to be committed, you must commit the outermost transaction. Also, it is recommended that transactions always be committed, regardless of whether changes were made or not. Aborting a transaction is generally not something you do explicitly, but rather because an exception caused a program to prematurely exit, and you want any changes that were made to be rolled back in that case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 06:04:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserted-blocks-disapear/m-p/12618943#M5265</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-03-06T06:04:45Z</dc:date>
    </item>
  </channel>
</rss>

