Python Objekte X Y Z
-
Hallo bin neu bei Python meine Frage ist es wie kann ich Objekte in einer Zeichnung dazu bringen sie in X Wert Y Wert Z Wert nach meinen Bedürfnissen auszurichten hat jemeand ein Script dazu?
Dankeschön!
-
Hallo @wdp,
willkommen im Plugin Café und in der Cinema 4D Development Community! Please note that we require all topics to be discussed in the English language only so that all developers can read and understand them. There are also other rules as tagging described in our Forum Guidelines. I took the liberty of translating your question and also adding the required tags.
Hello, I am new to Python [in Cinema 4D] and I have a question: How can I align objects with a tuple of (x, y, z) values in a drawing [document]? Can someone provide a script for that? Thank you!
Your question is also a bit too broad to be answered by the SDK-Team in all detail (you might get community help though). We have the Script Section of our GitHub Repository which does go over some fundamental stuff. There is also the Python API Documenation for technical information.
About your specific question: You do not specify exactly how the objects to align are meant to be determined and how the x, y, and z values should be entered. There is a broad range of complexity of what could be done here, find a very simple script at the end of this posting to get you started.
Cheers,
FerdinandThe result:
The code:"""Simple script to set the position of the selected objects. A script to be run in the Script Manger (Shift + F11). Will set all selected objects to a fixed position in global space. To have more complex inputs you should look at GeDialog examples or consider writing a ToolData plugin. """ import c4d def main(): """ """ # doc is a predefined module attribute ("variable") in a Script Manager # context pointing to the active document and equivalent to # c4d.documents.GetActiveDocument(). # Get the selected objects in the active document. selected = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) # The fixed global position all objects should be set to. pos = c4d.Vector(100, 200, 300) # Iterate over all selected objects and set the global position of each. for obj in selected: # Get the global matrix of the object, set its offset and write it back. mg = obj.GetMg() mg.off = pos obj.SetMg(mg) # Push and update event to Cinema 4D. c4d.EventAdd() if __name__ == '__main__': main()
-
Thank you very much!
-
Hello I have a problem and would like to include the two commands from the console in my script
object () [c4d.ID_BASEOBJECT_USECOLOR] = 1
c4d.ID_BASEOBJECT_COLORhow do I call to die that would be nice if someone could help me.
Thanks very much!
-
And how can I include an icon for the command bar then I would have done it.
Thank you very much!
-
Hello @WDP,
as a quick heads up: We ask users to open a new topic for each new question, so that things remain nicely organized (as mentioned in our Forum Guidelines). You can ask follow-up questions in a topic if they are related to the original question. This is here not the case, but for the first topic we can give a bit of rope But please make sure to follow this rule in the future, as we otherwise will simply split the topic which often does make them not very readble.
About your questions:
object () [c4d.ID_BASEOBJECT_USECOLOR] = 1
c4d.ID_BASEOBJECT_COLORobject ()
is the bit weird way how the script log gets hold of the active object. It is just a function which callsGetActiveObject
and returns theBaseObject
.def object(): return doc.GetActiveObject()
The script log does this for every action, which is inefficient when writing code manually. In manually written code we can just store the active object and then do multiple things with that object, since we know that the active object cannot change in between.
myObject = doc.GetActiveObject() if myObject is None: return myObject[c4d.ID_BASEOBJECT_USECOLOR] = c4d.ID_BASEOBJECT_USECOLOR_ALWAYS myObjectCube[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(1, 0, 0)
The loop
for obj in selected
in the code snippet shown above also iterates over suchBaseObject
. So, you could change the loop as follows:# Iterate over all selected objects and set the global position of each. for obj in selected: # Get the global matrix of the object, set its offset and write it back. mg = obj.GetMg() mg.off = pos obj.SetMg(mg) obj[c4d.ID_BASEOBJECT_USECOLOR] = c4d.ID_BASEOBJECT_USECOLOR_ALWAYS obj[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(1, 0, 0)
To also give all selected objects a red shading (or change any other parameter of them).
And how can I include an icon for the command bar then I would have done it.
The easiest way to do this, is to simply render one. But there are also other ways, please see the User Manual for details or contact customer support (we can only provide development support here).
Cheers,
Ferdinand -
Thank you very much!
-
This post is deleted!