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

changing blocks

2 REPLIES 2
Reply
Message 1 of 3
coralie.jacobi
303 Views, 2 Replies

changing blocks

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

2 REPLIES 2
Message 2 of 3

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

 

Message 3 of 3
zrobert
in reply to: coralie.jacobi

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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost