Removing Materials

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

On 19/12/2009 at 12:59, xxxxxxxx wrote:

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

---------
Is it possible to remove all materials that are associated with an object automatically when that object is deleted from the object manager?

~Shawn

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

On 19/12/2009 at 13:05, xxxxxxxx wrote:

Call "Remove Unused Materials" with CallCommand(12168) after the object is removed from the document.

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

On 19/12/2009 at 13:08, xxxxxxxx wrote:

Where do I do that?
Under what function.

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

On 19/12/2009 at 13:18, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Call "Remove Unused Materials" with CallCommand(12168) after the object is removed from the document.

That´s quite unsafe I would say. If there are other unused materials in the scene they will be removed too. It´s better to remove any materials in Free() yourself manually. However, I am not sure if that is safe either because Free is also called when closing the scene I guess. Why would you remove materials anyway? That´s definetly a user interaction, so it´s not that bad if you don´t remove them. But maybe the support knows a valid and safe way (maybe there is an internal message not documented).

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

On 19/12/2009 at 13:26, xxxxxxxx wrote:

My planet generator creates materials for the different layers of the planet.  When the user deletes the planet object I would like the associated materials to be deleted as well so as to not clog up the material editor.

Does anyone know how I could do this safely?

~Shawn

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

On 19/12/2009 at 13:48, xxxxxxxx wrote:

Not unsafe whatsoever.  If there are other dangling materials, not good, but it has no adverse side-affects at all.  I've used it.  The only real problem is that it will create an undo (because it is performing a command).

You'll need to go through the object's Texture tags, get the materials, and remove/delete them yourself if you want to have atomic control over the process.  This, obviously, will need to be done before deleting the object.  After that, good luck.  The connections (Texture tags) between the object and material will be lost after the object is deleted.  The only way around that would be to store BaseLinks to materials on each of your object somewhere else.

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

On 19/12/2009 at 13:52, xxxxxxxx wrote:

I understand how to get to the material and how to remove it..   for example I would use

textTag->GetMaterial()->Remove();

but where would I do this so that it only happens when the object is removed from the object manager?

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

On 19/12/2009 at 14:10, xxxxxxxx wrote:

As I said, if the user selects the object and deletes it, that is it.  There isn't anything you can do to get the object before it is actually deleted.  It is already too late to know which materials were associated with that object.

Your only alternative is to track your objects and their materials.  When the user deletes the object, use that tracking information to delete the orphaned materials.  You would probably need to use a SceneHook plugin to scan the document and check to see if an object referenced in your tracking no longer exists in the document.

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

On 19/12/2009 at 14:13, xxxxxxxx wrote:

This seemed to work.  When the Planet Object is deleted is seems to call Free()

void Planet::Free(GeListNode* node)
{
 
  BaseDocument* doc = node->GetDocument();
  BaseObject* prnt = doc->GetActiveObject();
 
  //Remove Materials when Object is deleted
  if (prnt->GetDown())
  {
      GePrint("Planet Object Removed");
      TextureTag* surfaceTag = (TextureTag* )(prnt->GetDown()->GetFirstTag());
      TextureTag* lightTag = (TextureTag* )(prnt->GetDown()->GetFirstTag()->GetNext());
      TextureTag* cloudTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetFirstTag());
      TextureTag* atmTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetNext()->GetFirstTag());
 
      surfaceTag->GetMaterial()->Remove();
      lightTag->GetMaterial()->Remove();
      cloudTag->GetMaterial()->Remove();
      atmTag->GetMaterial()->Remove();
  }

}

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

On 19/12/2009 at 15:12, xxxxxxxx wrote:

You never mentioned that it was a Plugin object. 🙂

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

On 19/12/2009 at 15:47, xxxxxxxx wrote:

Woops Sorry...    Thanks for your help Robert.

~Shawn

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

On 19/12/2009 at 15:53, xxxxxxxx wrote:

I have another question.   currently, with this plugin object,  the user has to press the CREATE PLANET button for the CreatePlanet() to be called.    I am trying to get CreatePlanet() to be called from init() to skip this button step.

currently I am able to get the init() to call Create Planet with,

BaseObject* op = static_cast<BaseTag*>(node)->GetObject();

CreatePlanet(op,node);

however, when it gets in to CreatePlanet() is returns false because I have the following code

if (!op)
      return FALSE;

I must be passing op incorrectly to CreatePlanet but I am not sure what I am doign wrong.  Does anyone know how I would do this correctly?

Thanks,

~Shawn

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

On 19/12/2009 at 18:42, xxxxxxxx wrote:

Originally posted by xxxxxxxx

This seemed to work.  When the Planet Object is deleted is seems to call Free()

Hmm, isn´t that exactly what I said?

*thinkingtomyself*Maybe some magic makes my posts invisible? coooool. I have three apes sitting on my chest peeing on me...phew, glad nobody can read this. I am the matrix. I am the matrix. I am the matrix. If I keep on saying this it will come true... *stopthinking*

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

On 19/12/2009 at 18:44, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Not unsafe whatsoever.  If there are other dangling materials, not good

Well, I am not sure how you work but I don´t know a single real project that does not have several materials not associated yet. It is simply unsafe and gets worse when materials are hidden in unselected material groups, so the user doesn´t even notice the missing materials. If that´s not unsafe what is unsafe? Actually any action that removes objects the user does not associate with the action (which is the case for unused material flushing) is unsafe, not codewise but from users POV. Einsteins "Do as much as you can but not more than necessary" fits quite well here.

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

On 19/12/2009 at 19:36, xxxxxxxx wrote:

LOL..   yes 3DDesigner..   That is what you said..   And I appreciate your help too...     🙂
hence the use of the free() function    You are the man and I bow to you.   HAHA

~Shawn