Hi all,
Hope you are well in these crazy times!
I'm having trouble understanding how ShowPopupDialog
currently works in R21, if caught by MessageData plugin's CoreMessage
. It keeps freezing Cinema, could be thread related (which I don't know a lot of)?
I manage to get the data across externally fine but when creating the menu it freezes immediately after c4d.gui.ShowPopupDialog
is called.
# Import modules
import os
import c4d
from c4d import documents
plugin_ID = 1055685
plugin_ID_loader = 1055684
MENU_ADD_ASSETS = c4d.FIRST_POPUP_ID
MENU_ADD_MATERIALS = c4d.FIRST_POPUP_ID + 1
MENU_REPLACE_ASSETS = c4d.FIRST_POPUP_ID + 2
MENU_REPLACE_MATERIALS = c4d.FIRST_POPUP_ID + 3
MENU_REPLACE_TAG = c4d.FIRST_POPUP_ID + 4
class AOMessage(c4d.plugins.MessageData):
"""
Class for the MessageData plugin.
"""
def GetTimer(self):
"""
Called to return a time in milliseconds to receive timer messages (MSG_TIMER) with that interval in CoreMessage.
This method is queried again after each message..
:return: The time in miliseconds.
"""
return 0
def CoreMessage(self, id, bc):
"""
Called to receive core messages.
:param id: The id of the messages received.
:param bc: The BaseContainer objects with message data.
:return: True if Message is received.
"""
if id == plugin_ID_loader:
world_container = c4d.GetWorldContainerInstance()
doc = documents.GetActiveDocument()
paths_str = world_container.GetString(plugin_ID_loader)
paths_lst = paths_str.split(', ')
active_objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)
active_mat = doc.GetActiveMaterial()
doc.StartUndo()
# Dialog for importing assets
menu = c4d.BaseContainer()
if active_objs or active_mat:
menu.InsData(MENU_REPLACE_ASSETS, 'Replace Asset(s)')
menu.InsData(MENU_REPLACE_MATERIALS, 'Replace Material(s)')
menu.InsData(MENU_REPLACE_TAG, 'Replace Texture Tag(s)')
else:
menu.InsData(MENU_ADD_ASSETS, 'Add Asset(s)')
menu.InsData(MENU_ADD_MATERIALS, 'Add Material(s)')
result = c4d.gui.ShowPopupDialog(cd=None, bc=menu, x=c4d.MOUSEPOS, y=c4d.MOUSEPOS)
doc.EndUndo()
world_container.RemoveData(plugin_ID_loader)
print("Finished")
return True
if __name__ == "__main__":
c4d.plugins.RegisterMessagePlugin(id=plugin_ID,
str="AO Message",
info=0,
dat=AOMessage())
It works perfectly in R19, so I'm not sure what changed since then.
Apologies if this as been asked before.
Thank you very much for your help in advance!
Andre