Page 14 of 15 FirstFirst ... 412131415 LastLast
Results 196 to 210 of 217

Thread: Kryslin's lScripts

  1. #196
    Electron wrangler jwiede's Avatar
    Join Date
    Aug 2007
    Location
    San Jose, CA
    Posts
    7,229
    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,290
    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,653
    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,653

    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.

  5. #200
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    Ok, update time...!

    I'm through all but one of my released lscript curve tools in converting them to Python.

    The real sticking point will be, of course, the style combing script, followed by the FFX estimator script.

    After that, I'll work on my layout tools, which look to be another fresh level of purgatory...

    - - - Updated - - -

    Ok, update time...!

    I'm through all but one of my released lscript curve tools in converting them to Python.

    The real sticking point will be, of course, the style combing script, followed by the FFX estimator script.

    After that, I'll work on my layout tools, which look to be another fresh level of purgatory...
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  6. #201
    Eat your peas. Greenlaw's Avatar
    Join Date
    Jul 2003
    Location
    Los Angeles
    Posts
    7,290
    Thanks again for all your hard work, Kryslin! I'm looking forward to the update!

  7. #202
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    Things I have discovered about coding in Python:
    -You will discover new and horrific ways to crash Lightwave... at least 6 times before lunch on the first day.
    -You will discover new and creative ways to curse as you struggle with a number of issues in the python SDK.
    -You will spend a third of your time putting in and taking out print statements so you can tell where you plugin is crashing.
    -You will spend another third of your time looking for ways to code things.
    -You will spend time that you're not coding digging out the hidden secrets of the Python SDK. And there is a lot of them.
    -And when you finally get a project converted to Python, you'll have a very good night's sleep, until you start on the next project.

    I'm currently working on the last two modeling tools - Style Combing, and SubD corners.
    Style combing has got everything up to a working UI, but no actual combing.
    SubD corners will be easy in comparison.

    Then comes the layout scripts... Symm. Bone Weight Assignment and Build Null Object.
    Ah, I love the smell of fresh new levels of hell...

    - - - Updated - - -

    Things I have discovered about coding in Python:
    -You will discover new and horrific ways to crash Lightwave... at least 6 times before lunch on the first day.
    -You will discover new and creative ways to curse as you struggle with a number of issues in the python SDK.
    -You will spend a third of your time putting in and taking out print statements so you can tell where you plugin is crashing.
    -You will spend another third of your time looking for ways to code things.
    -You will spend time that you're not coding digging out the hidden secrets of the Python SDK. And there is a lot of them.
    -And when you finally get a project converted to Python, you'll have a very good night's sleep, until you start on the next project.

    I'm currently working on the last two modeling tools - Style Combing, and SubD corners.
    Style combing has got everything up to a working UI, but no actual combing.
    SubD corners will be easy in comparison.

    Then comes the layout scripts... Symm. Bone Weight Assignment and Build Null Object.
    Ah, I love the smell of fresh new levels of hell...
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  8. #203
    Registered User fuzzytop's Avatar
    Join Date
    Feb 2012
    Location
    Glocca Morra
    Posts
    30

    Thanks for persevering

    I just kicked in $10… not much but … hope it helps!
    Lightwave 2015 2019 2020 (both Mac & Win)
    High Sierra & Windows 10
    Mac Pro 2012 & Alienware Aurora
    48 GB ram
    AMD RX580 (Mac) & NVIDIA RTX2080 Ti (Win)

  9. #204
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    Every little bit does, thank you.

    Update on updates...
    I now have a version of style comb that doesn't crash modeler straight to desktop (and doesn't crash under normal usage), and actually does something vaguely resembling the original! That's an improvement over where I was Last time, since I was crashing straight to the desktop. a lot of print statements, carefully inserted return lwsdk.AFUNC_OK's, and break statements. and I got something working. Now. it's a matter of refining the algorithm so that I get the same results (or nearly the same) as the Lscript...

    You get spoiled working in lscript, since there is far more consistency in what gets returned by functions. You can do far more with python, but things get convoluted fast.
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  10. #205
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    Style Comb for Python has passed the unit test phase, and has passed the tests on my test article shapes.

    I'll be digging up the melody mesh and seeing what results come out.

    This has the following features:
    - Fiber length, fiber curling, and sleekness are all controllable by weight maps
    - You can use parts and surfaces for what gets combed, plus you can use a point selection for what to comb away from as well.
    - It's much faster than the LScript version. On my test article object, about 3x faster.
    - It shouldn't be too hard to convert over to Python 3 when required, as it was written with that in mind.

    Frustrations encountered:
    -Indentations. One misplaced indentation, +/-, and you can not only crash llightwave, you can crash Windows.
    -Included modules for making the transition from LScript to Python easier... don't.
    -Lack of documentation : the lwsdk.Vector class, the lwsdk.EDPoint/Edge/PolygonInfo classes, the lwsdk.Panels/Panel/Control classes are ALL undocumented in the Python SDK. They are all kinda necessary to writing modeler plugins.

    End result:
    I'm not looking forward to doing my Build Null Object and Symmetric Weight Assigner scripts.
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  11. #206
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    There will be an update rolling out on Saturday; I have all my released modeler scripts converted to Python. ~yay!~

    Now, I'm learning (the hard way) about modal panels in layout. Symm. Weight Assignment is coming along nicely; The UI is done, the correct callbacks get called, and I've found out just how useful the user_data block on the panel can be - you can use it to store data you need to pass between callbacks. Also, for some reason, you lose instance variables on panels opened with the lwsdk.PANF_NOBUTT flag; essentially the script executes and completes, leaving the panel open. Everything has to be doen via callbacks, and anything you need to do when you close the panel has to be handled in the close callback. However, loss of globals and instance variables makes it kind of hard to do things like use recall and store for parameters...
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  12. #207

    There will be an update rolling out on Saturday; I have all my released modeler scripts converted to Python. ~yay!~
    impressive!
    LW vidz   DPont donate   LW Facebook   IKBooster   My vidz

  13. #208
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    Quote Originally Posted by erikals View Post
    impressive!
    My source code will probably be used as a warning to future generations, too.
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  14. #209
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    The website has been updated. I'll get the entire collection zipped up when the last two scripts for layout are converted.

    Build Null Objects will be a monster, because of the com ring. Symmetric Weight Assignment is being difficult in the UI department, while the code to handle everything is relatively simple.
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  15. #210
    Registered User fuzzytop's Avatar
    Join Date
    Feb 2012
    Location
    Glocca Morra
    Posts
    30
    Looking forward to When everything’s complete … I hope to have a project to use your new scripts on later this Fall.

    Right now grinding away on VFX … non-CG stuff…
    Lightwave 2015 2019 2020 (both Mac & Win)
    High Sierra & Windows 10
    Mac Pro 2012 & Alienware Aurora
    48 GB ram
    AMD RX580 (Mac) & NVIDIA RTX2080 Ti (Win)

Page 14 of 15 FirstFirst ... 412131415 LastLast

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
  •