• Categories
    • Overview
    • News & Information
    • Cinema 4D SDK Support
    • Cineware SDK Support
    • ZBrush 4D SDK Support
    • Bugs
    • General Talk
  • Unread
  • Recent
  • Tags
  • Users
  • Register
  • Login
Maxon Developers Maxon Developers
  • Documentation
    • Cinema 4D Python API
    • Cinema 4D C++ API
    • Cineware API
    • ZBrush GoZ API
    • Code Examples on Github
  • Forum
  • Downloads
  • Support
    • Support Procedures
    • Registered Developer Program
    • Plugin IDs
    • Contact Us
  • Categories
    • Overview
    • News & Information
    • Cinema 4D SDK Support
    • Cineware SDK Support
    • ZBrush 4D SDK Support
    • Bugs
    • General Talk
  • Unread
  • Recent
  • Tags
  • Users
  • Register
  • Login

Python Objekte X Y Z

Cinema 4D SDK
python r21 windows macos
2
8
957
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W
    WDP
    last edited by ferdinand Nov 4, 2021, 12:28 PM Nov 4, 2021, 11:24 AM

    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!

    F 1 Reply Last reply Nov 4, 2021, 12:26 PM Reply Quote 0
    • F
      ferdinand @WDP
      last edited by ferdinand Nov 4, 2021, 12:31 PM Nov 4, 2021, 12:26 PM

      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,
      Ferdinand

      The result:
      123.gif
      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()
      

      MAXON SDK Specialist
      developers.maxon.net

      1 Reply Last reply Reply Quote 0
      • W
        WDP
        last edited by Nov 4, 2021, 1:08 PM

        Thank you very much!

        1 Reply Last reply Reply Quote 0
        • W
          WDP
          last edited by Nov 5, 2021, 7:04 AM

          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_COLOR

          how do I call to die that would be nice if someone could help me.

          Thanks very much!

          1 Reply Last reply Reply Quote 0
          • W
            WDP
            last edited by Nov 5, 2021, 7:10 AM

            And how can I include an icon for the command bar then I would have done it.

            Thank you very much!

            F 1 Reply Last reply Nov 5, 2021, 11:31 AM Reply Quote 0
            • F
              ferdinand @WDP
              last edited by ferdinand Nov 5, 2021, 11:41 AM Nov 5, 2021, 11:31 AM

              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_COLOR

              object () is the bit weird way how the script log gets hold of the active object. It is just a function which calls GetActiveObject and returns the BaseObject.

              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 such BaseObject. 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).

              456.gif

              Cheers,
              Ferdinand

              MAXON SDK Specialist
              developers.maxon.net

              A 1 Reply Last reply Nov 5, 2021, 8:12 PM Reply Quote 0
              • W
                WDP
                last edited by Nov 5, 2021, 1:36 PM

                Thank you very much!

                1 Reply Last reply Reply Quote 0
                • W
                  WDP
                  last edited by WDP Nov 5, 2021, 2:45 PM Nov 5, 2021, 2:44 PM

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  4 out of 8
                  • First post
                    Last post