PDA

View Full Version : Execute Modeler's CloseAll



nickdigital
08-02-2013, 02:19 PM
How does one call Modeler's CloseAll? I have:


lwsdk.ICommandSequence(CLOSE_ALL)

But I get NameError: global name 'CLOSE_ALL' is not defined.

I'm admittedly new to python. I can fumble my way through the code. What's slowing me down is having to reference the LW sdk and figuring out how to tie everything together.

BigHache
08-02-2013, 06:47 PM
I have not learned the single shot method, but the long way is described here:
http://www.lawson3d.com/lwpywiki/index.php?title=Commands
http://www.lawson3d.com/lwpywiki/index.php?title=Modeler_Commands

Once we get documentation about PRIS I have a feeling this will change considerably.

nickdigital
08-02-2013, 07:29 PM
Ok, maybe I'll wait. I'm already confused enough, lol.

iain_r
08-03-2013, 05:05 AM
#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-

"""
This is a LightWave Command Sequence plug-in (Modeler) that closes all objects

"""

import sys
import lwsdk

__author__ = "Iain"
__date__ = "03 Aug 2013"
__copyright__ = ""
__version__ = "1.0"
__maintainer__ = "Iain"
__email__ = ""
__status__ = "Example"
__lwver__ = "11"

class cmd_test(lwsdk.ICommandSequence):
def __init__(self, context):
super(cmd_test, self).__init__()


# LWCommandSequence -----------------------------------
def process(self, mod_command):
cs_cmd = mod_command.lookup(mod_command.data, "CLOSE_ALL")
result, dyna_value = mod_command.execute(mod_command.data, cs_cmd, "", lwsdk.OPSEL_GLOBAL)

return lwsdk.AFUNC_OK


ServerTagInfo = [
( "Python Cmd Test", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "Cmd Test", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]

ServerRecord = { lwsdk.CommandSequenceFactory("LW_PyCmdTest", cmd_test) : ServerTagInfo }


I've tried this with 11.5, loaded a bunch of objects then run this script. Closes all.

Regards

Iain

nickdigital
08-03-2013, 09:55 AM
Thanks!

Celshader
08-24-2013, 10:26 AM
I have not learned the single shot method

For what it's worth, here is the single-shot version of Iain's script. I have tested it in Modeler 11.5.1 and Modeler 11.5.


import lwsdk

mod_command = lwsdk.ModCommand()
cs_cmd = mod_command.lookup("CLOSE_ALL")

mod_command.execute(cs_cmd, "", lwsdk.OPSEL_GLOBAL)



#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-

"""
This is a LightWave Command Sequence plug-in (Modeler) that closes all objects

"""

import sys
import lwsdk

__author__ = "Iain"
__date__ = "03 Aug 2013"
__copyright__ = ""
__version__ = "1.0"
__maintainer__ = "Iain"
__email__ = ""
__status__ = "Example"
__lwver__ = "11"

class cmd_test(lwsdk.ICommandSequence):
def __init__(self, context):
super(cmd_test, self).__init__()


# LWCommandSequence -----------------------------------
def process(self, mod_command):
cs_cmd = mod_command.lookup(mod_command.data, "CLOSE_ALL")
result, dyna_value = mod_command.execute(mod_command.data, cs_cmd, "", lwsdk.OPSEL_GLOBAL)

return lwsdk.AFUNC_OK


ServerTagInfo = [
( "Python Cmd Test", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "Cmd Test", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]

ServerRecord = { lwsdk.CommandSequenceFactory("LW_PyCmdTest", cmd_test) : ServerTagInfo }


I've tried this with 11.5, loaded a bunch of objects then run this script. Closes all.

Regards

Iain

Thank you for sharing this script, Iain. I used your script as the starting point for the single-shot version shown above.

nickdigital
08-24-2013, 11:03 AM
Good info Jen. I'm hoping to translate my existing lscripts to python and so far it's been a slow process for me.

BigHache
08-27-2013, 10:09 PM
Thanks Jen. I've been focusing on non Python projects lately. Hoping to get back into this.

Thanks for the SIGGRAPH vids too. Love the info.

shrox
08-27-2013, 10:42 PM
Code is bad, me want GUI!

I should learn something more than HTML I guess, at least I should learn lscripts.

Celshader
08-31-2013, 12:09 PM
Thanks Jen. I've been focusing on non Python projects lately. Hoping to get back into this.

Thanks for the SIGGRAPH vids too. Love the info.

Cool. I am glad you found the SIGGRAPH vids informative.

I wish to thank you again for providing the LwPy Wiki framework so that folks like me can post information there in an organized manner.

I just fleshed out the following LwPy Wiki pages with more code examples and info:

Getting Started - "Hello World" in Layout (http://www.lawson3d.com/lwpywiki/index.php?title=Getting_Started_-_%22Hello_World%22_in_Layout) - added 11.5+ single-shot example to the top.

LWDirInfoFunc (http://www.lawson3d.com/lwpywiki/index.php?title=LWDirInfoFunc)

LWFileReqFunc (http://www.lawson3d.com/lwpywiki/index.php?title=LWFileReqFunc)

LWMessageFunc (http://www.lawson3d.com/lwpywiki/index.php?title=LWMessageFuncs)

I'll post more soon when I can.