.NET

Reply
Distinguished Contributor
jboone
Posts: 167
Registered: ‎08-31-2006
Message 1 of 4 (211 Views)
Accepted Solution

Updating attributes of a selection set

211 Views, 3 Replies
08-01-2013 02:02 PM

I am trying to update blocks from a selection set and based on two specific attaributes.  I get and error eLockViolation

Not sure where it comes from since this is a dll.

 

 

      Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
      Dim db As Database = doc.Database
      Dim ed As Editor = doc.Editor
      Dim x As Integer = 0
      Dim tr As Transaction = db.TransactionManager.StartTransaction()

	  
	  


      MsgBox("Going into attribute write", MsgBoxStyle.OkOnly)
      Try
         Dim idArray As ObjectId() = selSet.GetObjectIds()
         For Each blkId As ObjectId In idArray
            Dim blkRef As BlockReference = DirectCast(tr.GetObject(blkId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), BlockReference)
            Dim btr As BlockTableRecord = DirectCast(tr.GetObject(blkRef.BlockTableRecord, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), BlockTableRecord)
            'ed.WriteMessage(vbLf & "Block: " + btr.Name)
            btr.Dispose()

            Dim attCol As AttributeCollection = blkRef.AttributeCollection
            For Each attId As ObjectId In attCol
               Dim attRef As AttributeReference = DirectCast(tr.GetObject(attId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), AttributeReference)


               'MsgBox("Block name: " & btr.AcadObject.ToString, MsgBoxStyle.OkOnly)
               'UpdateAttributesInBlock(attId, btr.AcadObject.ToString, "Block2NAME", TextVal)
               If attRef.Tag = "BlockPANEL" Then
                  attRef.UpgradeOpen()
                  attRef.TextString = TextVal
                  attRef.DowngradeOpen()
                  MsgBox("Wrote Block: " & TextVal, MsgBoxStyle.OkOnly)
               ElseIf attRef.Tag = "Block2PANEL" Then
                  attRef.UpgradeOpen()
                  attRef.TextString = TextVal
                  attRef.DowngradeOpen()
                  MsgBox("Wrote Block2: " & TextVal, MsgBoxStyle.OkOnly)
               End If

               If attRef.Tag = "BlockAttVal" Then
                  attRef.UpgradeOpen()
                  attRef.TextString = AttValNumber
                  attRef.DowngradeOpen()
               ElseIf attRef.Tag = "Block2AttVal" Then
                  attRef.UpgradeOpen()
                  attRef.TextString = AttValNumber
                  attRef.DowngradeOpen()
               End If
               x = x + 1
            Next
         Next
         tr.Commit()
         Str = ("Total number of blocks changes: " & x.ToString)
         ed.WriteMessage(WattageStr)
      Catch ex As Autodesk.AutoCAD.Runtime.Exception
         ed.WriteMessage(("Exception: " & ex.Message & vbCrLf))
         Exit Function
      Finally
         tr.Dispose()
      End Try

 

Distinguished Contributor
jboone
Posts: 167
Registered: ‎08-31-2006
Message 2 of 4 (207 Views)

Re: Updating attributes of a selection set

08-01-2013 02:10 PM in reply to: jboone

Oh the selection set is being stoed as a globel from another command.  Not sure if all this is logical.

 

 

   Public selSet As SelectionSet

 

*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 3 of 4 (198 Views)

Re: Updating attributes of a selection set

08-01-2013 02:44 PM in reply to: jboone

http://forums.autodesk.com/t5/NET/eLockViolation/m-p/2490289/highlight/true#M14566

---------------------------



(defun botsbuildbots() (botsbuildbots))
Distinguished Contributor
jboone
Posts: 167
Registered: ‎08-31-2006
Message 4 of 4 (194 Views)

Re: Updating attributes of a selection set

08-01-2013 02:49 PM in reply to: arcticad

Wow thanks.  That worked great!.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!