removing all nullobjects

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

On 11/06/2009 at 14:39, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   r11 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
Hi there,

i am trying to walk thru a document and remove all nullobjects. of course my approach crashes because of the usage of child after deleting it. but i dont know how to delete the object. after child=child->GetNext() it isnt referring the nullobject anymore:

> <code>
>
>> `

  
\>  void StepThru(BaseDocument* doc, BaseObject *child)  
\>  {  
\>       while (child)  
\>       {  
\>            if (child->GetType()==Onull)   
\>            {  
\>                 blDelete(child);  
\>            }  
\>            StepThru(doc,child->GetDown());  
\>            child = child->GetNext();  
\>       }  
\>  }  
\>  

`
>
> </code>

any hints? thanks in advance.

cheers,
Ello

Another question is, how can i put all objects of a document in an AtomArray? There i could use FilterObjects, right?

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

On 11/06/2009 at 15:32, xxxxxxxx wrote:

BaseObject\* nchild; \> for (; child; child = nchild) \> { \>      nchild = child->GetNext(); \>      if (child->GetType() == Onull) \>      { \>           child->Remove(); // CRITICAL!!! \>           blDelete(child); \>      } \>      else StepThru(doc,child->GetDown()); \> }

The object must be removed from any list in which it resides before being deleted. Same goes for tags, materials, and so on.

Do you care if there are children of the Null objects being deleted? If you don't want to delete the children of Null objects, it gets a bit more tricky. You have to obj->Remove() each direct child (before deleting the Null object, of course) and reinsert somewhere in the BaseDocument.

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

On 11/06/2009 at 23:24, xxxxxxxx wrote:

thanks for your snippet, it shows me real good to come aroud my first problem, but the nullobjects have of course children which shall stay.

i feared it would get that complex;)
so, would it be a better approach to clone all other objects into a new document and just kill the original one?

Anyhow, i would like to know how to use the AtomArray -> FilterObject. Is there an example somewhere?

many thanks
cheers,
Ello

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

On 12/06/2009 at 07:43, xxxxxxxx wrote:

What you can do is something like this:

> BaseObject\* nchild; \> BaseObject\*     cop; \> BaseObject\* cup; \> BaseObject\*     cnext; \> Matrix mg; \> for (; child; child = nchild) \> { \>      nchild = child->GetNext(); \>      if (child->GetType() == Onull) \>      { \>           // Take children of this Onull object and put as children of Onull's parent (or root) \>           cup =     child->GetUp(); \>           for (cop = child->GetDown(); cop; cop = cnext) \>           { \>                cnext =     cop->GetNext(); \>                mg =     cop->GetMg(); \>                cop->Remove(); \>                doc->InsertObject(cop, cup, (cup)?cup->GetDownLast() :NULL, FALSE); \>                cop->SetMg(mg); \>                cop->Message(MSG_UPDATE); \>           } \>           child->Remove(); \>           blDelete(child); \>      } \>      else StepThru(doc,child->GetDown()); \> }

Not too complex but just requires careful construction. Note that the global matrix is grabbed and reset after the reinsertion (of cop) since the transforms are not compensated for parenting changes like when doing this interactively in the Object Manager.

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

On 12/06/2009 at 08:32, xxxxxxxx wrote:

thank you.. i'll give that a try.
one question, what does this exactly mean:

doc->InsertObject(cop, cup, (cup)?cup- >GetDownLast() :NULL, FALSE);

cheers,
Ello

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

On 12/06/2009 at 10:48, xxxxxxxx wrote:

()?: is a C conditional operator. It's just shorthand for an if/else statement so that it can be embedded like I did. For instance:

int a = 1;
int b;
if (a) b=10;
else   b=0;

becomes:

int a = 1;
int b = (a)?10:0;

I do this because 'cup' could be NULL (if the Onull has no parent).

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

On 12/06/2009 at 11:40, xxxxxxxx wrote:

thank you for this! it is really cool

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

On 12/06/2009 at 13:10, xxxxxxxx wrote:

Fascinating Robert.
It works in Coffee as well!
The more I learn about programming, the less I realize I know 🙂
As in real life.

Cheers
Lennart