PyRx icon indicating copy to clipboard operation
PyRx copied to clipboard

``getActiveLayoutName`` returns the name for the current db

Open gswifort opened this issue 1 year ago • 1 comments

getActiveLayoutName method returns the layout name for the current document, but setCurrentLayout sets the active layout for the given db.

import traceback

from pyrx_imp import Db


def PyRxCmd_doit1():
    try:
        db = Db.Database(False, True)
        db.readDwgFile(r"...")
        lm = Db.LayoutManager()
        active_layout = lm.getActiveLayoutName(True, db)  # bug..?
        print(active_layout)
    except Exception:
        traceback.print_exc()


def PyRxCmd_doit2():
    try:
        db = Db.Database(False, True)
        db.readDwgFile(r"...")
        lm = Db.LayoutManager()
        lm.setCurrentLayout("Model", db)
        db.saveAs(r"...")
    except Exception:
        traceback.print_exc()

gswifort avatar Aug 06 '24 06:08 gswifort

Looks like a bug in ZwCAD, as it’s different behavior than AutoCAD

typically, when using a side database, you should acquire a token for the database as in ‘testLayoutManagerSample.py’ but it seems this is missing in ZwCAD as well.

Another option is temporarily set the working database to the side database , try this

from pyrx_imp import Ap, Db, Ed, Ge, Gi, Gs, Rx
import traceback

def PyRxCmd_doit1():
    try:
        curDb = Db.curDb()
        
        sideDb = Db.Database(False, True)
        sideDb.readDwgFile(r"e:/06457Submittal.dwg")
        
        #set the working database
        # short version of Db.HostApplicationServices().setWorkingDatabase(sideDb)
        Db.setWorkingDb(sideDb) 
    
        lm = Db.LayoutManager()
        active_layout = lm.getActiveLayoutName(True) 
        
        print(active_layout)
    except Exception as err:
        traceback.print_exception(err)
    finally:
        #make sure you restore the database or the app will probably crash
        Db.setWorkingDb(curDb)
        

def PyRxCmd_doit2():
    try:
        curDb = Db.curDb()
        sideDb = Db.Database(False, True)
        sideDb.readDwgFile(r"e:/06457Submittal.dwg")
        
        # this forces the entire database to be loaded into memory
        # if it's a big drawing that is partially loaded, saveas call can fail
        # with the same drawing path
        sideDb.closeInput(True)
        
        #set the working database
        Db.setWorkingDb(sideDb)
        lm = Db.LayoutManager()
        lm.setCurrentLayout("Model")
        
        sideDb.saveAs(r"e:/06457Submittal.dwg")
        
    except Exception as err:
        traceback.print_exception(err)
    finally:
        #make sure you restore the database or the app will probably crash
        Db.setWorkingDb(curDb)
        

CEXT-Dan avatar Aug 06 '24 07:08 CEXT-Dan

This seems to work on all platforms, I probably won't report this to zw

CEXT-Dan avatar Aug 25 '24 09:08 CEXT-Dan