View Full Version : Float Script Controller - Unique Object ID
JimJamGraphics 08-22-2009, 06:45 PM Hi all. I'm pretty new to this so please bear with me.
I'm trying to find the unique ID number of an object from a Float Script Controller. I guess it's the equivalent of thisLayer.index in After Effects expressions.
I have tried...
$.inode.handle
...but this is obviously referring to the current selected object as opposed to the object that has the Float Script Controller.
Is there anyway to do this?
Thanks,
Jamie
|
|
I think the only good way is to use custom attributes on the script controller. Since inode.handle doesn't survive a merge it's not a unique number you can refer to.
With a CA on the scriptcontroller you can easily access unique data from a generic script, using "this" to grab a value from the unique CA.
Maybe "appdata" is useful too, look it up in the help file.
-Johan
JimJamGraphics
08-23-2009, 11:29 AM
Hi Johan
Thanks for the reply.
I'm sorry for my lack of knowledge on this (I'm new to scripting and using script controllers).
With a CA on the scriptcontroller you can easily access unique data from a generic script, using "this" to grab a value from the unique CA.
Can you please explain how I can use a CA to obtain a unique number?
Any help is massively appreciated.
Jamie
Hi Jamie,
See if this works out for you
(
-- Collect some objects
theObjects = for i = 1 to 10 collect (box width:9 height:9 length:9 pos:[i*10-10,0,0] wirecolor:orange)
-- Create a script controller & script
sc = position_script()
script = "[this.UniqueIdentifiers.xOffset,this.UniqueIdentifiers.id * CurrentTime.frame,0]" -- Multiply ID times currenttime for y pos.
-- Create a Custom Attribute
ca = attributes UniqueIdentifiers
(
parameters main
(
id type:#integer default:0
xOffset type:#float default:0
)
)
-- Put it all together
startID = 1
for o in theObjects do
(
-- store old pos
oldPos = o.pos
-- create a copy of the script controller
o.pos.controller = copy sc
-- Assign Custom Attribute Definition to the scriptcontroller
custAttributes.add o.pos.controller ca #unique
-- Set the Unique ID
o.pos.controller.UniqueIdentifiers.id = startID
-- Set the x offset from the old position
o.pos.controller.UniqueIdentifiers.xOffset = oldPos.x
-- Assign the script
o.pos.controller.script = script
-- Increment the ID
startID += 1
)
)
Hope it's something you can use!
-Johan
denisT
08-23-2009, 06:58 PM
Hi all. I'm pretty new to this so please bear with me.
I'm trying to find the unique ID number of an object from a Float Script Controller. I guess it's the equivalent of thisLayer.index in After Effects expressions.
I have tried...
$.inode.handle
...but this is obviously referring to the current selected object as opposed to the object that has the Float Script Controller.
Is there anyway to do this?
Thanks,
Jamie
HOW TO get the node(s) that has the script controller (Sample):
(
try (delete $SampleBox) catch()
sb = box name:"SampleBox" length:20 width:20 height:20
sb.pos.track = position_XYZ()
-- inside the script controller script
ss = "node = refs.dependentNodes this firstOnly:on\n"
ss += "format \"inside - name:% handle:%\\n\" node.name node.inode.handle\n"
ss += "t*0.01\n"
sb.pos.track[3].controller = float_script()
sb.pos.track[3].controller.script = ss
-- outside the script
node = refs.dependentNodes sb.pos.track[3].controller firstOnly:on
format "outside - name:% handle:%\n" node.name node.inode.handle
)
is that you want?
The problem is what is a unique ID, handle has it's weaknesses. I'd rather go for a generated ID.
-Johan
denisT
08-23-2009, 08:43 PM
The problem is what is a unique ID, handle has it's weaknesses. I'd rather go for a generated ID.
-Johan
inode handle is unique for all nodes in the scene. What's the problem?
JimJamGraphics
08-23-2009, 09:21 PM
Hi all.
Thanks for all the answers, although I'm afraid to say that they've gone a bit over my head.
Perhaps I'm just trying to do something that is impossible or massively too complicated for what I need.
I'll try and give a simple example of what I'm trying to achieve in case there is a much easier/different solution.
Say I have a box.
I assign a Float Script Controller to it Z-Rotation.
I want the Float Script Controller to randomly choose a number between two parameters. To do this I seed with a unique number.
I can then clone the box object lots of times and each clone will have a randomly generated Z-Rotation.
I hope this makes sense?
Once again thanks for your time,
Jamie
denisT
08-23-2009, 09:33 PM
Hi all.
Thanks for all the answers, although I'm afraid to say that they've gone a bit over my head.
Perhaps I'm just trying to do something that is impossible or massively too complicated for what I need.
I'll try and give a simple example of what I'm trying to achieve in case there is a much easier/different solution.
Say I have a box.
I assign a Float Script Controller to it Z-Rotation.
I want the Float Script Controller to randomly choose a number between two parameters. To do this I seed with a unique number.
I can then clone the box object lots of times and each clone will have a randomly generated Z-Rotation.
I hope this makes sense?
Once again thanks for your time,
Jamie
it's very easy:
(
sb = box name:(uniqueName "ZRotBox") length:20 width:20 height:20
sb.rotation.track = euler_xyz()
ss = "node = refs.dependentNodes this firstOnly:on\n"
ss += "seed node.inode.handle\n"
ss += "speed = random -1.0 1.0\n"
ss += "t*speed\n"
sb.rotation.track[3].controller = float_script()
sb.rotation.track[3].controller.script = ss
)
it uses node's handle to seed random...
JimJamGraphics
08-23-2009, 10:48 PM
Brilliant, I've managed to get it working from that last post.
Thanks loads denisT!
inode handle is unique for all nodes in the scene. What's the problem?
Merge that file in a new file. The handle changes... so a CA or appdata seems a bit more robust. Maybe if we could assign a genClassID()...
I'm not using handles, because we do merge a lot in our scenes, no way to know when it's going to break.
-Johan
CGTalk Moderation
08-24-2009, 07:25 AM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.