Results 1 to 14 of 14

Thread: Something that should be really simple................

  1. #1

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

    ......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

  2. #2
    LightWave documentation BeeVee's Avatar
    Join Date
    Feb 2003
    Location
    Pessac
    Posts
    5,107
    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
    Ben Vost - NewTek LightWave 3D development
    LightWave 3D Trial Edition
    AMD Threadripper 1950X, Windows 10 Pro 64-bit, 32GB RAM, nVidia GeForce GTX 1050Ti (4GB and 768 CUDA cores) and GTX 1080 (8GB and 2560 CUDA cores) driver version 430.86
    AMD FX8350 4.2 GHz, Windows 7 SP1 Home Premium 64-bit, 16GB RAM, nVidia GeForce GTX 1050Ti (416.34, 4GB and 768 CUDA cores)
    Dell Server, Windows 10 Pro, Intel Xeon E3-1220 @3.10 GHz, 8 GB RAM, Quadro K620
    Laptop with Intel i7, nVidia Quadro 2000Mw/ 2GB (377.83 and 192 CUDA cores), Windows 10 Professional 64-bit, 8GB RAM
    Mac Mini 2.26 GHz Core 2 Duo, 4 GB RAM, 10.10.3

  3. #3
    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. :-/

  4. #4
    Member
    Join Date
    May 2006
    Location
    France
    Posts
    4,084
    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.

  5. #5
    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.

  6. #6
    Member
    Join Date
    May 2006
    Location
    France
    Posts
    4,084
    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.

  7. #7
    Member
    Join Date
    May 2006
    Location
    France
    Posts
    4,084
    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.

  8. #8
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,530
    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)
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  9. #9
    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

  10. #10
    Member
    Join Date
    May 2006
    Location
    France
    Posts
    4,084
    I think you need at least the declaration of the __lwver__

    Denis.

  11. #11
    Member
    Join Date
    May 2006
    Location
    France
    Posts
    4,084
    Also the double backslash because it's a special character.

    Denis.

  12. #12
    Member
    Join Date
    May 2006
    Location
    France
    Posts
    4,084
    ...And finally, the def process should not be indented to def _Init.

    Denis.

  13. #13
    Registered User
    Join Date
    May 2017
    Location
    Lampertheim, Germany
    Posts
    130
    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:
    Quote Originally Posted by TheMightySpud View Post
    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 by KANUSO; 10-25-2019 at 05:49 AM.

  14. #14
    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.
    Professional-level 3d training: Ryan's Lightwave Learning
    Plugin Developer: RR Tools for Lightwave

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •