PDA

View Full Version : Scripting using separate Class files?


Scott Ayers
04-05-2010, 10:02 PM
I think I already know the answer to this is no. But I figured I'd check with you guys and make sure.
If I create a custom class file. Can that file be called to from the script manager, Coffee tag, or a Coffee node?

So far the only ways I've seen this done is with either C++, or Coffee generated plug-ins.
I know you can put custom classes in the prepass section of a coffee script.
But I'd rather create my own separate class files. Then call to them from a script.

Is this possible?
Or is the plug-in structure the only way to call out to separate custom class files?

-ScottA

Per-Anders
04-05-2010, 11:54 PM
Use the inlcude function.

indeep
04-05-2010, 11:54 PM
Very Interesting question :)

Scott Ayers
04-06-2010, 12:51 AM
Use the inlcude function.

Do you have an example of this?
I don't know what's required for the include line in the script. And what's required in the constructor section of the class file.

Here's my code if that helps: include "c:\PSRClass.CSC"

main(doc,op)
{
var obj = doc->GetActiveObject();
var pos = vector(0,0,0);
var rot = vector(Radians(0),Radians(0),Radians(0));
var scale = vector(1,1,1);

SetGlobalPosition(obj, pos);
SetGlobalRotation(obj, rot);
SetGlobalScale(obj, scale);
}

And the class file named "PSRClass.csc" located in the C:\ directory: GetGlobalPosition(obj)
{
return obj->GetMg()->GetV0();
}

SetGlobalPosition(obj, pos)
{
var m = obj->GetMg();
m->SetV0(pos);
obj->SetMg(m);
}

GetGlobalRotation(obj)
{
return obj->GetMg()->GetHPB();
}

SetGlobalRotation(obj, rot)
{
var m = obj->GetMg();
var pos = m->GetV0();
var scale = vector(vlen(m->GetV1()),
vlen(m->GetV2()),
vlen(m->GetV3()));

m->SetRotHPB(rot);

m->SetV0(pos);
m->SetV1(vnorm(m->GetV1()) * scale.x);
m->SetV2(vnorm(m->GetV2()) * scale.y);
m->SetV3(vnorm(m->GetV3()) * scale.z);

obj->SetMg(m);
}

GetGlobalScale(obj)
{
var m = obj->GetMg();
return vector(vlen(m->GetV1()),
vlen(m->GetV2()),
vlen(m->GetV3()));
}

SetGlobalScale(obj, scale)
{
var m = obj->GetMg();

m->SetV1(vnorm(m->GetV1()) * scale.x);
m->SetV2(vnorm(m->GetV2()) * scale.y);
m->SetV3(vnorm(m->GetV3()) * scale.z);

obj->SetMg(m);
}

-ScottA

tcastudios
04-06-2010, 03:28 PM
The file with the functions should be at the same level as the plugin file.

To use such a file "globally" put it in the Resource/modules/coffee folder
(like the convenient.cof file in there)

Or make use of symbolic links.

More details about this at plugin cafe:

http://www.plugincafe.com/forum/forum_posts.asp?TID=4114&KW=include

Cheers
Lennart

Scott Ayers
04-06-2010, 04:13 PM
Thanks Lennart,

Everything you've presented here is centered around coffee created Plug-Ins. Right?
But I was asking if this is possible to do from the Script Manager, Coffee tags, and Coffee Nodes.
I'd like to be able to call out to class files from these sources without needing to write it as a plug-in.

I tried putting my class file into that coffee folder. And used include "../PSRClass.h" in my main script to call to it. But it still gives me an include error.
Are you sure this kind of thing is possible to do without being a plug-in?

-ScottA

tcastudios
04-06-2010, 07:13 PM
Please read that thread again, it is explained that/how it works
globally, scripts coffe nodes etc.
See no reason to repeat it all here again.

The include filename is -not- a path, it's the actual name of the
file. Check the Convenient.cof file in the resource how it is formatted.

Cheers
Lennart

Scott Ayers
04-06-2010, 07:50 PM
Oh wow!
I missed (actually, I really just didn't understand it properly) the part where you said that the functions become available system wide once they're in that folder.

After reading that again a few times. It suddenly registered that what you meant by that was my custom functions are already available. So there's no need to use an include in my scripts. And I can just use them. So I tried it and it works. Cool!

Sorry that I didn't get it the first time.
I'm still fairly new at this stuff. And sometimes I need the house to actually fall on me before I get it.:blush:

Thanks for the help.
-ScottA

CGTalk Moderation
04-06-2010, 07:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.