.NET

Reply
Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 1 of 3 (134 Views)

changing blocks

134 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.

 

thanks

cj

Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 2 of 3 (119 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.

 

thanks

 <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

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

            End Using
        End If
    End Sub

 

Contributor
zrobert
Posts: 18
Registered: ‎08-28-2009
Message 3 of 3 (97 Views)

Re: changing blocks

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

Hi;

 

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

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

 

http://forums.autodesk.com/t5/NET/Replace-Block-Record/td-p/3566644

 

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.