PDA

View Full Version : Select next/prev


Schnupps
02-14-2011, 02:47 PM
Iīm totally new to scripting and I promise to do tutorials and get the basics done ;-)
But right now Iīm looking for a little script to select the next or previous object.
Just like using the up or down arrow in object manager.
Selecting one hierachy level up would be nice too :-)

Can anybody help?
The clostest thing I got was:

main(doc, op)
{
var obj;
obj = doc->GetActiveObject();
(obj->GetNext());
}

Well at least it didnīt give me an error ;)

Scott Ayers
02-14-2011, 03:19 PM
Do you have my Coffee Bible?
There's tons of small copy and paste code snippets in it that should help you do these kinds of simple things.

-ScottA

Cairyn
02-14-2011, 03:23 PM
Iīm totally new to scripting and I promise to do tutorials and get the basics done ;-)
But right now Iīm looking for a little script to select the next or previous object.


Well, you will need to deselect the previous object, and select the next, too.
And it's a good idea to check for nulls, or the script will crash when nothing is selected.
For single selections, the following will do:


main(doc, op)
{
var obj;
obj = doc->GetActiveObject();
if (obj != NULL)
{
obj->DelBit(BIT_AOBJ);
obj = obj->GetNext();
if (obj != NULL)
{
obj->SetBit(BIT_AOBJ);
}
}
}


Replace GetNext() with GetPrev() to move upwards (must be a different script, obviously) and use GetUp() and GetDown() to move through the hierarchy (in which case you may also want to show the element so you see where you are).

Schnupps
02-14-2011, 04:43 PM
Thanks, seems to be more complicated than I thought...
It would need much more work to respect the hierachies and Object Manager expanded/collapsed (if accesable) to work exactly like up/down keys I guess.

With Coffee you canīt simulate key presses, which are taken as hotkeys?
I could just make call "object manager" id followed by the up/down keystroke then...

Downloaded the bible, looking good :-)

Schnupps
02-18-2011, 11:30 AM
Ok, started learning seriously with the help of RuiMacīs CoffeBook, the Coffe Bible and the SDK of course.
For a later If function I want to check, wether my object is folded in OM.

{
var obj;
var state;
obj = doc-> GetActiveObject();

state = obj->GetBit(BIT_OFOLD);

println(state);
}


