Inserting as a child without cloning first ?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/08/2012 at 15:42, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R13 
Platform:   Windows  ;   
Language(s) :   C.O.F.F.E.E  ;

---------
Guys is it possible to insert an object already in the scene hierarchy as a child of another object ?

I tried this and Cinema crashed.
I think this is not possible using the insertObject() method because there can't be 2 instances of the same unique object in two different positions in the same hierarchy.

This is my code (I use with a shorcut) where I had to clone the obj first to avoid crashing:

main(doc,op)
{
	var myObj = doc->GetActiveObject(); // Gets the Selected Object
	if(!myObj) {
		return;
	}
	var myObjParent = myObj->GetUp(); // Gets the Parent
	if(myObjParent) {
		if(myObjParent->GetType() == 1007455) { // Is HyperNurbs ?
  
			/*
					Snippet to activate/deactivate visibilty on HyperNurbs Object
			*/
  
			if (myObjParent#ID_BASEOBJECT_GENERATOR_FLAG == TRUE) { // Active ?
				myObjParent#ID_BASEOBJECT_GENERATOR_FLAG = FALSE; 
			}
			else {
				myObjParent#ID_BASEOBJECT_GENERATOR_FLAG = TRUE;
			}
  
			return;
		}
	}
	
	// If no parent Hypernurbs Object Found - Create One
  
	CallCommand(1007455); // Create an HyperNurbs Object
  
	var myHPN = doc->GetActiveObject(); // And Select that
	
	if(!myHPN) {
		return;
	}
	var newObj = myObj->GetClone(0);
	doc->InsertObject(newObj, myHPN, NULL); // Need an Alternative
	doc->SetActiveObject(myObj);
}

Is there any way to access a method that instead of inserting the objects just move that in the hierarchy to avoid cloning ?

And do you guys know the method to delete an object fron the hierarchy, programmatically, not by selecting it and deleting with CallCommand(100004787); // Delete

The script is made to improve workflow in SDS modeling, to get a similar behaviour like in Modo.

Thanks for the attention.

EDIT: I've found how to delete the object (obj->Remove()).

But that is not what I want basically because the behaviour I want to implement will make the tool selected or the selected geometry(Polygon,Edges,Points), remain selected.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/08/2012 at 00:24, xxxxxxxx wrote:

First you have to remove the object from the document and then insert it as a child of the other object.  Everything is in a list (thus the derivation from BaseList2D) and you must insert things into the list and remove them before deletion or reinsertion.  You don't need a clone unless you want to have two objects.

myObj->Remove();  
doc->InsertObject(newObj, myHPN);

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/08/2012 at 07:14, xxxxxxxx wrote:

So I can remove the Obj without unloading it from the memory, I'm simply removing from the hierarchy then placing it back again where I want.

Yes with this correction now works flawlessly. I switch on the fly without touching the Hierarchy using TAB key, I'm also improving the script to include a switch between CClark with nGons and without it.

And adding a check to avoid if the Hypernurbs object get selected in the Hierarchy to create a new One.

SanX.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/08/2012 at 11:03, xxxxxxxx wrote:

Exactly.  Removing it from the list does not Free (delete) it, it just removes it from the hierarchy.  That's a good thing to remember.  Before you can free anything in a list (objects, tags, materials, etc.), you must Remove() them first.

Glad that you have it working! :)