View Full Version : LScript Q: Adding Plugins to Object Properties.
I was watching the videos released from Newtek about LScript. The macro functions that can be create w/ the LScript commander are really powerful and easy, but here's the rub:
I'm using the LScript Commander to create a button to perform a macro operation and one of the things that is not recorded in the command list, namely: adding say a "speedometer" plugin to the geometry tab of a null's properties. Every thing else works great. So, how do I get around this speed bump; how can one tell lightwave to add a plugin to an object's geometry properties via LScript?
Kind regards,
Micah
ArtHowe
11-22-2004, 01:37 PM
Unfortunately actions such as applying plugins to items in the scene is beyond the LScript Commander's abilities. You would basically need to create a script that simply applies a plugin to the currently selected item. The example below is simple and adds an item motion plugin to a single object. You could modify it to support multiple selections by creating an object agent for the scene and then iterating through the selections with a for loop and calling the same command:
// addFollower.ls
@version 2.7
@script generic
@warnings
@name Add Follower //<--- Replace with whatever plugin you would like.
generic
{
ApplyServer("ItemMotionHandler","LW_Follower"); //<--- Apply the plugin by specifying the type and servername as listed in the config file.
}
You could add this as a plugin and then assign it to a button.
Art
CB_3D
02-08-2005, 01:55 AM
One way to this this would be to let Lscript create a scene with a with the objects name that has the plugin applied. Lscript can the parse the scene file and eliminate the null,this leaviving only the settings information.When executing a LoadFromScene only the plugin and settings are loaded right onto your object.
That way you can also add Follower and any other plugin via LS.
GregMalick
02-09-2005, 05:27 PM
CB_3D,
That's a very interesting method. Much better than rewriting the plugin (as I unfortunately did).
Oh well, it was indeed fun while the fun lasted. :rolleyes:
faulknermano
02-11-2005, 06:11 AM
One way to this this would be to let Lscript create a scene with a with the objects name that has the plugin applied. Lscript can the parse the scene file and eliminate the null,this leaviving only the settings information.When executing a LoadFromScene only the plugin and settings are loaded right onto your object.
That way you can also add Follower and any other plugin via LS.
how does this work? meaning how does the LoadFromScene() know which item in layout it should apply the settings to?
CB_3D
02-11-2005, 08:11 AM
Unfortunatelly right now i am not scripting but i did this once (actually inspired by some stuff you helped me with via email,faulknermano;-)
Please forgive me for not providing an example script, i myself couldnīt script this right now as i simply donīt remember how to and i have no idea where my scripts from 2 years ago are ;-)
Before the steps i described above you execute a Getname (i think that was the command) of the selected object. When parsing the prepared scenefile the script temporarilly creates you substitute the generic name in the scene with the name you got from the Getname command.
Then, the script eliminates the line referring to the object itself in the scene txt file. It deletes the whole line, leaving all the other settings. If you you would load the scene into a clean layout it would create a null with the objectīs name, but since an object with the very same name already exists all the remaining scene info is loaded right into the existing scene and onto the present object.
Edit!!
Ahh,ok,after playing around a bit i see i forgot to mention one important thing. The scene file is created in a temmporary directory where the object is not present. While executing the LoadFromScene the script sets the content directory to this temp directory. That way you donīt have to eliminate the reference of the objectname in the scenefile.
Itīs a simple but very effective workaround.
CB_3D
02-11-2005, 08:41 AM
Yikes,i swear i got this to work 2 years ago,but right now i am unable to replicate this myself. Iīll have to dig out my backups sometime.
CB_3D
02-11-2005, 08:51 AM
Ok,thatīs how i would do it now (i think).
You actually REPLACE the whole scene. First you write the scene to disc (to the same content directory you are currently in).
Then you parse the scene file and add the block of text referring to the plugin at the apropriate place.
For example
_______________________________________
Plugin ItemMotionHandler 1 LW_Follower
"536870912 1"
"Channels 511 0 1 2 3 4 5 6 7 8"
"TimeSlip 0.0000 Randomize 0.0000 PathSlip 0.0000 1"
"Scale 1.0000 Add 0.0000"
"Scale 1.0000 Add 0.0000"
"Scale 1.0000 Add 0.0000"
"Scale 1.0000 Add 0.0000"
"Scale 1.0000 Add 0.0000"
"Scale 1.0000 Add 0.0000"
"Scale 1.0000 Add 0.0000"
"Scale 1.0000 Add 0.0000"
"Scale 1.0000 Add 0.0000"
EndPlugin
________________________________________
After that one ClearScene and the a LoadScene.
****,if only i could find the old scripts.. I used this in production to quickly add follower and various other preconfigured plugins to selected objects at the push of one button.
CB_3D
02-11-2005, 09:09 AM
Alright,i did find the textfile of Faulknermanoīs explanation that lead me to the result i unfortunatelly lost. Since this was here on the forums at the time i think you wonīt bother if i repost it here. After all what i did in the end was a search and replace, basically rewriting the whole scene as text and then reloading it with the new settings and plugins in place.
__________________________________________________ ________________
Parsing a scenefile and substituting a line?
--------------------------------------------------------------------------------
NewTek Forum: LightWave 3DŪ: LScript: Parsing a scenefile and substituting a line?
--------------------------------------------------------------------------------
By Chris Burkert (Cb_3d) (212.113.164.97) on Friday, January 10, 2003 - 04:35 pm:
And then i want to rewrite the scenefile.
As far as i know it can be done, but how? As always, an example script would be great.
Thanks a lot
Chris
By Lernie D Ang (Faulknermano) (210.14.13.229) on Friday, January 10, 2003 - 11:46 pm:
something like
...
a = string("c:/readFile.lws");
b = string("c:/writeFile.lws");
rf = File(a,"r+");
wf = File(b,"w+");
while(!rf.eof())
{
line = rf.read();
if(line == "search string")
wf.writeln("replace with this");
else
wf.writeln(line);
}
rf.close();
wf.close();
By Chris Burkert (Cb_3d) (212.113.164.97) on Saturday, January 11, 2003 - 06:45 am:
Cool Lernie, thank you :-)
I just have a problem with the "c:/readFile.lws".
I am not at home now, so i canīt try it, but i suppose that i could bypass this with
Conttemp1 = getdir("Content");
Ahh, i think itīll work
Chris
By Chris Burkert (Cb_3d) (212.113.164.97) on Saturday, January 11, 2003 - 06:51 am:
....to be compatible with mr mac...or content directories that are not on c.
By Chris Burkert (Cb_3d) (212.113.164.97) on Saturday, January 11, 2003 - 06:57 am:
oh yes, one more to make it complete.
what if i want to replace a known word, thatīs in this file a few hundred times?Like "Replace All" in UltraEdit or Word?
By Chris Burkert (Cb_3d) (212.113.164.97) on Saturday, January 11, 2003 - 07:01 am:
I suppose iīd have to let the script count the word/line occurencies and then multiply the replace action with the result, right?
By Lernie D Ang (Faulknermano) (210.14.21.144) on Saturday, January 11, 2003 - 08:09 am:
you can use the search-and-replace expressions.
i have a short function that will do simple search-and-replace
searchAndReplace: oName, search, replace
{
exp = regexp(search,replace);
oName ~= exp;
return(oName);
}
to use, feed the string you want to process as "oName". "search" is the variable containing
the string you want to replace. "replace" is the variable that will subsitute the "search" variable
in the "oName" string.
are we cool?
By Chris Burkert (Cb_3d) (212.113.164.97) on Saturday, January 11, 2003 - 08:46 am:
Yes, very cool, man!!!!!!!!
Thanx, thatīs exactly what i needed!
__________________________________________________ _______________
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.