But it always just prints 0
Sorry, itīs probably very basic, but I ainīt got any scripting experience at all :-(

Cairyn
02-18-2011, 11:56 AM
Ok, started learning seriously with the help of RuiMacīs CoffeBook, the Coffe Bible and the SDK of course.
For a later If function I want to check, wether my object is folded in OM.


state = obj->GetBit(BIT_OFOLD);


But it always just prints 0
Sorry, itīs probably very basic, but I ainīt got any scripting experience at all :-(

BIT_OFOLD is a legacy bit from the time when there was only one object manager. Today, there are up to 4 object managers, and each can have a different folding situation.

In C++ it would be the bit NBIT_OM1_FOLD (OM1, OM2, OM3, OM4 for the 4 object managers) set by the method GetNBit(). Sorry, I don't know by heart what the COFFEE equivalent is; this method does not exist in the COFFEE API.

Scott Ayers
02-18-2011, 04:06 PM
Yeah.
BIT_OFOLD and BIT_AFOLD haven't worked for many years now. Yet Maxon keeps including them in their SDK's for some strange reason.:shrug:

Robert,
Have you been able to fold things with C++?
They aren't working for me. And I still have to use CallCommand(100004749) to do it. Which is something I'd rather not do.
BaseObject* obj = doc->GetActiveObject(); // get the active object
if(!obj) return 0;
//obj->SetBit(NBIT_OM1_FOLD); // Fold --This does NOT work!!!
CallCommand(100004749); // Fold All--This works fine
LONG state = obj->GetNBit(NBIT_OM1_FOLD); // Checks if the object is folded or not folded
EventAdd();//Update all the changes
GePrint(RealToString(state)); //Print the folded state to the console

-ScottA

Cairyn
02-19-2011, 09:43 AM
Yeah.
BIT_OFOLD and BIT_AFOLD haven't worked for many years now. Yet Maxon keeps including them in their SDK's for some strange reason.:shrug:

Robert,
Have you been able to fold things with C++?
They aren't working for me.

//obj->SetBit(NBIT_OM1_FOLD); // Fold --This does NOT work!!!


-ScottA

Just use SetNBit() there...

Scott Ayers
02-19-2011, 03:16 PM
No can do.
obj->SetNBit(NBIT_OM1_FOLD); = Error: 'SetNBit': is not a member of BaseObject.

I looked through the alphabetical listing of available methods and I can't even find an SetNBit() function in the SDK.

-ScottA

Cairyn
02-20-2011, 07:19 PM
No can do.
obj->SetNBit(NBIT_OM1_FOLD); = Error: 'SetNBit': is not a member of BaseObject.

I looked through the alphabetical listing of available methods and I can't even find an SetNBit() function in the SDK.


No SetNBit? I thought I used that. Meh, then

Bool ChangeNBit (file:///D:/Applications/3D/Cinema4D/Cinema4D%20Doku/Programming/Cinema4D_API_V12.0_preliminary/help/pages/c4d_baselist/class_GeListNode540.html#changenbit25)(NBIT (file:///D:/Applications/3D/Cinema4D/Cinema4D%20Doku/Programming/Cinema4D_API_V12.0_preliminary/help/pages/ge_prepass/enum_NBIT995.html) bit, NBITCONTROL (file:///D:/Applications/3D/Cinema4D/Cinema4D%20Doku/Programming/Cinema4D_API_V12.0_preliminary/help/pages/ge_prepass/enum_NBITCONTROL996.html) bitmode);

with NBITCONTROL_SET (in class GeListNode).

Scott Ayers
02-21-2011, 12:51 AM
Nope...Tried that one too. Doesn't work either.

I've tried every possible combination of GetBit(), GetNBit, ChangeNBit() I can think of.
But all of these various functions do for me is control the state of the bit. And none of them will physically collapse the hierarchy. Except for the CallCommand(100004749).


-ScottA

Cairyn
02-21-2011, 11:03 AM
Nope...Tried that one too. Doesn't work either.

I've tried every possible combination of GetBit(), GetNBit, ChangeNBit() I can think of.
But all of these various functions do for me is control the state of the bit. And none of them will physically collapse the hierarchy. Except for the CallCommand(100004749).


I checked the CollieTools (which do work fine), and I'm using ChangeNBit there:

Bool CCollieFoldApplier::DoApply (BaseObject* p_pTarget)
{
if (p_pTarget == NULL) return TRUE;

// NOTE: Fold and unfold operations are not part of the undo system,
// so we won't make undo possible here!
switch (m_nObjectManager)
{
case 1: p_pTarget->ChangeNBit(NBIT_OM1_FOLD, m_bUnfold ? NBITCONTROL_SET : NBITCONTROL_CLEAR); break;
case 2: p_pTarget->ChangeNBit(NBIT_OM2_FOLD, m_bUnfold ? NBITCONTROL_SET : NBITCONTROL_CLEAR); break;
case 3: p_pTarget->ChangeNBit(NBIT_OM3_FOLD, m_bUnfold ? NBITCONTROL_SET : NBITCONTROL_CLEAR); break;
case 4: p_pTarget->ChangeNBit(NBIT_OM4_FOLD, m_bUnfold ? NBITCONTROL_SET : NBITCONTROL_CLEAR); break;
default: break;
}
return TRUE;
}


So, whatever is wrong in your code, it's not that function. The only thing that comes to mind immediately is that you may use the wrong flag for the wrong object manager instance, but I'm sure you have checked that already. Sorry, can't help in this case.

Scott Ayers
02-21-2011, 02:54 PM
Holy moley!
No wonder why I couldn't get it to work. That code is different from to what the SDK says.

The SDK says to use this: Bool ChangeNBit(NBIT (http://forums.cgsociety.org/../ge_prepass/enum_NBIT999.html) bit, NBITCONTROL (http://forums.cgsociety.org/../ge_prepass/enum_NBITCONTROL1000.html) bitmode)
That's illustrating a function pointing to an object. With two parameters in it.
But what's missing from the SDK description is the bit state, and that weird ? symbol are also needed.
How on earth would a new user figure that out based on what the SDK says? :banghead:

Thanks a lot Robert. Got it working now.
Here's a very simple example just in case anyone else new to C++ had the same problem: BaseObject* obj = doc->GetActiveObject(); // get the active object
if(!obj) return 0;
LONG fold = obj->GetBit(BIT_OFOLD);
obj->ChangeNBit(NBIT_OM1_FOLD, fold ? NBITCONTROL_SET : NBITCONTROL_CLEAR);

Thanks again,
-ScottA

Cairyn
02-22-2011, 10:19 PM
Holy moley!
No wonder why I couldn't get it to work. That code is different from to what the SDK says.

The SDK says to use this: Bool ChangeNBit(NBIT (http://forums.cgsociety.org/../ge_prepass/enum_NBIT999.html) bit, NBITCONTROL (http://forums.cgsociety.org/../ge_prepass/enum_NBITCONTROL1000.html) bitmode)
That's illustrating a function pointing to an object. With two parameters in it.
But what's missing from the SDK description is the bit state, and that weird ? symbol are also needed.
How on earth would a new user figure that out based on what the SDK says? :banghead:

Thanks a lot Robert. Got it working now.
Here's a very simple example just in case anyone else new to C++ had the same problem: BaseObject* obj = doc->GetActiveObject(); // get the active object
if(!obj) return 0;
LONG fold = obj->GetBit(BIT_OFOLD);
obj->ChangeNBit(NBIT_OM1_FOLD, fold ? NBITCONTROL_SET : NBITCONTROL_CLEAR);

Thanks again,
-ScottA

umm, just for the record: that weird ? : symbol is a standard C++ operator, and has nothing to do with the function. The expression x ? y : z just means: if x then y else z - yes, it is an "if" with a return value. What I did there is just introducing a controlling boolean variable (m_bUnfold) to determine the behaviour of the ChangeNBit() method (either setting or clearing the flag).

obj->ChangeNBit(NBIT_OM1_FOLD, NBITCONTROL_SET) should work just fine without the ?, and the documentation is complete after all... and you should not access BIT_OFOLD any more for whatever reason, since it is deprecated and has no effect (or worse).

Scott Ayers
02-22-2011, 11:30 PM
Thanks for pointing that out Robert.
I didn't recognize those as conditional operators. I haven't had a chance to use those yet in any of my code.

But obj->ChangeNBit(NBIT_OM1_FOLD, NBITCONTROL_SET) just refuses to work for me.
I've got too many other things to learn right now. So I'm giving up on it for now.

Thanks for your help,
-ScottA

CGTalk Moderation
02-22-2011, 11:30 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.