Redefine Block definition from another file

Redefine Block definition from another file

GilesPhillips
Collaborator Collaborator
2,567 Views
9 Replies
Message 1 of 10

Redefine Block definition from another file

GilesPhillips
Collaborator
Collaborator

Anyone got any idea how I can get VBA to insert/redefine a block reference from another file into a block (of the same name) that already exists in the target drawing?

 

I've tried using the insertblock method but it produces a 'filer error' - and I'm not sure it's the right way to approach this anyway..

 

Anyone got any thoughts? I've read an older posts that uses some sort of objectdbx reference that I've not run into before but I can't get the code to work - I'm guessing I need to reference some other type library but I've no idea which or what..

 

As a bonus point, it'd would also be good to be able to retrieve the contents of the blocks collection in the source drawing in some clever way other than opening it (a bit like browsing using the design centre) - is it at all possible?

 

cheers

 

G

ACad, MEP, Revit, 3DS Max
0 Likes
2,568 Views
9 Replies
Replies (9)
Message 2 of 10

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> insert/redefine a block reference from another file into a block (of the same name) that already exists in the target drawing?

If I understand you correctly "insert a blockreference into a block of the same name" ==> that would not work because then you would have a circular reference. That has to be avoided an could therefor be the reason why AutoCAD creates an exception.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 10

GilesPhillips
Collaborator
Collaborator

Sorry, I worded the question badly.

 

I'm trying to automate the process of updated a block reference in a file to be the same as a block reference in anothe file - the VBA equivilent of using the redefine option when importing an existing block from the design centre.

 

I've since managed to get some code relating to objectdbx working, and have posted below for future reference, though I've not put any error trapping in there so it'll probably fail spectacularly if any of the blocks are missing:

 

Function UpdateBlock(SourceDrawing As String, BlockName As String) As Boolean

Dim ObjDbx As AxDbDocument
Dim SrcBlock As AcadBlock
Dim DestBlock As AcadBlock
Dim EntCnt As Integer
Dim CopyArray() As Object
Dim BlkEnt As AcadEntity

Set DestBlock = ThisDrawing.Blocks.Item(BlockName) 'block to be updated in current acad file
Set ObjDbx = ThisDrawing.Application.GetInterfaceObject("objectdbx.axdbdocument.18")
ObjDbx.Open SourceDrawing 'open source file to read block
Set SrcBlock = ObjDbx.Blocks.Item(BlockName) 'block used to update current block

ReDim CopyArray(SrcBlock.Count - 1) 'size array for number of entities in block
For EntCnt = 0 To UBound(CopyArray)
    Set CopyArray(EntCnt) = SrcBlock.Item(EntCnt) 'copy entities into array
Next EntCnt
'empty destination block:
For Each BlkEnt In DestBlock
    BlkEnt.Delete
Next BlkEnt
'copy array into destination block
ObjDbx.CopyObjects CopyArray, DestBlock
'update
For Each BlkEnt In DestBlock
    BlkEnt.Update
Next BlkEnt
'update dwg
ThisDrawing.Regen acActiveViewport
end function

 

G

ACad, MEP, Revit, 3DS Max
Message 4 of 10

JBerns
Advisor
Advisor

@GilesPhillips,

 

I realize this is an old post, but perhaps a solution can be offered.

Do you know if an equivalent function exists in the Visual LISP language? I am not as experienced with VBA as I am LISP.

Otherwise, could this VBA function be called from Auto/Visual LISP?

 

Kind regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 5 of 10

Ed__Jobe
Mentor
Mentor

A search of the lisp forum for "redefine block" returns these results.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 6 of 10

JBerns
Advisor
Advisor

@Ed__Jobe,

 

Thank you, but I have been searching the forums for the past day using terms such as redefine, block, tool, palette, etc. I don't post until I am at a roadblock.

 

 

I have received plenty of suggestions for using -INSERT BLOCK=BLOCK, but respondents are not reading my full request.

 

I just found this post a few minutes ago and it is the closest to accomplishing the goal of inserting a block from a source drawing to redefine a block in the active drawing.

https://forums.autodesk.com/t5/visual-basic-customization/redefine-block-definition-from-another-fil...

Be aware, the source drawing is a library drawing which contains multiple block definitions. The blocks are not saved as individual drawings.

 

Unfortunately, the code in the link above uses VBA which adds another level of complexity to the solution. I was hoping to do this all with Visual LISP. I tried to run the VBA code, but get a user-defined type error. I am researching that now.

 

I am trying to learn the secret of the Tool Palette context menu Redefine option.

2019-01-11_7-06-31.png

Trust me, it is not -INSERT Block=Block. That does not work with library drawings that are leveraged by Tool Palette.

 

Thanks again for your time and search suggestion.

 

 

Regards,

Jerry

 

 

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 7 of 10

Ed__Jobe
Mentor
Mentor

If you just copied the code as-is, you probably need to set a reference to it's type library. Go to Tools>References and select "AutoCAD/ObjectDbx Common ##.0 Type Library" where ## is appropriate for the version of AutoCAD you are using. The sysvar ACADVER will tell you. And you will also need to change the class id in the call from GetInterfaceObject.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 8 of 10

JBerns
Advisor
Advisor

@Ed__Jobe,

 

Good news, I resolved the issue with the References required. The code is working great! I can redefine a block from a Source (library) drawing.

 

Thanks,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 9 of 10

GilesPhillips
Collaborator
Collaborator

Hi Jerry,

 

sorry for the late reply, I'm not as well versed in lisp as I am in VBA, though it can be a very powerful tool, and I believe it can access a lot more core components than you'd think, however I'm not sure where to start beyond looking at the activeX extension for lisp which seem to be where the "power functions" live.

 

hope this helps, though it looks like you're seeing some success with my VBA code- glad it's helping.

ACad, MEP, Revit, 3DS Max
0 Likes
Message 10 of 10

JBerns
Advisor
Advisor

@GilesPhillips,

 

Your response and generosity to the community are appreciated.

I am confident I can get a single language solution or count on the Community to assist with the merger of the two languages.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes