ImportSymbols with single file didn't return as expect.
-
Hi community,
I found the mxutils.ImportSymbols can not work with single file. Is this is a bug?
win 11 + 2025.2
Cheers~
DunHouimport c4d from pathlib import Path from mxutils import ImportSymbols from pprint import pp doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. # replace a file path c4d_symbol = r".....c4d_symbols.h" def main() -> None: # the file is true exists print(Path(c4d_symbol).exists()) symbols_A = ImportSymbols(str(c4d_symbol), output=dict) pp(symbols_A) # return {} symbols_B = ImportSymbols(str(Path(c4d_symbol).parent), output=dict) pp(symbols_B) # return a dict with symbols symbols_C = ImportSymbols(str(Path(c4d_symbol).parent)) pp(symbols_C) # return None if __name__ == '__main__': main()
-
Hey @Dunhou,
Thank you for reaching out to us. Sorry for the delay, everything is happening at once here right now and I am rotating on the spot
.
I quickly checked your example, and you are right, some regression happened there. That
symbols_C
returnsNone
is correct, as passing the defaultNone
foroutput
should place the symbols in the enclosing scope of the function call. I.e., when yourc4d_symbol
(which btw can be any header file, not just ac4d_symbols.h
) would containenum blah { BOB_IS_YOUR_UNCLE = 42}
, you should be able to simply writeprint(BOB_IS_YOUR_UNCLE)
and it then printing42
. But that is not working anymore. Andsymbols_A
is also faulty.I will have a look what heck broke there, at first glance it is not obvious to me. I think Maxime touched symbol parsing not too long ago, because the parser missed some symbols in the C++ API (this mechanism is used to auto-expose parts of the C++ API to Python), maybe this broke things, I will have to see.
For now, I would recommend to use the case which is working. I have moved this topic into bugs and hopefully can have a look next week.
Cheers,
FerdinandPS: Your MRD weight thingy is not forgotten, I will hopefully cross that off by the end of the week.
-
F ferdinand moved this topic from Cinema 4D SDK on
-
Hey,
sorry for the long turnaround. So, I had a look at the code, and this works as intended.
path (str) – The path within which header files should be discovered and parsed.
I got a bit confused by your
pathlib
shenanigans. So, the bottom line is that the function I myself wrote (lol), does not support passing a file as an input but only directories. I will add a little check to throw a more verbose error, because now this just silently fails when trying to traverse that path.We could think about adding the option to parse only a file, but that would be up to Maxime, as he owns the symbol parser backend.
Cheers,
Ferdinandedit: In future versions (not the next) this will now fail more verbosely when providing a non-directory path or a path that does not exist.
E:g.:
import c4d from mxutils import ImportSymbols from pprint import pp doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. # replace a file path c4d_symbol = r"/Users/f_hoppe/git/sdk/plugins/doc.python.github/plugins/py-cmd_gui_resources_2024/res/" def main() -> None: symbols_A = ImportSymbols(str(c4d_symbol), output=dict) pp(symbols_A) # return {} symbols_C = ImportSymbols(str(Path(c4d_symbol))) pp(symbols_C) # return None print(ID_PLUGIN) if __name__ == '__main__': main()
{'__DUMMY__': 2006, 'ID_PLUGIN': 1065655, 'IDC_VALUE_A': 2003, 'IDC_VALUE_B': 2005, 'IDD_VALUES': 2000, 'IDS_PLUGIN_HELP': 1001, 'IDS_PLUGIN_NAME': 1000, 'IDS_VALUE_A': 2002, 'IDS_VALUE_B': 2004, 'IDS_VALUES': 2001} {'__DUMMY__': 2006, 'ID_PLUGIN': 1065655, 'IDC_VALUE_A': 2003, 'IDC_VALUE_B': 2005, 'IDD_VALUES': 2000, 'IDS_PLUGIN_HELP': 1001, 'IDS_PLUGIN_NAME': 1000, 'IDS_VALUE_A': 2002, 'IDS_VALUE_B': 2004, 'IDS_VALUES': 2001} None 1065655
-
Hey @ferdinand,
Is there any deficiency in
pathlib
? I just think its writing style is more convenient and it produces less code. Lazy me@ferdinand said in ImportSymbols with single file didn't return as expect.:
does not support passing a file as an input but only directories
I'm a bit confused, does this mean that ImportSymbols only support directories, but the documentation says that files can be passed for parsing, or did I misunderstand again...
Cheers~
DunHou -
You are right, that is a bit odd, either there is regression, or I mixed something up with the code example. In any case, we will either add back singular file support or change the example.
-
FYI: This has been fixed and will be shipped in a future version of Cinema 4D.