Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
You cannot assign shortcuts to buttons. An alternative solution (which I have used in the past) is to create a CommandData plugin for each button, and let the CommandData::Execute call the button. Or instead of a CommandData plugin you could also create a separate script for each button. Either way, these can then be assigned a shortcut.
CommandData::Execute
If I remember correctly we did discuss the other way (from CommandData to ToolData) quite a while ago (see https://plugincafe.maxon.net/topic/10044/13513_using-objectmessage). But I guess using this same technique could still be applicable to your current request.
Most important is to understand that a CoreMessage is not captured by a ToolData. This type of message can only be captured by a MessageData plugin, where you then could "translate" it into a message that actually is sent to the ToolData.
What I have been successful in using is, performing following from the "transmitter":
BasePlugin* tool = FindPlugin(TOOL_PLUGIN_ID, PLUGINTYPE::TOOL); if (tool) tool->Message(TOOL_MSG_PREPAREDATA);
Where TOOL_PLUGIN_ID is the plugin ID of the ToolData, and TOOL_MSG_PREPAREDATA is a custom defined message, using a unique plugin ID.
And then using following in the "receiver" ToolData:
Bool MyToolData::Message(BaseDocument *doc, BaseContainer &data, Int32 type, void *t_data) { if (type == TOOL_MSG_PREPAREDATA) { PrepareData(); } return DescriptionToolData::Message(doc, data, type, t_data); }
@bentraje said in Bug on GetActiveObjects() on R20.057?:
objSel = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER) print objSel[0] print objSel[1]
Works fine by me.
I have a cube and a plane primitive. With the two selected, I get a printout for both. No out of range. Running 20.057 (on Windows).
<c4d.BaseObject object called 'Plane/Plane' with ID 5168 at 0x0000004C44847570> <c4d.BaseObject object called 'Cube/Cube' with ID 5159 at 0x0000004C448476D0>
When I only select a single object then I get an out of range (obviously):
IndexError: list index out of range
EDIT: Hang on, when I make one the child of the other and have both selected, I do get an out of range. But this is obvious, since your active objects flag doesn't mention children. As such, you do only have a single parent object selected.
To take children into account as being detected as selected, you need:
objSel = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER | c4d.GETACTIVEOBJECTFLAGS_CHILDREN )
spam frenzy all over again, lately.
I have been in need of something similar as well. And if I remember correctly it has been discussed a few years ago. Reason is that a ToolData or DescriptionToolData might need to initialize some stuff depending the currently active object. When the user selects a different object in the ObjectManager, the ToolData might need to reinitialize some stuff.
The solution proposed in the past was to use a MessageData and listen to EVMSG_CHANGE to check if a different object has been selected using the object's "unique" id and then trigger the ToolData by sending a SpecialEvent ... or something.
It is quite a complex implementation that seems to work, but probably is very error prone. I wish we would have had some kind of message telling the active object selection was changed (from inside the ToolData), not via-via. And definitely not using such a hacky and complex solution. It has been a while, but I seem to remember that the whole use of the object's unique id was rather flawed as the id didn't exactly seem to be that unique after all.
Anyway, I am still hoping for a nice solution to detect when user changes the current active object. But it seems to not be possible after all.
I am less active since a few months, and this will probably not change any time soon, but let that not restrict me for sending Best Wishes for 2021 to everyone of the SDK team. Not only to those more present and visible in the forums, but also to those behind the scenes that keep everything running.
Thank you for your 2020 support and best wishes for 2021.
You need to obtain the tool's data in order to be able to modify/set it. The callcommand just activates the tool.
import c4d def main(): # activate the command c4d.CallCommand(1019952) # change its settings nTool = c4d.plugins.GetToolData(doc, 1019952) nTool[c4d.ID_CA_JOINT_NAMING_REPLACE] = "_L_" nTool[c4d.ID_CA_JOINT_NAMING_REPLACE_WITH] = "_R_" # Execute main() if __name__=='__main__': main()
In the above code "nTool" is a BaseContainer, that won't work.
I also found the following in the legacy forum
import c4d def main(): toolID = 1019952 c4d.CallCommand(toolID) tool=c4d.plugins.FindPlugin(toolID, c4d.PLUGINTYPE_TOOL) tool[c4d.ID_CA_JOINT_NAMING_REPLACE] = "_L_" tool[c4d.ID_CA_JOINT_NAMING_REPLACE_WITH]= "_R_" c4d.CallButton(tool, c4d.ID_CA_JOINT_NAMING_REPLACE_APPLY) c4d.EventAdd()
Another take on modifying the settings, since the "tool" returned from FindPlugin is a BasePlugin which is derived from BaseList2D, exactly what we need for the CallButton
FindPlugin
BasePlugin
BaseList2D
CallButton
The geometry of an object is stored in hidden tags (points and polygons, namely) These are not visible, nor selectable ... and thus can theoretically not be deleted by user. But you still can access these via Python, or C++. As such, when removing all tags you also remove critical ones, that are needed by the object in order to exist.
import c4d def main(): c4d.gui.ActiveObjectManager_SetObject(c4d.ACTIVEOBJECTMODE_OBJECT, op, 0, c4d.ACTIVEOBJECTMANAGER_SETOBJECTS_OPEN) if __name__=='__main__': main()
If you want to know from within the TagData-derived object the enable state of the tag you can (with a method receiving a GeListNode* node as argument) do:
BaseTag* tag = (BaseTag*)node; Bool enabled = false; if (tag) { GeData d; tag->GetParameter(<your tag's ENABLE-id>, d, DESCFLAGS_GET::NONE); enabled = d.GetBool(); } ...
If you want to get triggered by the change of state then:
Bool YourTagDataDerivedClass::Message(GeListNode* node, Int32 type, void* data) { if (type == MSG_DESCRIPTION_POSTSETPARAMETER) { DescriptionPostSetValue* postsetval = static_cast<DescriptionPostSetValue*>(data); if (postsetval && (*postsetval->descid == DescID(<your tag's ENABLE-id>))) ... and same as above: you get the state of the enable-parameter
Bool YourTagDataDerivedClass::SetDParameter(GeListNode* node, const DescID& id, const GeData& t_data, DESCFLAGS_SET& flags) { if (!node) return false; const Int32& gadgetID = id[0].id; switch (gadgetID) { case <your tag's ENABLE-id>: enabled = t_data.GetBool();
As far as I know there is no possibility to just "hook into" existing commands of Cinema4D. You will have to provide your own command where you perform the "preliminaries" and then call the existing command. In other words, for your example, you will want to create a 'My Render View' command which perform the tasks you want to see executed before 'Render View' and which after that just calls 'Render View'.
As I won't be spending more time on this project there is no need for delving further into the subject. As such I am setting the status of the topic to "solved".
@ferdinand
I had searched the forums earlier and found quite some references to AddEventNotification used over the years. However, using that technique requires a "host" to be available. In my case I don't see a scenario with a mandatory BaseList2D always available, except for the active document. But still worth a shot ...
AddEventNotification
The reason I was experimenting with the Cinema4D resources was because this is for personal use only (exclusively within R20), and not meant as a plugin to be made public. As such, I would be future-safe, since no further development will be released for R20.
@del The V value of the UVs have switched (since R21 if I am remembering correctly). Originally, the V value was 0 (top) to 1 (bottom), putting the origin of the UVs at the top left. Since R21 the origin has been moved to bottom left, and is also visualized as such in the UV editor, and also in the structure manager. The stored data however, probably for compatibility, has remain untouched and still represents coordinates with origin at top left.
This all means that the stored values and the actual values seen in structure manager are complementary to 1 (the V values are "mirrored") You can see that with the values of point 8.b: its V value in structure manager is 0.889, while its stored value actually is 0.111, where 0.889 is the 1 complement of 0.111 (0.889 + 0.111 = 1) Similarly, the V value of 1 in structure manager is actually stored as 0 ... which you see in the vector representation.
Additionally, the UVs are stored as single precision floats (at least, that was how it was upto R20). I don't know the internals of Python enough, but this might be the reason why you get the strange -1.xxx e-16 value when printed out. Note that printing out the c4d.Vector does show it as 0 (which is the mirrored value of the value 1 in the structure manager.
Hi again, I know this is quite a strange request, but is there a way to detect the press of a tool's description button, outside of the Message() of that tool plugin?
Message()
Let's say I am wanting to add a button to the Modeling Axis tab of the Live Selection tool. For this I edited the toolmodelingaxis.h, .res, .str files. Since I cannot add functionality to the original Modeling Axis tool, I am looking for a way to detect the press of the additional button. Can this be detected via a c4d.plugins.MessageData's CoreMessage() ? Or do I need a C++ SceneHook for this?
An alternative solution would be to implement a CommandData, with dialog containing the button, and dock the dialog somewhere in the layout. But I would prefer to have that button inside of the original tool's description, next to the other attributes.
@m_adam Thanks for the reply. I did mark the post as a question. But didn't see any difference.
I also still don't see any notification, (notification bell remains unchanged), even though there are new notifications when I press the bell icon. Using Firefox (94.0.1 = latest version). No big deal, but it might be related to the failed mark-post-as-question.
I encounter a problem when creating a Python script, and docking that script into the layout. I have simplified the script as much as possible, by simple generating a new script from the Script Manager, and enabled the commented out "def state():" function as such
import c4d from c4d import gui # Welcome to the world of Python # Script state in the menu or the command palette # Return True or c4d.CMD_ENABLED to enable, False or 0 to disable # Alternatively return c4d.CMD_ENABLED|c4d.CMD_VALUE to enable and check/mark def state(): return True # Main function def main(): gui.MessageDialog('Hello World!') # Execute main() if __name__=='__main__': main()
When you save this script, and add the script icon into your layout, then rendering to viewport is broken. Sometimes pressing the "render view" button simply does not react (same with shortcut Ctrl-R), sometimes the command reacts but generates a black render.
Open the script, put the "def state():" function in comment, save, and rendering is reacting as should be.
Haven't tried on other version of Cinema4D, but people have responded that this issue is present in R21 and up (at least on Windows, haven't tried on macOS)
I have tried returning True, False, CMD_ENABLED, CMD_ENABLED | CMD_VALUE ... I even have tried without any return at all. Same result: as soon as "def state():" is present in the script, and script's icon is added to a palette in the layout -> render view is broken
You create a custom GUI to display your custom data by deriving a class from iCustomGUI
class iMyCustomGUI : public iCustomGui ...
Then in you CustomGUIData derived class you implement the allocation by providing the derived iCustomGUI
CDialog* ReferencePointCustomGUI::Alloc(const BaseContainer& settings) { iMyCustomGUI* dlg = NewObjClear(iMyCustomGUI, settings, GetPlugin()); ...
you can find more details in the R20 SDK example customdata_customgui.cpp in folder cinema4dsdk\source\gui Works OK for R16 upto at least R21 (I have not used/tested in more recent versions)
@césar-vonc
Yes you can do this with scripts. I have done this in the past with my Dials plugin.
Let's say you have a CommandData. You simply create a script which does perform c4d.CallCommand(pluginID, option) where <pluginID> is the plugin id of the CommandData, and option is the CallCommand::ExecuteSubID to be executed.
You then assign a shortcut / icon to your script ... and you're done. You can create as many scripts / shortcuts as you want, each with a different <option> value