Valued Contributor
Posts: 55
Registered: ‎11-12-2012
Message 1 of 3 (136 Views)

changing blocks

136 Views, 2 Replies
11-07-2013 08:34 AM

Looking for some advice on what the best way to proceed is. I'm still pretty new to object oriented programming.


I have a series of blocks with all the same attribute tag names. I need to create a function that allows me to change a block from one to another within a drawing.


Can I do this by just changing the blockID? or do I need to go through and grab all the info from the old block and insert a new block with the attribute values and then delete the old block.


Any suggestions are welcome.




Valued Contributor
Posts: 55
Registered: ‎11-12-2012
Message 2 of 3 (121 Views)

Re: changing blocks

11-07-2013 11:26 AM in reply to: cjacobi

So I've started writing some code, but now I'm stuck because both the BlockName and BlockID of the block I want to change are read-only....can someone help me out to what I'm doing wrong...or point me in the correct direction.



 <CommandMethod("swapblk")> _
    Public Sub swapblk()
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim doc As Document = DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor

        Dim newblockresult As PromptResult = ed.GetString("New block name: ")
        If newblockresult.Status = PromptStatus.OK Then
            Dim newblockname As String = newblockresult.StringResult.ToString

            Using Trans As Transaction = doc.TransactionManager.StartTransaction
                Dim myBlockTable As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
                If myBlockTable.Has(newblockname) = True Then
                    Dim TVs(0) As TypedValue
                    TVs(0) = New TypedValue(DxfCode.Start, "INSERT")
                    Dim MYfILTER As New SelectionFilter(TVs)
                    Dim PSR As PromptSelectionResult = ed.GetSelection(MYfILTER)
                    If IsNothing(PSR.Value) = False Then
                        For Each myOBJID As ObjectId In PSR.Value.GetObjectIds
                            Dim myblockref As BlockReference = myOBJID.GetObject(OpenMode.ForWrite)
                            Dim blkname As String = myblockref.BlockName

                    End If
                    MsgBox("New block must be already defined within the drawing")
                End If

            End Using
        End If
    End Sub


Posts: 18
Registered: ‎08-28-2009
Message 3 of 3 (99 Views)

Re: changing blocks

11-07-2013 11:19 PM in reply to: cjacobi



Try solution from this post. It seems very similar to your problem.

If you can't solve it, come again...




Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.