Page 14 of 14 FirstFirst ... 4121314
Results 196 to 199 of 199

Thread: Kryslin's lScripts

  1. #196
    Electron wrangler jwiede's Avatar
    Join Date
    Aug 2007
    Location
    San Jose, CA
    Posts
    6,971
    Quote Originally Posted by Kryslin View Post
    I might even put together a document called "So you want to write a LW UI in Python" with my notes in a somewhat organized fashion to share.
    Always a good idea. Organizing your notes for others to view will often grant even deeper understanding of that content.

    Meanwhile, Newtek MUST do a better job of documenting those aspects of Python SDK. There are still major aspects of LW plugin development in Python which are simply not covered, and that needs to come from Newtek, or most third-party LW Python devs will quickly get exasperated and give up. Leaving devs to reverse engineer Panels Python bindings from a few, very meager examples is just asking too much.

    Whether or not third-party devs can and do provide help/guidance, SDK holes this large tend to drive devs away from platforms rightly interpreting such treatment as "uncaring platform developer". Few devs will invest time and effort into deeply understanding a platform knowing the SDK has huge holes, isn't being well-maintained, etc. because those are all signs their time and effort required to understand and develop for a platform will provide no RoI, only pain.
    John W.
    LW2015.3UB/2019.1.5 on MacPro(12C/24T/10.13.6),64GB RAM, NV 980ti

  2. #197
    Eat your peas. Greenlaw's Avatar
    Join Date
    Jul 2003
    Location
    Los Angeles
    Posts
    7,277
    Thanks Kryslin and JWeide. I'm glad to hear you're making progress! Please keep up the great work.

    Re: your Python document, yes, any new learning material is welcome! I took a Python class at work and I occasionally dabble with it at home (very minor stuff) but I'd like to get more serious about it.

  3. #198
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,612
    A basic UI for a few simple parameters, like color, or distance, or a boolean choice...

    Not all that hard. When you want to start hiding / swapping controls around... The fun begins.

    If you have ODTools, the Auto GUI tool will meet 75%-90% of your UI needs.

    However, something like my Style Combing script, that requires are bit more know-how.

    I'll get my notes in order, and post them somewhere...
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  4. #199
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,612

    So you want to write a UI in Python...

    This is my initial example for UI programming in Python.
    I'm using the one-shot format for this example, a future example will use the Class Based form.
    And, while I ran it it Modeler, it should work in Layout as well.

    Feel free to point out where I've made mistakes as well.

    - - - - - - - - - -

    So, You want to program a UI for a Lightwave Python Script?
    (Notes are current as of Lightwave 2020.0.1)

    So you have this neat idea for a Lightwave script, and you know Python, and it requires a UI.

    When you go flipping through the Lightwave Python documentation, you find that there is absolutely no documentation on UI programming in the Python SDK documents, and when you ask on the Lightwave forums, they tell you to use the documentation for the C SDK, which is not very helpful, since they also tell you it's almost a one for one match, but neglect to tell you what doesn't match up.

    I hope to alleviate this lack of knowledge.

    A simple UI that requires only parameter entry isn't that difficult, it turns out, its just made harder to do because the documentation doesn't exist (and has been reported as such twice, and no action has been taken yet).

    First, like any Python plugin for Lightwave, you'll need to import the lwsdk module.

    Code:
    import lwsdk
    Next, you'll need to do this:

    Code:
    #Your UI code starts here
    ui = lwsdk.LWPanels()
    panel = ui.create('Your Script's Name')
    #These are optional
    panel.setw(400)
    panel.seth(300)
    This creates the object for your panel, and allows you to access the methods to define your controls on the panel. If you do not specify a panel width or height, the UI module will automatically handle it. Otherwise, using the .setw(int Width) and .seth(int Height) methods allows you to set the panel's width and height, respectively.

    To add controls, you do the following:

    Code:
    my_control = panel.popup_ctl("Control Label",['Choice 1','Choice 2', 'Choice 3'])
    #This is optional
    my_control.move(5,5)
    This adds a popup control to the form, and moves it to position (5,5) from the upper left corner of the panel. If you do not specify a control position (the .move method), the UI module will handle it later.

    To have the UI toolkit handle your control position and alignment, you'll need this:

    Code:
    #Vertically Align Input areas
    panel.align_controls_vertical([my_control])
    #Resize panel to hold all the controls, plus margins
    panel.size_to_layout(5,5)
    If you are handling the positioning of your controls via the .move method, you do not need these two lines of code. If you are letting the .align_controls_vertical method handle your alignment, you need to pass it a list containing all your controls. You can either create the list as shown here, or append your control to the list using the .append method (mylist.append(my_control)), and pass the list name as your argument. Do not use .extend to add your controls to the list, this will cause a runtime error.

    To display your panel, you need the following:

    Code:
     
    if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0:
    	#The Cancel button has been pressed, Abort Execution...
    	ui.destroy(panel)
    	my_value = 0
    else:
    	my_value = my_control.get_int() + 1
    You need to supply flags to the panel.open() function, these determine if the panel is modal, non modal, and what buttons are displayed at the bottom of the panel; In this case, "OK" and "Cancel" buttons. In a Class style plugin, you would want to pass a return value to lightwave. In a one shot plugin, you need to handle it in another fashion. Usually, an else: statement.

    Code:
    else:
    	my_value = my_control.get_int() + 1
    This gets the value of the control, in this case, which choice we made. Because Python lists start at 0 instead of 1, we're adding a 1 to the output. We're using 0 as the no choice made value for this example.

    unlike LScript, which uses a generic getvalue(control name) function, getting values for a control in Python requires a .get_(type) method for the specific type the control handles. Since the popup_ctl returns an integer index, you'll need to use the .get_int() method to get the value and store it in a variable.

    And that's a simple UI in Lightwave's Python SDK.

    Now, onto the actual details...

    ----------
    Here is the complete one-shot format script of the above...

    Code:
    import lwsdk
    """
    A one-shot Lightwave UI Example
    27 June 2020, by Steven Pettit
    """
    #Your UI code starts here
    ui = lwsdk.LWPanels()
    panel = ui.create('Your Script\'s Name')
    #These are optional
    panel.setw(400)
    panel.seth(300)
    #Add a pop-up control
    my_control = panel.popup_ctl("Control Label",['Choice 1','Choice 2', 'Choice 3'])
    #This is optional
    my_control.move(5,5)
    
    """
    If you want Lightwave to handle the panel layout,
    comment out the optional sections above, and uncomment
    The section below.
    """
    """
    #Vertically Align Input areas
    panel.align_controls_vertical([my_control])
    #Resize panel to hold all the controls, plus margins
    panel.size_to_layout(5,5)
    """
    
    #Display the Panel, with Buttons
    if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0:
    	#The Cancel button has been pressed, Abort Execution...
    	ui.destroy(panel)
        my_value = 0
    	print("You pressed the Cancel Button")
    else:
        my_value = my_control.get_int() + 1
    	print("You chose choice ", my_value)
    (Yeah, I'm aware this isn't much of a plugin, but it does work as an example.)
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

Page 14 of 14 FirstFirst ... 4121314

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
  •