PDA

View Full Version : New Lightwave python blog



richhelvey
02-09-2014, 10:15 AM
In an effort to try to get more people scripting with python (and to have a place to collect what I've learned in one place for my own future reference), I've launched a new blog at justaddmilk.org (http://justaddmilk.org) dedicated to Lightwave and python. It's been up and cranking for a month now, and I'm trying to get something up every few days at the least. The goal is to present scripts of various sorts and run through them so everyone can see how and why I did things the way I did.

You can find cheat sheets (http://justaddmilk.org/?page_id=423) for making interfaces, bare-bones templates (http://justaddmilk.org/?page_id=180) for each type of python script available (well, only a few as of this writing, but more are coming), my own python libraries (http://justaddmilk.org/?page_id=371) to make scripting easier, and a bunch of scripts (http://justaddmilk.org/?page_id=301) you can use or abuse as you see fit.

Plus I'll be constantly writing about my own explorations through scripting and finding cool things you can do with it.

Things like this (http://justaddmilk.org/?attachment_id=324), this (http://justaddmilk.org/?attachment_id=349) or this (http://justaddmilk.org/?attachment_id=404).

Rich Helvey
justaddmilk.org

ernpchan
02-09-2014, 11:04 AM
This will be very helpful. Thank you for doing this!

50one
02-09-2014, 11:25 AM
Many thanks for doing this, bookmarked!

Areyos Alektor
02-09-2014, 12:22 PM
Well useful, thank you !

raw-m
02-09-2014, 02:40 PM
That's amazing, I had no idea you could do all those particle effects using Python!

BokadCastle
02-09-2014, 02:53 PM
Thanks, great!

richhelvey
02-09-2014, 03:47 PM
Forgot to mention that I'm taking requests. If there's a script you'd like to write, but are having trouble, let me know, and I'll do my best to help you out - with the caveat that it'll wind up on the blog at some point.

djwaterman
02-09-2014, 04:15 PM
I've often wondered how much Python has been embraced by the LW users in general, I'll look in on your blog every now and then to mystify myself, perhaps some of it will sink in over time.

sami
02-09-2014, 05:04 PM
Forgot to mention that I'm taking requests. If there's a script you'd like to write, but are having trouble, let me know, and I'll do my best to help you out - with the caveat that it'll wind up on the blog at some point.

Actually there is something - have you figured out the raster functions? i.e. do you know how to draw onto panels and/or controls (equivalent to LScript's ctlinfo()) ? I've been trying to figure it out (as well as the equivalent of @data's) and iain_r had uploaded a script here: http://forums.newtek.com/showthread.php?140001-How-to-draw-data-graphics-in-Lightwave-Python&p=1366673#post1366673
but we're currently not having any luck. Have you been able to do this?

EDIT: btw, Lscript's @data allows you to serialize a PNG, JPG, TGA or any such kind of file LW understands and we can draw that using the Glyph() function. As far as I can tell, Python only lets you draw RGBpixels, which means to draw a PNG graphic, you'd have to write your own PNG reader and translate that to get the pixel data to hand draw it. Is there a Python equivalent of LScript's Glyph() too which bypasses all this mess and just takes your graphic data as data and draws it?


thanks for the blog! :)

rcallicotte
02-09-2014, 05:56 PM
+1

richhelvey
02-10-2014, 08:23 AM
Actually there is something - have you figured out the raster functions? i.e. do you know how to draw onto panels and/or controls (equivalent to LScript's ctlinfo()) ? I've been trying to figure it out (as well as the equivalent of @data's) and iain_r had uploaded a script here: http://forums.newtek.com/showthread.php?140001-How-to-draw-data-graphics-in-Lightwave-Python&p=1366673#post1366673
but we're currently not having any luck. Have you been able to do this?

EDIT: btw, Lscript's @data allows you to serialize a PNG, JPG, TGA or any such kind of file LW understands and we can draw that using the Glyph() function. As far as I can tell, Python only lets you draw RGBpixels, which means to draw a PNG graphic, you'd have to write your own PNG reader and translate that to get the pixel data to hand draw it. Is there a Python equivalent of LScript's Glyph() too which bypasses all this mess and just takes your graphic data as data and draws it?


thanks for the blog! :)
Challenge accepted. First thought off the top of my head is to explore the Python Imaging Library which can load and save many different types of image data. I'm sure there's a way to have it give us something we can use in panels. I'll post back with my findings.

50one
02-10-2014, 08:27 AM
I would love to see simple script that would create a "network" of tubes between given point cloud, sort of like hanging tubes...:)

richhelvey
02-10-2014, 08:29 AM
OK, I'll add that to the list.

raw-m
02-10-2014, 08:54 AM
I would love to see simple script that would create a "network" of tubes between given point cloud, sort of like hanging tubes...:)

Great idea, with the addition of a weight map so we can animated them if needed!

50one
02-10-2014, 09:16 AM
Thanks! I was creating a illustration of spores and wanted to add something like cobwebs, but it was too time consuming, but it's quite easy to do in Cinema4D with their nodal expresso...

richhelvey
02-10-2014, 09:53 AM
Actually there is something - have you figured out the raster functions? i.e. do you know how to draw onto panels and/or controls (equivalent to LScript's ctlinfo()) ? I've been trying to figure it out (as well as the equivalent of @data's) and iain_r had uploaded a script here: http://forums.newtek.com/showthread.php?140001-How-to-draw-data-graphics-in-Lightwave-Python&p=1366673#post1366673
but we're currently not having any luck. Have you been able to do this?

EDIT: btw, Lscript's @data allows you to serialize a PNG, JPG, TGA or any such kind of file LW understands and we can draw that using the Glyph() function. As far as I can tell, Python only lets you draw RGBpixels, which means to draw a PNG graphic, you'd have to write your own PNG reader and translate that to get the pixel data to hand draw it. Is there a Python equivalent of LScript's Glyph() too which bypasses all this mess and just takes your graphic data as data and draws it?


thanks for the blog! :)

Here's (http://justaddmilk.org/?p=446) step 1, drawing something - ANYTHING - to a panel. I used the same data in the script you linked to. Hope that's all right. Now that we've got that working, it should be a simple matter to find a way to load in a jpg or png and convert it to this same format. Then finally, I'll look at blitting the whole image up at once like the linked script was trying to do, instead of drawing it pixel by pixel. Baby steps.

OnlineRender
02-10-2014, 10:45 AM
love the url ... & thanks

richhelvey
02-10-2014, 12:23 PM
Here's (http://justaddmilk.org/?p=446) step 1, drawing something - ANYTHING - to a panel. I used the same data in the script you linked to. Hope that's all right. Now that we've got that working, it should be a simple matter to find a way to load in a jpg or png and convert it to this same format. Then finally, I'll look at blitting the whole image up at once like the linked script was trying to do, instead of drawing it pixel by pixel. Baby steps.

Step2: (http://justaddmilk.org/?p=462) loading a png file to use as your source instead of hard-coding individual pixels into your script.

sami
02-10-2014, 05:15 PM
Step2: (http://justaddmilk.org/?p=462) loading a png file to use as your source instead of hard-coding individual pixels into your script.

This is awesome that you got it working! Thanks for taking the time to experiment! :thumbsup: However, do you think there is a way to get it working without using a the 3rdparty utils numby & pillow for loading images?

LScript seems to use the LW Importers in that I can serialize data from TGAs, PNGs, JPGs etc and it seems to work.

This is a Layout generic script I adapted off of Bob Hood's work to make LScript @datas for graphics:

120035

I like to include graphics as text embedded in the script so that all the graphics for the script are included within one single file and I don't have to worry about other graphic files not being present when running. Also, they get embedded when you compile an LScript.

(Btw side question: Can you compile a Lightwave Python script? I haven't tried that and didn't see a compiler button like for LScript...? )

Would you mind taking a quick look at this super short Modeler plugin that loads 2 pngs and basically makes a custom hover button out of them. It would be cool to do that in Python and hopefully without 3rd party libraries. I mean 3rd party librarys are awesome in Python - I started experimenting with using squirtle to read SVGs in Python, but some stuff like images should be native Lightwave like in LScript - but I guess if there is no other way to do thing until they enhance LW Python, then maybe that's all you can do?

Here's the Modeler LScript with the PNG loading - it also uses LScript's mouse functions in order to test for clickable regions - I still need to learn how to do that in LW Python too - would you consider that challenge as well? Or am I asking too much? :bowdown:

120034

thanks! :)

RebelHill
02-10-2014, 05:38 PM
Can you compile a Lightwave Python script? I haven't tried that and didn't see a compiler button like for LScript...?

You compile in python itself using the compile() function...

Its pointless for protection though, you can easily decompile pyc files with any number of tools, getting not just code, but comments, docstrings, everything.

sami
02-10-2014, 05:43 PM
You compile in python itself using the compile() function...

Its pointless for protection though, you can easily decompile pyc files with any number of tools, getting not just code, but comments, docstrings, everything.

So for protection/obfuscation LScript is still better? (not that I mind sharing - but occasionally protection is needed)

RebelHill
02-10-2014, 06:00 PM
Yeah, for protection pythons no use at all... LS or C it is.

You COULD potentially try putting certain bits or locks into an LSC or C file, and have python call those... but that's gonna be messier (and Im not entirely sure how workable it is). One thing Ill be experimenting with at some point is Cython, in the hope I can use one codebase, python, for doing a bit of cross dev for LW, maya, etc and spit out compiled C code... but again, how possible thats gonna be... dunno.

richhelvey
02-10-2014, 06:28 PM
This is awesome that you got it working! Thanks for taking the time to experiment! :thumbsup: However, do you think there is a way to get it working without using a the 3rdparty utils numby & pillow for loading images?
thanks! :)

I'm sure there's a way, but part of the power of python is the ability to use all this free code that's out there, much of which is quite sophisticated. And I believe, though I haven't tried it yet, that if you compile a python script, you can distribute the script to people without the library and they can use it just fine. Another thing I need to test.

GoatDude
02-10-2014, 08:09 PM
This is a great site. Thank you

Waves of light
02-11-2014, 04:08 AM
What a generous resource, bookmarked for future reference.

richhelvey
02-11-2014, 12:19 PM
Fractured Fun with Voronois!
120087
Step1 (http://justaddmilk.org/?p=484)
Step2 (http://justaddmilk.org/?p=494)

http://justaddmilk.org/wp-content/uploads/2014/02/voronoiCrevices2.mp4

Dodgy
02-11-2014, 09:54 PM
Good stuff Rich :)

raw-m
02-12-2014, 02:56 PM
I have a couple of scripts to throw in the bag!

1. A script that bakes instances. The current baking script is broken (http://forums.newtek.com/showthread.php?138818-Python-Bake-Instances-script-bug-Please-Fix!!) when selecting multiple items but a script that also bakes out any movement/animation on an instance would be very handy.

2. I've tried to get this to work (http://forums.newtek.com/showthread.php?138670-AE-Multiplane-in-LW-items-to-only-looks-correct-at-specific-angle) in LW but couldn't get it to translate correctly. Basically, it replicates an extremely useful AE script called PT Multiplane (http://aescripts.com/pt_multiplane/) - it allows you to move layers around but will automatically scale the item as it's moved along the z so it looks the same from the camera perspective (better explanation on the website). A Null to do the moving is created at the origin and the layer is parented to it. The code it puts to the scale channel in AE is:


camZoom = 1777.7778;
distance = position[2] + camZoom;
scale * (distance / camZoom);

camZoom is the comps Camera's Zoom setting. This example it says 1777.7 (39.6degs).

But as mentioned, I'm not clever enough to get it to work!

Just a though anyway. The line between what can be scripted and what could be nodal is slightly blurred for me so feel free to slap me down if not possible!

richhelvey
02-12-2014, 03:05 PM
I have a couple of scripts to throw in the bag!

1. A script that bakes instances. The current baking script is broken (http://forums.newtek.com/showthread.php?138818-Python-Bake-Instances-script-bug-Please-Fix!!) when selecting multiple items but a script that also bakes out any movement/animation on an instance would be very handy.

2. I've tried to get this to work (http://forums.newtek.com/showthread.php?138670-AE-Multiplane-in-LW-items-to-only-looks-correct-at-specific-angle) in LW but couldn't get it to translate correctly. Basically, it replicates an extremely useful AE script called PT Multiplane (http://aescripts.com/pt_multiplane/) - it allows you to move layers around but will automatically scale the item as it's moved along the z so it looks the same from the camera perspective (better explanation on the website). A Null to do the moving is created at the origin and the layer is parented to it. The code it puts to the scale channel in AE is:


camZoom = 1777.7778;
distance = position[2] + camZoom;
scale * (distance / camZoom);

camZoom is the comps Camera's Zoom setting. This example it says 1777.7 (39.6degs).

But as mentioned, I'm not clever enough to get it to work!

Just a though anyway. The line between what can be scripted and what could be nodal is slightly blurred for me so feel free to slap me down if not possible!

OK, I'll take a look. I'm working on building dynamically created objects in Layout right now, but I'll put these on the list. I think I should put up a request page, with a progress tracker, otherwise I'll forget what i said i'd try to do!

raw-m
02-13-2014, 06:25 AM
Cheers Rich. Dynamic created objects sounds very interesting, do that first :D

lertola2
02-13-2014, 07:08 PM
Forgot to mention that I'm taking requests. If there's a script you'd like to write, but are having trouble, let me know, and I'll do my best to help you out - with the caveat that it'll wind up on the blog at some point.

I don't know anything about python scripting but I have an idea for a script that I think could be very useful to the Lightwave community. I have thought about this off and on and there should be a way to do it but so far I have not figured out how. The idea is to be able to zoom in on a portion of the perspective camera's view. This would be something like what fprime could do. Fprime had the very useful ability to zoom in on a portion of your camera's view. This is very handy for looking at small parts of your scene.

The way I think the script interface should work would be to draw a limited region then invoke the script. The script would create a new shift camera parented to the current camera. The shift camera would have its parameters set to reproduce the view through the limited region. I have been playing around in excel trying to figure out the math of using the limited region information to create a shift camera that reproduces the limited region view. If I can figure out how to do that I might ask you if you think it is possible use python to collect the limited region parameters and also to create a the new shift camera.

-Joe

MarcusM
02-14-2014, 02:31 AM
Is there a possibility to make plugin for modeler something like tooltip. When cursor is on tool button it showing short description.
It can help new users get know tools and old users what forgotten tools.

Another idea is to make possibility to use shortcut what allow jumping between Modeler menu tabs.

Can someone do pop up UV window with texture and uv choosing next to each other? :)

I had python at the University but it was few year ago...;]

sami
02-15-2014, 09:22 PM
Is there a possibility to make plugin for modeler something like tooltip. When cursor is on tool button it showing short description.
It can help new users get know tools and old users what forgotten tools.

I dont believe this is possible in any type of plugin in Lightwave. The Lightwave interface is not exposed to the plugins in a way that would allow tooltips etc on existing LW buttons etc.





Another idea is to make possibility to use shortcut what allow jumping between Modeler menu tabs.

This is possible by writing having your LScript or Python plugin sending a virtual mouse-click to those tabs by launching a 3rd party script possibly written in AutoIt or AHK (like erikals' scripts). But it would be windows only, unless you launched an Applescript or whatever the Mac equivalent of AHK is.



Can someone do pop up UV window with texture and uv choosing next to each other? :)

I had python at the University but it was few year ago...;]
Not sure what you mean here? Are you talking about another OpenGL viewport in a popup window with a way to browse through UVmaps?

raw-m
06-19-2014, 03:19 AM
i have an idea for a script that shouldn't be too complicated and would save a lot of frustration in LW. I'm sure everyone would find it incredibly useful, too:

In AE it's called Rove Across Time. C4d has something similar, I want it! I've had to use Spline Control on numerous occasions, which is a bit over kill just to smooth a path out.

Possible?

RebelHill
06-19-2014, 07:09 AM
whats that then, Just an animation smoother? I posted a laplace filter plugin for someone in the nevron forum a while back... that'll do it.

raw-m
06-19-2014, 07:23 AM
Ough, missed that!

Basically, if I create a keyframe between two other keyframes and tell it to Rove Across Time, that keyframe will be automatically repositioned in the timeline so the motion is nice and smooth.

I'll go and take a look, would be great if this has been addressed by someone :D

raw-m
06-19-2014, 07:30 AM
whats that then, Just an animation smoother? I posted a laplace filter plugin for someone in the nevron forum a while back... that'll do it.

Got a link, RH? Could be anywhere!

spherical
06-19-2014, 07:53 AM
Well, using the forum search on laplace filter and RebelHill in the NevronMotion forum, it'd likely be this:
http://forums.newtek.com/showthread.php?136831-Non-destructive-mocap-filtering&highlight=laplace+filter+plugin
Then there's these for RH's other rigging/animation plugins:
http://forums.newtek.com/showthread.php?140004-Best-way-to-reduce-key-frames-from-motion-capture&highlight=laplace+filter
http://forums.newtek.com/showthread.php?140004-Best-way-to-reduce-key-frames-from-motion-capture&highlight=laplace+filter
http://forums.newtek.com/showthread.php?139397-Why-do-rotation-values-randomly-jump-positive-to-negative-after-baking&highlight=laplace+filter
http://forums.newtek.com/showthread.php?136831-Non-destructive-mocap-filtering&highlight=laplace+filter

RebelHill
06-19-2014, 07:55 AM
would be here...

http://forums.newtek.com/showthread.php?136831-Non-destructive-mocap-filtering&p=1336705&viewfull=1#post1336705

This however is a SPATIAL smoother (and now I actually bother to google AE rove time)... it appears to me you're after a TEMPORAL smoother. No can help there atm, but Ill add it to the list.

Cheers.

raw-m
06-19-2014, 07:55 AM
Oops, thanks, I thought laplace was an autocorrect spelling mistake thing!

RebelHill
06-19-2014, 07:59 AM
I thought laplace was an autocorrect spelling mistake thing!

Could be worse... I always mix up Laplace, and Lovelace, and my girlfriend does the exact same... anytime we get to discussing a topic involving one or the other it always takes about ten minutes and a couple visits to wikipedia before we can figure out what it is we're actually talking about... only for one of us to screw it up again a few minutes later. Oh the hilarity.

raw-m
06-19-2014, 08:02 AM
Interested to see what a Lovelace script would do!

RebelHill
06-19-2014, 08:10 AM
Considering she was the first person to ever undertake the approach we today broadly call "computing"... i suspect the answer would be... everything. (: