Basic Scripting Tutorial Available in this Thread

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

Basic Scripting Tutorial Available in this Thread // Roundtable

1  2  |  

Post by frootee // Aug 14, 2007, 11:29am

frootee
Total Posts: 2667
pic
Well I wanted to do 2 levels of sds actually....I only see one inside a given object when applied....I am still new to this...I have some experience with programming, but this seems foreign to me somehow...I don't know all the keywords and what they do(in laymens terms)????


Well, in your developer guide, in the ScriptObjects directory, you want the structIRiMeshModifiers.html

file. Load that.


I belive you are interested in the: ChangeSSLevel command:

---------------------


HRESULT IRiMeshModifiers::ChangeSSLevel ( [in] int iDiff )



Change subdivision surface level



Parameters:

bszSelection Specify node or '' for current selection.


Returns:

standard HRESULT processing can be applied to returned value

--------------------


so you can either specify the scene node (your object you want to subdivide), or just use two single quotes: '' in order to use the current selection.


Then, in your script, you do something like this: (currently untested, I'm doing this off the top of my head):


// for testing, first select your object to be SS'd


Name1_ = Node.Selection(); // per Dele example


// now the object you selected has a 2nd name: Name1_


// Now SS it!


level = 2; // this is the level of SS you want to set


MeshModifiers.ChangeSSLevel(level);


-------


Something along those lines; be sure to look at the tutorials from Dele, Stan, etc. here on the forums for sample code.


Froo

Post by Délé // Aug 14, 2007, 11:46am

Délé
Total Posts: 1374
pic
Here's what I would do:


//Select the object (in this example we select "cube")

Node.Select(Space.CurrentScene() + "/Cube")


// Apply 2 levels of SDS to selected mesh

ScriptObject.RunCmd("mesh modifiers package/add subdivision level", "Selection", "", "Strength", 2)


If you wanted to remove 2 SDS layers you could do it like this:


//Make sure the object is selected

Node.Select(Space.CurrentScene() + "/Cube")


//Change the 2 at the end to -2 to remove 2 layers

ScriptObject.RunCmd("mesh modifiers package/add subdivision level", "Selection", "", "Strength", -2)

Post by frootee // Aug 14, 2007, 12:01pm

frootee
Total Posts: 2667
pic
Here's what I would do:


//Select the object (in this example we select "cube")

Node.Select(Space.CurrentScene() + "/Cube")


// Apply 2 levels of SDS to selected mesh

ScriptObject.RunCmd("mesh modifiers package/add subdivision level", "Selection", "", "Strength", 2)


If you wanted to remove 2 SDS layers you could do it like this:


//Make sure the object is selected

Node.Select(Space.CurrentScene() + "/Cube")


//Change the 2 at the end to -2 to remove 2 layers

ScriptObject.RunCmd("mesh modifiers package/add subdivision level", "Selection", "", "Strength", -2)


Okay, I have a question here dele. I cannot find any information in the documentation about the stuff you have in quotes, like "mesh modifiers package/add subdivision".


Also, I do not find information about RunCmd.

What is your approach to finding information about these commands and script items that you need?


Thanks,

Froo

Post by nowherebrain // Aug 14, 2007, 12:41pm

nowherebrain
Total Posts: 1062
pic
Probably looking at other scripts, that is how I usually get around...but I've not so much time these days.

Post by nowherebrain // Aug 14, 2007, 12:42pm

nowherebrain
Total Posts: 1062
pic
BTW: Thanks guys...I need a lot of work here!!!

Post by trueBlue // Aug 14, 2007, 1:22pm

trueBlue
Total Posts: 1761
pic
The jScript Macro recorder is your friend. :)
I have my object selected and then record adding 2 levels of SDS. The first function is for any selected object. Next function adds one level of SDS twice.
Doing it this way you could apply SDS to any selected object.
Just another way FYI.

// Macro captured 08/14/07 16:12:40
function Execute(params)
{
sel = Node.Selection();
for (i = 0; i < Node.SelectionLength(sel); i++)
{Node.Select(Node.SelectionGetAt(sel, i)); ApplyMacro(Node.SelectionGetAt(sel, i))};
}
function ApplyMacro(selectedObj_)
{
ScriptObject.RunCmd("mesh modifiers package/add subdivision level",
"Selection", "", "Strength", 1)
ScriptObject.RunCmd("mesh modifiers package/add subdivision level",
"Selection", "", "Strength", 1)
}

Post by Délé // Aug 14, 2007, 1:46pm

Délé
Total Posts: 1374
pic
Yup, trueBlue has got it. :) I use the Jscript macro recorder very often to figure out how to access stuff. Sometimes it works, sometimes not. But a lot of what I've been able to figure out has been from that.


I do also dig around in other peoples scripts too. Especially the ones the devs make. But most of what I learn is from the Jscript macro.

Post by nowherebrain // Aug 14, 2007, 3:19pm

nowherebrain
Total Posts: 1062
pic
I will start to look into the macro recording...

Post by 3dvisuals dude // Aug 17, 2007, 2:36am

3dvisuals dude
Total Posts: 1703
pic
Hi Folks. I have assembled a very basic introductory tutorial to scripting and the LE. It takes you step by step through the script creation process. It is in powerpoint format, and I have included a free powerpoint viewer from Microsoft.

Please let me know what you think. I feel this will help others get their feet wet and build confidence in their LE and scripting skills.

Enjoy! If you like it more's coming!

Froo

WOW 58 VIEWS ALREADY ON THIS TUTORIAL!!!

See how much we all realize we need LE and Scripting Tutorials which are free?

Awesome... this upcoming "Script Hookup" Meeting on Tuesdays will be GREAT!!!!

Thanks a million for all this Frootee!

- 3dvisuals dude

Post by trueBlue // Aug 29, 2007, 7:51pm

trueBlue
Total Posts: 1761
pic
Okay, I have a question here dele. I cannot find any information in the documentation about the stuff you have in quotes, like "mesh modifiers package/add subdivision".
Also, I do not find information about RunCmd.
What is your approach to finding information about these commands and script items that you need?
Thanks,
Froo
Besides using the jScript Macro Recorder as a helper in scripting, I also wanted to point out something else. The Buttons in the Library Browser have most of the icons that are in the toolbars. Insert a button into the Link Editor and look at the commands in the Command and RClickCommand. You will see the differences in the way the Macro records and the real tS7 commands. Most likely why you could not find it in the DG. Lets use the Add SS as an examlpe.

The jScript Macro Recorder records this with a selected object:

function Execute(params)
{
sel = Node.Selection();
for (i = 0; i < Node.SelectionLength(sel); i++)
{Node.Select(Node.SelectionGetAt(sel, i)); ApplyMacro(Node.SelectionGetAt(sel, i))};
}
function ApplyMacro(selectedObj_)
{
ScriptObject.RunCmd("mesh modifiers package/add subdivision level",
"Selection", "", "Strength", 1)
}

8182

And the command in it's button is this:
MeshModifiers.ChangeSSLevel(1)

Note: Sometimes you do not want to have anything selected before recording a jScript Macro for there is different ways to use this tool as well.
Experiment with both ways and see the difference.

Post by frootee // Aug 30, 2007, 2:25am

frootee
Total Posts: 2667
pic
Hi trueblue. Nice! Thanks! I played around with the macro recorder just now and followed your instructions. I do see the difference.


Maybe we should plan to talk about the macro recorder at the next meeting?

Since it is such a very useful tool that may be underutilized?

Post by frootee // Mar 6, 2008, 12:48pm

frootee
Total Posts: 2667
pic
Just thought I'd revive this thread.


Prodigy, This One's For You! :banana::banana::banana:


At this past Tuesday's scriptor meeting Prodigy asked if there was a basic scripting tutorial.


This is actually more of an introduction to the Link Editor (LE) but it shows how to get setup for scripting.


BTW if you are interested in writing your own scripts to enhance your truespace experience we hold a scriptor meeting every Tuesday. I usually make an announcement on Mondays as a reminder.


Later!


Jason / Froo

Post by jamesmc // Mar 6, 2008, 1:12pm

jamesmc
Total Posts: 2566
Hi trueblue. Nice! Thanks! I played around with the macro recorder just now and followed your instructions. I do see the difference.

Maybe we should plan to talk about the macro recorder at the next meeting?
Since it is such a very useful tool that may be underutilized?

Yes,

This should be made into a video course on how to integrate macro recordings into scripts that you want to perform certain functions and how to integrate them into the LE.

Limiting the user base in scripting to those with programming experience is a good thing, but tends to alienate the broader user base.

Post by frootee // Mar 6, 2008, 2:00pm

frootee
Total Posts: 2667
pic
hey james. Norm made a few scripting courses way back when; I am not sure if the macro recorder is included in the videos though.

Post by jamesmc // Mar 6, 2008, 2:08pm

jamesmc
Total Posts: 2566
I think I have all the scripting courses, don't recall the macro recorder being covered in any depth. At least how to apply the results to any meaningful way.

Post by frootee // May 1, 2008, 4:25am

frootee
Total Posts: 2667
pic
Just want to bump this thread for the new users and new forum members, in case you want to get into scripting and the Link Editor (LE) for truespace. :)


Enjoy!


Froo
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2021. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn