Something that should be really simple................

TheMightySpud

Boy Genius - Sort of.
......but I'm having such a problem finding anything in the SDK docs about this.

How do you simply load an object into layout using Python?

Working on something and this is my last stumbling block.

Thanks
TheMightySpud
 

BeeVee

ex-LightWave documentation
I'm no Python expert, but I would say you want to use a LightWave command through Python. Check the SDK docs for Loading and the Command List...

B
 

TheMightySpud

Boy Genius - Sort of.
This is petty much my problem, I'm finding the docs to be absolute garbage, I've been through numerous times and can't see anything to do with loading an object. :-/
 

dpont

Member
in the SDK html "commands" folder, layout.html
->Object,
LoadObject sfilename

Also in Layout/Utilities/ a "Save Cmd List" button will save a file with all available commands.

There are several sample python scripts in Generic folder,
for examples of Command synthax.

Denis.
 

TheMightySpud

Boy Genius - Sort of.
I've been looking at the LoadObject command but can't for the life of me figure it out. Might be just tired. Giving up for today.
 

dpont

Member
In support/scripts/Python/Layout/Generic
there's a Add_Null/py script, good template for beginning,
see how the AddNulll command is handled.

Denis.
 

dpont

Member
there's also a Proxi with PRIS (see the online Lightwave Python doc)
lwsdk.pris.layout.cs.loadobject(filename)

lscript has also a proxy, this is even simpler, except the double backslash,

@warnings
@name "Load Object"

generic
{
LoadObject("D:\\3D\\LWContent\\Objects\\Box.lwo");
}

Denis.
 

Kryslin

Active member
It appears that you have to go through the following steps:

Code:
import lwsdk

def process (self, ga)
   name = "myfilename.lwo"
   result = ga.evaluate(ga.data, "LoadObject %s" % name)
(This is taken from the 'add_scene_comment.py' example.)

or something similar.

you could also use the (much maligned) PRIS, which has a proxy for the LoadObject command...
Code:
 lwsdk.pris.layout.cs.loadobject(filename)
 

TheMightySpud

Boy Genius - Sort of.
This is now driving me insane. I've tried both of the solutions provided by Kryslin, but still not doing anything. I'm not getting any errors, but the scripts don't load in the object.

I'm probably doing something really silly wrong.

Here's the 'non-pris' version of the script.

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

"""
This is a LightWave Generic plug-in that adds a new Null object
and positions it at <0, 1, 0>.
"""

import sys
import lwsdk

class Load_Object(lwsdk.IGeneric):
    def __init__(self, context):
        super(Load_Object, self).__init__()

        def process (self, ga):
            name = "F:\StaticModels\Objects\Aset_qkduW_ZTool.lwo"
            result = ga.evaluate(ga.data, "LoadObject %s" % name)

            return lwsdk.AFUNC_OK
   
ServerTagInfo = [
                    ( "Load_Object", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
                    ( "Load Object", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
                    ( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
                ]

ServerRecord = { lwsdk.GenericFactory("LW_LoadObject", Load_Object) : ServerTagInfo }

Can anybody see where I'm going wrong? :-/

Thanks
TheMightySpud
 

KANUSO

New member
Hi,

I don't know if this is the solution, but I think your indentation is wrong.
The script does nothing visible... because the "process is declared as a sub-func of __init__
I think it should look like:
Code:
#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-

"""
This is a LightWave Generic plug-in that adds a new Null object
and positions it at <0, 1, 0>.
"""

import sys
import lwsdk

class Load_Object(lwsdk.IGeneric):
    def __init__(self, context):
        super(Load_Object, self).__init__()

    # the complete process-func goes 4 spaces to the left, so process is no longer a Sub func of __init__
    def process (self, ga):
        name = "F:\StaticModels\Objects\Aset_qkduW_ZTool.lwo"
        result = ga.evaluate(ga.data, "LoadObject %s" % name)

        return lwsdk.AFUNC_OK
   
ServerTagInfo = [
                    ( "Load_Object", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
                    ( "Load Object", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
                    ( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
                ]

ServerRecord = { lwsdk.GenericFactory("LW_LoadObject", Load_Object) : ServerTagInfo }

Take a deeper look at your filename. in win-based Environments the \ is represented as \\


I hope this helps you any further

Regards,
Kanuso
 
Last edited:

Ryan Roye

Animator
You need only 2 lines of code to do this...

Code:
import lwsdk
lwsdk.command("LoadObject C:\\myfolder\\Objects\\MyObject.lwo")

Single shot plugins (AKA generic plugins) don't require Lightwave's fancier classes and functions, you can skip them alltogether. Unfortunately the LWSDK's documentation is only in place as a reference... it doesn't do much to help you take advantage of the sdk.

If you find yourself getting stuck and its a simple matter, i'll try and make sure you get the info you need.
 
Top Bottom