Rename a layout with ObjectDBX (VBA)

Rename a layout with ObjectDBX (VBA)

ragarcia
Enthusiast Enthusiast
3,209 Views
11 Replies
Message 1 of 12

Rename a layout with ObjectDBX (VBA)

ragarcia
Enthusiast
Enthusiast

I need to rename a layout from a .dwg document opened using ObjectDBX library (from Visual Basic for Applications). I tried this:

 

layout.Name="New name"

where "layout" is the layout object I want to modify.

 

Then I get an error:

 

layout does not exist for renaming

 

I need to do this without opening the file in Autocad. When I execute the same code from inside Autocad, it works perfectly. Maybe it can't be done by using ObjectDBX. Am I right?

 

Thanks.

0 Likes
Accepted solutions (1)
3,210 Views
11 Replies
Replies (11)
Message 2 of 12

Ed__Jobe
Mentor
Mentor

Is your layout variable getting set? It would help if you showed the rest of your code so we can see how you're setting the variable.

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 3 of 12

ragarcia
Enthusiast
Enthusiast

Yes, it is getting set. Here is the whole code:

 

Set objDbx = GetInterfaceObject("ObjectDBX.AxDbDocument.20")
objDbx.Open "C:\Users\PC\Desktop\Drawing.dwg"
Set lay = objDbx.Layouts.Item(0)
lay.Name = "New name"
Set objDbx = Nothing

It tries to rename the first layout tab as "New name".

 

0 Likes
Message 4 of 12

Ed__Jobe
Mentor
Mentor

If you set a breakpoint and step through your code, what is Layouts(0).Name equal to? It's "Model". You can't rename modelspace.

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 5 of 12

ragarcia
Enthusiast
Enthusiast

Thanks for the answer, but no. Layouts(0).Name is actually "1". The drawing has 8 layouts, named from "1" to "8" and these names are stored from Layouts(0) to Layouts(7). Layout(8) (the last one, not the first one) is the one that stores "Model".

0 Likes
Message 6 of 12

Ed__Jobe
Mentor
Mentor

How did you verify that? I'm pretty sure that Layouts(0) is always modelspace and you can't reorder that. You can add and delete paperspace layouts but the modelspace layout is fixed. Can you post a sample dwg?

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 7 of 12

ragarcia
Enthusiast
Enthusiast

I can see the value of Layers(0).Name in the debugger. I also used a variable to read it before the error takes place. Remember I said the problem does not happen when I change the layout name in Autocad without using ObjectDBX. I attached 2 files: one with the code and the other with the layouts I wanna change (It has only 2 layouts, but that makes no difference).

 

0 Likes
Message 8 of 12

ragarcia
Enthusiast
Enthusiast

I forgot to mention the code is embedded in the Main.dwg file. You can call it from Manage/Run VBA Macro. It's name is layout.

0 Likes
Message 9 of 12

Ed__Jobe
Mentor
Mentor
Accepted solution

My test shows that layouts are read only via odbx.

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 10 of 12

ragarcia
Enthusiast
Enthusiast

Thanks a lot for your help. I was afraid it might be so but I wasn't sure and thought there could be another way via ODBX.

0 Likes
Message 11 of 12

Anonymous
Not applicable

I am trying to exactly the same thing (rename layout tabs in multiple drawings via obdx). Is there any other way this can be achieved?

 

What did you do in the end ragarcia?

0 Likes
Message 12 of 12

Anonymous
Not applicable

as per Ed Jobe tests (see post #9) you can't do that via odbx, since in that context layout object is read-only. thus you can't change any of its properties

0 Likes