ObjDbx & Layout Name

ObjDbx & Layout Name

pranieriADNKG
Explorer Explorer
825 Views
6 Replies
Message 1 of 7

ObjDbx & Layout Name

pranieriADNKG
Explorer
Explorer

Ho to all,

I'm trying to change the layout name trough ObjDbx.

I have a lot of drawings, I'm able to open them by ObjDbx and find object inside, eg blocks and related attributes.

What I'm not able to do is change the layout name, inside the drawing there is only one layout and I want to rename it based upon sheet number, but I got an error if I wrote following syntax

ObjDbx.Layouts(1).Name="01"

but I got an error.

Thank you

0 Likes
Accepted solutions (1)
826 Views
6 Replies
Replies (6)
Message 2 of 7

norman.yuan
Mentor
Mentor

The index of the collections (AcadLayouts, AcadLayers, AcadBlocks...) starts from 0. So, the code should be:

 

objDbxDoc.Layouts(0).Name="NewName"

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 7

pranieriADNKG
Explorer
Explorer

Hi Norman, I'll try but reading posts from other guys on same argument seems cannot be be changed by ObjDbx. Could you confirm or the main issue it's related to the item number ?.

Thank you

0 Likes
Message 4 of 7

Ed__Jobe
Mentor
Mentor

I think I came across something just the other day, but I don't remember where is was, but it said that the Layout object is read-only when using ObjectDbx.

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 7

daniel_cadext
Advisor
Advisor

I tried with  dbx and I get  'Layout does not eixst for renaming',

a legit Autodesk exception because of the typo? ( I’m kidding : )  )

your only choice appears to be ARX, or .NET. I used python just because its fast for prototyping …

 

 

 

import traceback
import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed

import AxApp24 as Ax

# fails with 'Layout does not eixst for renaming'
def PyRxCmd_doit2():
    try:
        dbx = Ax.getDbx()
        dbx.Open("e:\\06457Submittal.dwg")

        layout: Ax.IAcadLayout
        for layout in dbx.Layouts:
            if layout.Name == "Model":
                continue
            if layout.Name.startswith('S'):
                print(layout.Name)
                layout.Name = "{} +1".format(layout.Name)

        dbx.SaveAs("e:\\06457SubmittalNew.dwg")

    except Exception as err:
        traceback.print_exception(err)

#works
def renameLayout(db : Db.Database):
    token = Db.LayoutManager.setupForLayouts(db)
    mgr = Db.LayoutManager()
    mgr.renameLayout("S1", "S1 WOOOHOO",db)
    Db.LayoutManager.clearSetupForLayouts(token)
    
def PyRxCmd_doit():
    try:
        sidedb = Db.Database(False,True)
        sidedb.readDwgFile("e:\\06457Submittal.dwg")
        sidedb.closeInput(True)
        renameLayout(sidedb)
        sidedb.saveAs("e:\\06457SubmittalNew.dwg")
    except Exception as err:
        traceback.print_exception(err)

 

 

layout.png

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 6 of 7

grobnik
Collaborator
Collaborator

Hi thank you for suggestion,

Wherw I can found more on Autocad and PYTHON ?

I tried your link but seem you have to install before PYTHON.

 

More suggestions ?

0 Likes
Message 7 of 7

daniel_cadext
Advisor
Advisor
Accepted solution

There’s a couple of options, you can use win32com & pywin32, this will access AutoCAD’s ActiveX API

There’s pyautoacad on PyPi, this also uses ActiveX, but has some useful wrappers.

Another notable option is to use IronPython and .NET

 

There’s PyRx, which is the project I’m working on, its Python wrappers around ARX

Has fun stuff like Jigs, Overrules, Palettes etc. caveat, it’s still a work in progress and assumes some cad API knowledge

 

PyRx, Python for AutoCAD

1, install python 3.10.10

2, install wxPython 4.2.0 using PIP  (used for dialogs and palettes)

3, run the installer that’s on GitHub  See:

https://github.com/CEXT-Dan/PyRx/blob/main/README.txt

https://github.com/CEXT-Dan/PyRx/blob/main/READMEINSTALL.txt

 

If you need help on these modules, please ask at the swamp as not to annoy the VBA users here

https://www.theswamp.org/index.php?topic=58162.0

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes