PlugIn/Scripting Beginners Questions
-
On 28/08/2017 at 04:58, xxxxxxxx wrote:
Hey everyone,
I'm quite new to scripting in Cinema as well as scripting in general. The last two months I wrote my first 3 PlugIns and even though these work as expected, during that process I ended up with quite some questions, which I'd like to find answers to.
Since I couldn't find any forum rules regarding topics, I'll put all my questions in that one topic. However I'll name every section/question, so that one can find that thread via searching.
I'd be thankfull for some help.
To my actual questions:
1. How do you add a PlugIn to a self-created submenu?
So as you can see I have a submenu example which works just fine. However when trying to add a "PlugIn" to it I don't get the result I'd like to have.
def GetSubContainer(self, doc, submenu) :
[...]
sub2 = c4d.BaseContainer() #a submenu in a submenu
sub2[1] = "Another submenu"
sub2.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_5159")
sub2[subsubmenu_2] = "Sub_SubMenu II"
sub2[subsubmenu_3] = "Sub_SubMenu III"
sub2[subsubmenu_4] = "Disabled&d&"
[...]def ExecuteSubID(self, doc, id) :
[...]
elif id == subsubmenu_2:
gui.MessageDialog("You clicked on 'Sub_Submenu II'")
elif id == subsubmenu_3:
gui.MessageDialog("You clicked on 'Sub_Submenu III'")
[...]I'm obviously doing something wrong. I guess I can't just use InsData() to add a PlugIn to the menu, but how would you do that?
I guess I could add the submenu to the plugins and use ExecuteSubID() to execute it, but that doesn't seem like how it's meant to work.2. How to access an object after using TransferGoal()?
I'm using that function to copy the information of where an object(A) is linked (e.g. in an Instance) to another object(B). Once I did that I'd like to delete that object(A).
The references however that I use to access that object(A), while the program is running are getting transferred as well. That means, that I'm unable to delete it after using
TransferGoal(). So I used the following code to do what I tried to achieve, but there has to be a better solution than that.splines[k].SetName("ßashd0ø9873hß09d8ahs0ßfå7h0ø87ahdg87ha8sdhf90q403q8fußa9æ8dghåß9uhd")
splines[k].TransferGoal(new_spline, False)
doc.SearchObject("ßashd0ø9873hß09d8ahs0ßfå7h0ø87ahdg87ha8sdhf90q403q8fußa9æ8dghåß9uhd").Remove()3. Is there any way to access the Coordinate Manager?
I'm trying to get the "Size" value which basically gives the vector for the bounding box of anything selected (points as well as objects). If that's not possible, is there any way to get that information?
4. Is it possible to create an object using Python so that attributes are linked to a "parent object"?
I'm basically trying to do what you see in the picture, but with Python. Is there any way to create the "Compositing_Child" with Python in a way so that parts of its attributes are permanently linked to the parent?
So when I change these attributes of the parent the attributes of the child change as well.5. Is it possible to get every change made in the object manager?
The answer to that question might be beyond me, since I haven't tried to use events yet.
Basically I'd like to know, if there is a way to get the information if any object in the object manager is being modified and if so, which object is being modified and how it's being modified.Thanks in advance!
-
On 29/08/2017 at 08:50, xxxxxxxx wrote:
Hi and welcome to the Plugin Cafe forums!
We prefer one topic for each question so that these can be investigated and answered separately.
Originally posted by xxxxxxxx
1. How do you add a PlugIn to a self-created submenu?
You can simply do it this way:
sub2.InsData(5159, "CMD") # Add "Cube" command to the submenu
Pass the plugin/command ID first then "CMD". This information will be added to the Python SDK docs.
Originally posted by xxxxxxxx
2. How to access an object after using TransferGoal()?
The behavior you describe is a limitation of the Python API implementation.
Originally posted by xxxxxxxx
3. Is there any way to access the Coordinate Manager?
I'm afraid the information in the Coordinate Manager can't be accessed.
Originally posted by xxxxxxxx
4. Is it possible to create an object using Python so that attributes are linked to a "parent object"?
The following script creates an object node for a parent cube and for a child cube. Then in/output ports are created and connected for the size/length attribute. (Note the code only works in R18.057, GvNode.OperatorSetData() was added in such version)
import c4d def main() : if op is None: return child = op.GetDown() if child is None: return xpresso = op.GetTag(c4d.Texpresso, 0) if xpresso is None: return master = xpresso.GetNodeMaster() if master is None: return nodeFrom = master.CreateNode(master.GetRoot(), c4d.ID_OPERATOR_OBJECT, insert=None, x=-100, y=0) nodeTo = master.CreateNode(master.GetRoot(), c4d.ID_OPERATOR_OBJECT, insert=None, x=100, y=0) nodeFrom.OperatorSetData(c4d.GV_ATOM, op, c4d.GV_OP_DROP_IN_BODY) outPort = nodeFrom.AddPort(c4d.GV_PORT_OUTPUT, c4d.DescID(c4d.DescLevel(c4d.PRIM_CUBE_LEN, c4d.DTYPE_VECTOR, 0))) nodeTo.OperatorSetData(c4d.GV_ATOM, child, c4d.GV_OP_DROP_IN_BODY) inPort = nodeTo.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.PRIM_CUBE_LEN, c4d.DTYPE_VECTOR, 0))) outPort.Connect(inPort) c4d.EventAdd() if __name__=='__main__': main()
Originally posted by xxxxxxxx
5. Is it possible to get every change made in the object manager?
It's possible to be notified if any change happened but no information on the change is given. The checks to know what has been changed have to be done manually.
-
On 30/08/2017 at 06:45, xxxxxxxx wrote:
Hey Yannick,
thanks for answering all questions straight away. That helped me a lot!
Originally posted by xxxxxxxx
We prefer one topic for each question so that these can be investigated and answered separately.
I'll keep that in mind.
-
On 30/08/2017 at 09:00, xxxxxxxx wrote:
You're welcome!
Don't hesitate to ask questions or doubts you have.