Material created/deleted event



  • On 23/04/2018 at 02:23, xxxxxxxx wrote:

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

    ---------
    Hello.

    I have a dialog that needs to know when new materials are created or when one is deleted.
    Are there core messages for these functions ?
    If not how can I do it ?

    Thank you.



  • On 24/04/2018 at 02:23, xxxxxxxx wrote:

    Hi,

    There isn't specialized core messages for material creation/deletion.

    A specific document message is sent when a material gets added to a document: MSG_DOCUMENTINFO _- >type:_MSG_DOCUMENTINFO_TYPE_MATERIAL_INSERT. Note it's only sent to scene hooks.

    You can use the general core messsage EVMSG_CHANGE and perform checks to see if a material was created/deleted.



  • On 24/04/2018 at 04:14, xxxxxxxx wrote:

    Hello and thank you very much for your help.

    By handling EVMSG_CHANGE, I'll have to check all materials one by one to see if one is deleted, right ? 
    To do that I need to store the materials into baselinks and check if these are empty.

    Thank you.



  • On 24/04/2018 at 09:44, xxxxxxxx wrote:

    I have done something similar (but then with tags on an object).

    Basically what you do is keep a maxon::BaseArray of BaseLink as a member of your derived MessageData. Then in your MessageData::CoreMessage you react to EVMSG_CHANGE by getting all materials from the scene, and iterating over your BaseArray.
    When the obtained material from the stored BaseLink is nullptr, you know this material has been deleted. Still you need to update the stored BaseArray with potential new materials to keep in sync.



  • On 24/04/2018 at 14:25, xxxxxxxx wrote:

    Hello and thank you very much for your answer.

    That's what I do about the deleted materials, but it seems a little bit slow if you have to check, for example 400 materials on every EVMSG_CHANGE to see which one doesn't exist in the BaseArray.
    I'll try to find another way.

    Thank you very much guys !



  • On 24/04/2018 at 23:17, xxxxxxxx wrote:

    Just a thought.
    But you're the only one to know if this might work, as it depends on what you actually need.
    Without knowing the whole context it's hard to evaluate if this "short-cut" is useful.

    What if you could reduce the times you need to check for deleted/inserted materials, by looking at the material count in the scene, and the count in your BaseArray<BaseLink>. If the counts are equal, you know no material was added or removed, and no need to check further.
    Is this a safe to assume?
    Well, consider that when user removes or inserts materials there will always be an EVMSG_CHANGE sent out. But a user will not be able to AND remove AND insert a material without an EVMSG_CHANGE being sent between the remove and insert. Which then means you can detect the removal/insertion simply by looking at the count.
    What will not be supported is when scripts or plugins are involved, which might perform remove and insert in a single step and perform a single EventAdd() afterwards, resulting in the same count of materials before as after.
    But as said, this depends on the context you need.


Log in to reply