@m_adam
Hi Maxime,
Cinema R21.207 Build RB303831.
Windows 10 1809
I'm calling the SpecialEventAdd
on an SceneLoaderPlugin.
# Import modules
import c4d
plugin_ID = 1055684
class AOLoader(c4d.plugins.SceneLoaderData):
"""
Class for the SceneLoaderData plugin.
"""
def Identify(self, node, name, probe, size):
"""
Identifies if the format of the custom file captured meets the plugins requirements.
:param node: BaseContainer for instance.
:param name: Path and file name of the instance.
:param probe: The data from the instance.
:param size: The data size of the instance.
:return: True if meets object requirements.
"""
file_name = name.lower()
if not file_name.endswith('.ao'):
return False
return True
@staticmethod
def clean_path_str(txt, chr_lst):
"""
This method removes specific characters in a path.
:param txt: The string to replace character.
:param chr_lst: The characters list to be replaced.
:return: Returns the path with removed c characters.
"""
for c in chr_lst:
txt = txt.replace(c, '')
return txt
def read_lines(self, data_file):
"""
Iterates throught the data until finds the line with path for .c4d asset.
:param data_file: The file data returned by Identify method.
:return: The path string, not formatted.
"""
with open(data_file, 'rU') as data:
ds_file = data.read().splitlines()
paths = ""
for line in ds_file:
if ".c4d" in line:
remove_chrs = self.clean_path_str(line, [')', '"'])
paths += remove_chrs.replace("\\\\", "\\")
return paths
def Load(self, node, name, doc, filterflags, error, bt):
"""
Loads the data into the active document. In this case, we do not load or merge the file, but
send a message to CoreMessage when it is catched with a SpecialEventAdd.
The WorldContainer will save the path to be used later.
:param node: BaseContainer for the instance.
:param name: Path and file name of the instance.
:param doc: The active document.
:param filterflags: Flags to filter objects to load.
:param error: Errors brought by Identify Method.
:param bt: The BaseThread for the document.
:return: Returns a c4d.FILEERROR_USERBREAK to capture the message.
"""
paths = self.read_lines(name)
world_container = c4d.GetWorldContainerInstance()
world_container.SetString(plugin_ID, paths)
c4d.SpecialEventAdd(plugin_ID)
return c4d.FILEERROR_USERBREAK
if __name__ == "__main__":
c4d.plugins.RegisterSceneLoaderPlugin(id=plugin_ID,
str="AO Loader",
g=AOLoader,
info=c4d.PLUGINFLAG_SCENELOADER_MERGEORIGINAL,
description="")
It's passing the data correctly, so perhaps the call needs to be done somewhere else?
Thank you in advance!
Andre