InsertObject Increment



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

    On 07/04/2012 at 01:45, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:    
    Platform:      
    Language(s) :

    ---------
    Hi All,
     
    I'm trying to insert a line of cubes along the X axis as determined by a number the user selects (via a Real gui element). Everything seems to work fine, except I can't get each cube to become a child of the previous inserted cube object. My code below:
     
    note: Prev_Cube is just a marker for myself to fix (if that's where the fix is needed...!)

    if(Cube_Count == 0){goto End;}  
    for(i=1; i<=Cube_Count;)  
    {  
     BaseObject *Cube = BaseObject::Alloc( Ocube );  
      if(!Cube) GePrint("Cube failure");  
     if(i!= Cube_Count){Cube->SetName("Cube " + LongToString(i));}  
     else{Cube->SetName("Cube " + LongToString(i));}  
     if(Cube_Count == 1){Cube->SetRelPos(Vector(200.0, 0.0, 0.0));}  
     else{Real Dist = 200/Cube_Count;GePrint(LongToString(Div));Cube->SetRelPos(Vector(Dist, 0.0, 0.0));}  
      if(i == 1)  
     {  
    doc->InsertObject(Cube, NULL, NULL);  
     }  
     else  
     {  
    doc->InsertObject(Cube, Prev_Cube???, NULL);    // what's missing in-place of Prev_Cube here???  
     }  
      EventAdd();  
     i++;  
     if(i > Cube_Count){goto End;}  
    }
    

    Cheers,
     
    WP.



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

    On 07/04/2012 at 02:31, xxxxxxxx wrote:

    GeListNode has some methods to group objects.

    InsertUnder() and InsertUnderLast() would be the one you are searching for. is there a reason why
    you have to add each cube manually into the document, instead of creating the whole hierarchy 
    within the code and then just return the parent baseobject containing the full hierarchy ?



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

    On 07/04/2012 at 02:47, xxxxxxxx wrote:

    Hi littledevil,
     
    I had been looking at GeListNode but couldn't quite get it to work. I'll go back and have a play with that - thanks!
     
    Re: manually adding them to doc - you'll have to forgive my ignorance on this (learning this as I go) but are you refering to having the Baseobject and/or EventAdd inside the loop? It's just how I managed to get it all to work thus far - no other reason really! Is there a more efficient way this could be done?
     
    Thanks again,
     
    WP.



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

    On 07/04/2012 at 02:56, xxxxxxxx wrote:

    im refering to  doc->InsertObject . you are placing each cube seperatly into the document. which 
    forces a rebuild of the cache each time. baseobjects are derived from BaseList2D which is derived 
    from GeListNode. so any baseobject can be a tree of baseobjects. just get a pointer to your last 
    cube and it will be something like pointer newcube.InsertUnder(pointer lastcube).



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

    On 07/04/2012 at 03:20, xxxxxxxx wrote:

    Ah - so I only need to return the initial parent cube and the rest will follow?
    The experiments I did with the .InsertUnder etc must have been close - but were obviously not right. Will post something a bit more fruitful when it's going (or if it isn't!).
     
    Cheers,
     
    WP.



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

    On 07/04/2012 at 03:32, xxxxxxxx wrote:

    yes,

    BaseObject *cube = BaseObject::Alloc( Ocube );
    BaseObject *sphere = BaseObject::Alloc( Osphere );
      
    cube.InsertUnder(sphere);
      
    return sphere;
    

    will return a sphere with cube as its child.

    edit : i am a beginner myself, but here is an example of my plugin work in progress, it is a static method which either returns a loftnubrs>nsidespline or a loftnubrs > spline + spline structure. it
    doesn't inculde the recursion / tree aspect of your example, but maybe it helps.
    i

    static BaseObject *GetDisc(BaseObject *op)
    {
    	BaseContainer *bc = op->GetDataInstance();
    	BaseObject *loft = NULL, *inner = NULL, *outer = NULL;
      
    	switch (bc->GetLong(PLIGHT_DISC_TYPE))
    	{
    		case PLIGHT_DISC_TYPE_DISC :
    			{
    				loft = BaseObject::Alloc(Oloft);
    				inner = BaseObject::Alloc(Osplinearc);
    				outer = BaseObject::Alloc(Osplinearc);
    				BaseContainer *loftbc = loft->GetDataInstance();
    				BaseContainer *innerbc = inner->GetDataInstance();
    				BaseContainer *outerbc = outer->GetDataInstance();
      
    				loft->SetName("Light");
    				loftbc->SetBool(LOFTOBJECT_ADAPTIVEY , FALSE);
    				loftbc->SetLong(LOFTOBJECT_SUBX, bc->GetReal(PLIGHT_DISC_SEGMENTS_ROTATION) * 4 + 1);
    				loftbc->SetLong(LOFTOBJECT_SUBY, bc->GetReal(PLIGHT_DISC_SEGMENTS_DISC) + 2);
    				loftbc->SetLong(CAP_START, CAPTYPE_NOCAP);
    				loftbc->SetLong(CAP_END, CAPTYPE_NOCAP);
    				outer->SetName("Outer");
    				outerbc->SetReal(PRIM_ARC_RADIUS , bc->GetReal(PLIGHT_DISC_OUTER_SIZE_X));
    				outerbc->SetReal(PRIM_ARC_START , bc->GetReal(PLIGHT_DISC_SLICE_START));
    				outerbc->SetReal(PRIM_ARC_END , bc->GetReal(PLIGHT_DISC_SLICE_END));
    				if (bc->GetBool(PLIGHT_DISC_ISELLIPTICAL))
    					if (bc->GetReal(PLIGHT_DISC_OUTER_SIZE_X) > 0)
    						outer->SetAbsScale(Vector(1 , (bc->GetReal(PLIGHT_DISC_OUTER_SIZE_Y)/bc->GetReal(PLIGHT_DISC_OUTER_SIZE_X)) , 1));
    					else
    						outer->SetAbsScale(Vector(1 , 1 , 1));
    				outer->InsertUnder(loft);
    				inner->SetName("Inner");
    				innerbc->SetReal(PRIM_ARC_RADIUS , bc->GetReal(PLIGHT_DISC_INNER_SIZE_X));
    				innerbc->SetReal(PRIM_ARC_START , bc->GetReal(PLIGHT_DISC_SLICE_START));
    				innerbc->SetReal(PRIM_ARC_END , bc->GetReal(PLIGHT_DISC_SLICE_END));
    				if (bc->GetBool(PLIGHT_DISC_ISELLIPTICAL))
    					if (bc->GetReal(PLIGHT_DISC_INNER_SIZE_X) > 0)
    						inner->SetAbsScale(Vector(1 , bc->GetReal(PLIGHT_DISC_INNER_SIZE_Y)/bc->GetReal(PLIGHT_DISC_INNER_SIZE_X) , 1));
    					else
    						inner->SetAbsScale(Vector(1 , 1 , 1));
    				inner->InsertUnderLast(loft);
    			}
    			break;
    		case PLIGHT_DISC_TYPE_NSIDE :
    			{
    				loft = BaseObject::Alloc(Oloft);
    				outer = BaseObject::Alloc(Osplinenside);
    				BaseContainer *loftbc = loft->GetDataInstance();
    				BaseContainer *outerbc = outer->GetDataInstance();
      
    				loft->SetName("Light");
    				loftbc->SetLong(CAP_TYPE , CAP_TYPE_NGON);
    				outerbc->SetLong(SPLINEOBJECT_INTERPOLATION , SPLINEOBJECT_INTERPOLATION_NATURAL);
    				outerbc->SetLong(SPLINEOBJECT_SUB , bc->GetLong(PLIGHT_NSIDE_SEGMENTS));
    				outerbc->SetReal(PRIM_NSIDE_RADIUS, bc->GetReal(PLIGHT_NSIDE_SIZE_X));
    				outerbc->SetBool(PRIM_NSIDE_ROUNDING , TRUE);
    				outerbc->SetReal(PRIM_NSIDE_RRADIUS, bc->GetReal(PLIGHT_NSIDE_ROUNDING));
    				outerbc->SetLong(PRIM_NSIDE_SIDES, bc->GetReal(PLIGHT_NSIDE_SIDES));
    				if (bc->GetBool(PLIGHT_DISC_ISELLIPTICAL))
    					if (bc->GetReal(PLIGHT_DISC_INNER_SIZE_X) > 0)
    						outer->SetAbsScale(Vector(1 , bc->GetReal(PLIGHT_NSIDE_SIZE_Y)/bc->GetReal(PLIGHT_NSIDE_SIZE_X) , 1));
    					else
    						outer->SetAbsScale(Vector(1 , 1 , 1));
    				outer->SetAbsRot(Vector(0 , 0 , bc->GetReal(PLIGHT_NSIDE_ROTATION)));
    				outer->InsertUnder(loft);			
    			}
    			break;
    	}
    	return loft;
    }
    


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

    On 07/04/2012 at 05:47, xxxxxxxx wrote:

    Try it this way:

    if(Cube_Count == 0L){goto End;}  
    BaseObject*    Cube =    NULL;  
    BaseObject* Parent_Cube = NULL;  
    for(i = 1L; i <= Cube_Count; ++i)  
    {  
      Cube = BaseObject::Alloc( Ocube );  
      if (!Cube) { GePrint("Cube failure"); break; }  // Or continue but you can't continue down from here if Cube equals NULL unless you want a definite crash!  
      if (i != Cube_Count)    Cube->SetName("Cube " + LongToString(i));  
      else Cube->SetName("Cube " + LongToString(i));  
      if (Cube_Count == 1L) Cube->SetRelPos(Vector(200.0, 0.0, 0.0));  
      else  
      {  
          Real Dist = 200.0/Cube_Count;  
          GePrint(LongToString(Dist));  
          Cube->SetRelPos(Vector(Dist, 0.0, 0.0));  
      }  
      doc->InsertObject(Cube, Parent_Cube, NULL);  
      Parent_Cube =    Cube;  
      EventAdd();  
    }
    

    Note that if Parent_Cube is NULL then Cube (at i == 1L) is inserted at the root.  Then each subsequent Cube is inserted as a child of the previously created Cube as set by Parent_Cube in the loop;



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

    On 08/04/2012 at 02:39, xxxxxxxx wrote:

    Aha -adding a null BaseObject that you change the newly inserted object over too in the loop as you've suggested Rob with the "BaseObject Parent = NULL" line did the trick.
     
    I've got to work a bit more on this gelistnode tree business as I think I could utilise that somewhere else - but for now I'm a happy camper!
     
    Thanks to both of you - your help is much appreciated!
     
    WP.


Log in to reply