Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Material created/deleted event

 Post Reply Post Reply
Author
Message
peterakos View Drop Down
Member
Member


Joined: 2015 Jul 13
Online Status: Offline
Posts: 340
Post Options Post Options   Quote peterakos Quote  Post ReplyReply Direct Link To This Post Topic: Material created/deleted event
    Posted: 2018 Apr 23 at 2:23am

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.
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1127
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 24 at 2:23am
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.






Edited by Yannick Puech - 2018 Apr 24 at 2:23am
MAXON
Developer Support
Back to Top
peterakos View Drop Down
Member
Member


Joined: 2015 Jul 13
Online Status: Offline
Posts: 340
Post Options Post Options   Quote peterakos Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 24 at 4:14am
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.



Back to Top
C4DS View Drop Down
Member
Member


Joined: 2015 Dec 01
Online Status: Offline
Posts: 212
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 24 at 9:44am
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.

Back to Top
peterakos View Drop Down
Member
Member


Joined: 2015 Jul 13
Online Status: Offline
Posts: 340
Post Options Post Options   Quote peterakos Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 24 at 2:25pm
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 !
Back to Top
C4DS View Drop Down
Member
Member


Joined: 2015 Dec 01
Online Status: Offline
Posts: 212
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 24 at 11:17pm
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.


Edited by C4DS - 2018 Apr 24 at 11:19pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.