View Full Version : Script desperately needed! :)
jforrester 12-03-2007, 04:18 PM Hi Guys,
Just wondered if there were any clever people out their who is a dab hand at writing scripts. What I need is a script that finds objects that are always seen by the renderer or always seen by the editor. Basically it finds any object that has a little "green light on" which is hidden away somewhere in the sub folder of a sub folder of a sub folder, basically very time comsuming to find. This would be a great help to many others as well I guess. I would attempt to do this myself but have no experience in this field, zilch.
If anyone could help I would be emtremely greatful.
Many thanks in advance
|
|
Darter
12-04-2007, 11:36 AM
Here's a script which selects all scene objects with Editor/Renderer 'On' and unfolds the hierarchy down to the level of each selected object.
FindVisible(obj)
{
while(obj)
{
var editorMode = obj#ID_BASEOBJECT_VISIBILITY_EDITOR;
var rendererMode = obj#ID_BASEOBJECT_VISIBILITY_RENDER;
if(editorMode == 0 || rendererMode == 0)
{
obj->SetBit(BIT_AOBJ);
var parent = obj->GetUp();
while(parent)
{
parent->SetBit(BIT_OFOLD);
parent = parent->GetUp();
}
}
FindVisible(obj->GetDown());
obj = obj->GetNext();
}
}
main(doc,op)
{
var obj = doc->GetFirstObject();
FindVisible(obj);
}
jforrester
12-04-2007, 01:26 PM
Thank you very much, more appreciated. Just one thing though, it highlights the folder in which it is in, but doesn't unravel the hierarchy like it says in the description. But never the less still extremely handy> Many thanks again.
Darter
12-04-2007, 02:04 PM
Thanks for the feedback.
I created and tested this script in 9.6, where it works fine.
Disappointingly the SetBit(BIT_AOBJ) command, which is responsible for unfolding, doesn't seem to work with COFFEE in R10.5. This was unexpected but I'll be sure to check next time.
jforrester
12-04-2007, 02:07 PM
No probs, thanks anyway. Very handy command
c-montesano
12-04-2007, 04:51 PM
With R10 you have to use ChangeNBit to fold/unfold, but unfortunately that doesn't seem to be available with COFFEE.
rui_mac
12-04-2007, 04:59 PM
With R10 you have to use ChangeNBit to fold/unfold, but unfortunately that doesn't seem to be available with COFFEE.
But you have ToggleBit(BIT_LOCATION) that, I believe, serves the same purpose.
Rui Batista
JoelOtron
12-04-2007, 06:28 PM
This will be great!--thanks
I'll keep watching to see if that fold/unfold issue is revised (although, I DID buy rui's book so I "should" know how to fix it myself :)
Darter
12-05-2007, 09:29 AM
With R10 you have to use ChangeNBit to fold/unfold, but unfortunately that doesn't seem to be available with COFFEE.
Thanks for the information. I had a look but you're right, there doesn't seem to be anything viable in the C++ SDK.
But you have ToggleBit(BIT_LOCATION) that, I believe, serves the same purpose.
Thanks for the suggestion. Unfortunately I couldn't get this to work either.
Maybe it will be necessary to wait for Maxon to update the COFFEE SDK.
tcastudios
12-05-2007, 10:52 AM
This folds and unfolds down in hierarchy, but kicking the command up to top parent should do the trick.
Cheers
Lennart
if(!op) return;
var state;
state = op->GetBit(BIT_OFOLD);
if(state==1)
{
CallCommand(100004802); // unfold
op->DelBit(BIT_OFOLD);
op->Message(MSG_UPDATE);
return;
}
if(state==0)
{
CallCommand(100004803); // fold
op->SetBit(BIT_OFOLD);
op->Message(MSG_UPDATE);
}
jforrester
12-05-2007, 12:20 PM
Is it possible to put these two bits of code together to make the finished script as I dont have a clue what goes where. :)
Thanks for all your help guys, much appreciated.
Darter
12-05-2007, 01:37 PM
Thanks Lennart, you've pointed me in the righ direction with CallCommand(). I wasn't aware of the R10 Fold Selected command, which is necessary for this solution.
This seems to work okay, although it's not as elegant as the R9.6 script. There's a lot of selecting and deselecting going on. The result seems to be the same though.
EDIT: I've uploaded the script as well, as an alternative to the CODE tag-whacked formatting below.
UnfoldVisible(obj)
{
while(obj)
{
var editorMode = obj#ID_BASEOBJECT_VISIBILITY_EDITOR;
var rendererMode = obj#ID_BASEOBJECT_VISIBILITY_RENDER;
if(editorMode == 0 || rendererMode == 0)
{
var parent = obj->GetUp();
while(parent)
{
parent->SetBit(BIT_AOBJ);
CallCommand(100004802); //Unfold Selected
parent->DelBit(BIT_AOBJ);
parent = parent->GetUp();
}
obj->SetBit(BIT_AOBJ);
CallCommand(100004803); //Fold Selected
obj->DelBit(BIT_AOBJ);
}
UnfoldVisible(obj->GetDown());
obj = obj->GetNext();
}
}
SelectVisible(obj)
{
while(obj)
{
var editorMode = obj#ID_BASEOBJECT_VISIBILITY_EDITOR;
var rendererMode = obj#ID_BASEOBJECT_VISIBILITY_RENDER;
if(editorMode == 0 || rendererMode == 0)
{
obj->SetBit(BIT_AOBJ);
}
SelectVisible(obj->GetDown());
obj = obj->GetNext();
}
}
main(doc,op)
{
CallCommand(100004767); //Deselect All (Object Manager)
var obj = doc->GetFirstObject();
UnfoldVisible(obj);
SelectVisible(obj);
}
jforrester
12-05-2007, 01:51 PM
Hi Darter,
Thanks for your help. It now seems tounfold the null's within the hierarchy to locate the object, but now in unfolds every null, within that null, within that null etc, instead of just opening the null objects down the order. This would be o.k if there were very few null's but working with many null's, in null's this opens hundreds of objects to find just a single "green light" left on. Scroll to first active works in the same way needed, just unfolding the necessary nulls.
Seems so close. :)
Thanks again.
Darter
12-05-2007, 01:58 PM
Could you post an example scene so that I can see what the exact problem is?
Darter
12-05-2007, 02:15 PM
Never mind, I've got it. It's late and my brain has stopped working.
Darter
12-05-2007, 02:46 PM
This approach is really a hack due to the difference between Fold/Unfold Selected which is used here and SetBit() unfold, which works in R9.6. This is like clicking the +/- sign in the OM and only unfolds the immediate parents of the visible objects. It doesn't go marauding through other parts of the hierarchy like a drunken sailor.
Anyway, I'll have another think about this tomorrow.
Darter
12-06-2007, 10:22 AM
Okay, this seems to be working okay. With my test scene, the hierarchy unfolds just down to the level of the visble 'On' objects. Just be mindful that, unlike the R9.6 version, the script alters the folded state of all scene objects in the Object Manager.
Let me know if there are any more issues.
EDIT: Further testing identified unwanted folding at the parent level of 'On' objects in certain situations. This has been fixed in the updated file.
jforrester
12-06-2007, 03:00 PM
Hi Darter,
Thanks again for your continued help, very much appreciated. I've tried the new script in a small test scene and it worked great, here it comes...., but in a larger scene file with hundreds/thousands of objects it just spins out until I force quit it. Definatley something to do with the folding/unfolding as you say because the very first script you gave me locates the objects extremely quick, even in a large screen, after that I can use the Scroll to first active, the only thing is if there are 3/4/5 objects this has to be done everytime which is'nt the worst thing in the world, but just thought because of the scroll to first active that this could be incorperated into the script if thats possible.
Thanks again for your help.
Darter
12-06-2007, 07:47 PM
Thanks for the feedback. For what it's worth, here's a version of the script using your idea of Scroll to First Selected.
I've tested the scripts with a scene of 1000 objects, of which 500 have visibility set to 'On'. My machine is an Athlon 3200+.
The results are:
Current version: 54 seconds
Version 3: 1 min 26 seconds
Version 1 (R9.6 using SetBit(BIT_OFOLD): instantaneous upon mouse click.
A hack is a hack.
My COFFEE is going cold...
CGTalk Moderation
12-06-2007, 07:47 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.