Arx users will immediately recognize this layout as it’s similar
to AcRxArxApp, I actually considered making the entry point a class in Python,
but it seemed overkill at the time.
After running the command ‘pyload’ or ‘pyreload’ to load
your module, OnPyInitApp and OnPyLoadDwg are called, functions that are
prefixed with PyRxCmd_ are registered as commands, functions that are prefixed
as PyRxLisp_ are registered as lisp callable functions. Note, this only the
file that is being loaded is parsed, imports are not parsed.
When registering and command with PyRxCmd_ the group name is
the module name, the global name and local name are the same. Command flags are
optional, with the default being ACRX_CMD_MODAL. These flags may be OR’d. I may
wrap acedRegCmds->addCommand at some point, but the design intent is to be
simple.
#import
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 traceback
#optional called when the app is loaded
def OnPyInitApp():
print("\nOnPyInitApp")
#optional called when the app is inloaded
def OnPyUnloadApp():
print("\nOnPyUnloadApp")
#optional called when a drawing is opened
def OnPyLoadDwg():
print("\nOnPyLoadDwg")
#optional called when a drawing is closed
def OnPyUnloadDwg():
print("\nOnPyUnloadDwg")
# prefix PyRxCmd_ defines a command
# CmdFlags is optional, default is modal
def PyRxCmd_mycommand(CmdFlags = Ap.CmdFlags.TRANSPARENT):
try:
print("Hello world!")
except Exception as err:
traceback.print_exception(err)
# prefix PyRxLisp_ defines a lisp function
# (mylisp '("hello world" 1 2 3 4 (1 10 100)))
def PyRxLisp_mylisp(args):
try:
return args
except Exception as err:
print(err)
No comments:
Post a Comment