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
    • Login
    1. Maxon Developers Forum
    2. delizade
    3. Topics
    • Profile
    • Following 0
    • Followers 0
    • Topics 13
    • Posts 29
    • Best 0
    • Controversial 0
    • Groups 0

    Topics created by delizade

    • delizadeD

      How to Modify the Axis of a Point Object?

      Cinema 4D SDK
      • python • • delizade
      7
      0
      Votes
      7
      Posts
      2.4k
      Views

      ferdinandF

      Hey @delizade,

      The script works for anything that is a c4d.PointObject, i.e., editable polygon and spline objects. But not for generators, e.g., the Cube object or the Circle spline, as you cannot edit their points and therefore have no control over the placement of their "axis" in relation to their vertices.

      When you want to set the transform of any BaseObject, e.g., a PointObject, a generator, or a null object, you must simply set either its local or global matrix. But this will not keep vertices 'in place' as generators and a null object have no vertices one could edit, and the vertices of PointObject instances must be corrected manually to achieve the 'move the axis idea'.

      But you can of course just set the global or local matrix (a.k.a. transform) of a BaseObject. Find an example below. For more detailled information, I would recommend having a look at the Matrix Manual.

      Cheers,
      Ferdinand

      The result, the two cubes are not at the same location because combining two transforms is not commutative, i.e., the order matters. A * B is not always the same as B * A for matrices:
      8392f997-7526-4a6d-b00b-e020d7669c59-image.png

      The code:

      """Demonstrates the basic concept of transformations as realized by Cinema 4D. """ import c4d def main() -> None: """Constructs two transforms and applies them in the global coordinate system to two cube objects. """ # Construct a transform that translates by 500 units on the y-axis and one that rotates by # 45° on the x-axis. move: c4d.Matrix = c4d.utils.MatrixMove(c4d.Vector(0, 500, 0)) rotate: c4d.Matrix = c4d.utils.MatrixRotX(c4d.utils.DegToRad(45)) # Combine both transforms into a singular one by multiplying them. Note that matrix # multiplication, combining transforms, is not commutative. I.e., the order matters opposed # to numbers; move * rotate is not the same as rotate * move. tMoveRotate: c4d.Matrix = move * rotate tRotateMove: c4d.Matrix = rotate * move # Allocate two cube objects. cubeMoveRotate: c4d.BaseObject = c4d.BaseObject(c4d.Ocube) cubeRotateMove: c4d.BaseObject = c4d.BaseObject(c4d.Ocube) if None in (cubeMoveRotate, cubeRotateMove): raise MemoryError("Could not allocate cube object.") # And set their global matrix, i.e., the absolute transform in the global coordinate system. cubeMoveRotate.SetMg(tMoveRotate) cubeRotateMove.SetMg(tRotateMove) # Name both null objects, set their display color, insert them into the active document, and # push an update event. cubeMoveRotate.SetName("Cube: Move -> Rotate") cubeRotateMove.SetName("Cube: Rotate -> Move") cubeMoveRotate[c4d.ID_BASEOBJECT_USECOLOR] = c4d.ID_BASEOBJECT_USECOLOR_ALWAYS cubeRotateMove[c4d.ID_BASEOBJECT_USECOLOR] = c4d.ID_BASEOBJECT_USECOLOR_ALWAYS cubeMoveRotate[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(1, 0, 0) cubeRotateMove[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(0, 0, 1) doc.InsertObject(cubeMoveRotate) doc.InsertObject(cubeRotateMove) c4d.EventAdd() if __name__ == '__main__': main()
    • delizadeD

      "Render Marked Takes" Command via Python?

      General Talk
      • python s26 • • delizade
      3
      0
      Votes
      3
      Posts
      629
      Views

      delizadeD

      Hi Manuel,
      Thank you for your help.

    • delizadeD

      How can I make a simple input form for my Python script?

      Cinema 4D SDK
      • • • delizade
      3
      0
      Votes
      3
      Posts
      993
      Views

      ferdinandF

      Hello @delizade,

      thank you for reaching out to us. I am a bit confused when you say:

      I'm new about Python and Cinema 4D scripting.

      You have more than 20 postings in your account, asking Python questions which I would hardly classify as being new? Nonetheless, windows or 'input forms' are called dialogs in Cinema 4D and represented by the type c4d.gui.GeDialog. There is also another form of GUI definitions called descriptions, but they are tied to classic API nodes, e.g., a Cube object or a Noise shader. Dialogs can be modal and non-modal. In a 'Script [Manager script]' you are bound to modal dialogs, i.e., the user can only interact with the dialog until the dialog has been closed.

      We also have a series of GeDialog related example scripts on GitHub. I also provided a small example which probably does some things you want to do.

      Cheers,
      Ferdinand

      The result:
      simple_dialog.gif

      The code:

      """Simple example for a custom dialog in Cinema 4D. The example will contain a file selection element and a button, as well as a multiline text box. Pressing the button will load the content of a selected file into the text box. Windows are represented by the class c4d.gui.GeDialog in Cinema 4D. There are two ways to define dialogs, programmatically, as shown here, or with the help of something which is called a resource file. Resource files work similarly to other GUI markups, as for example XAML for C# or QT-XML for QT. The dialog raised here is modal, i.e., the user must focus on the dialog. For async, i.e., non-modal dialogs you must write a plugin and cannot use a script (there are ways to wiggle around that restriction, but it is not recommended to do that.) For more information, see the Python and C++ documentation of Cinema 4D on dialogs and dialog ressources. """ import c4d import os class MyDialog(c4d.gui.GeDialog): """Defines a dialog. """ ID_TEXT = 1000 ID_CHECKBOX = 1001 ID_FILENAME = 1002 ID_MULTILINE = 1003 ID_BUTTON = 1004 ID_GROUP = 10000 def CreateLayout(self) -> bool: """Called by Cinema 4D to populate the dialog with gadgets. """ # Set the title of the dialog. self.SetTitle("My Dialog") # Open a container to put other elements into. self.GroupBegin(id=MyDialog.ID_GROUP, flags=c4d.BFH_SCALEFIT, cols=1) self.GroupSpace(spacex=5, spacey=5) # Add a text box and a check box. self.AddEditText(id=MyDialog.ID_TEXT, flags=c4d.BFH_SCALEFIT) self.AddCheckbox(id=MyDialog.ID_CHECKBOX, flags=c4d.BFH_SCALEFIT, initw=0, inith=0, name="Check") # A Filename, i.e., an interface to select a file is a bit more fringe and must be added # over its custom GUI. self.AddCustomGui(id=MyDialog.ID_FILENAME, pluginid=c4d.CUSTOMGUI_FILENAME, name="Path", flags=c4d.BFH_SCALEFIT, minw=0, minh=0, customdata=c4d.BaseContainer()) # Add text box spanning multiple lines (that is set to read only mode). self.AddMultiLineEditText(id=MyDialog.ID_MULTILINE, flags=c4d.BFH_SCALEFIT, inith=50, style=c4d.DR_MULTILINE_READONLY) # Add a button. self.AddButton(id=MyDialog.ID_BUTTON, flags=c4d.BFH_SCALEFIT, name="Run") # Close the lyaout group. self.GroupEnd() return super().CreateLayout() def InitValues(self) -> bool: """Called by Cinema 4D to initialize a layout. """ self.SetString(MyDialog.ID_TEXT, "Hello World!") self.SetBool(MyDialog.ID_CHECKBOX, True) self.SetFilename(MyDialog.ID_FILENAME, "") self.SetString(MyDialog.ID_MULTILINE, "") return super().InitValues() @staticmethod def ReadFile(filename: str) -> str: """Custom static function to read the content of a file into a string. """ if not os.path.exists(filename): raise OSError("Could not access file.") try: with open(filename, mode="rt") as f: return f.read() except Exception as e: raise OSError(f"Could not read access file {filename}.") def Command(self, mid: int, msg: c4d.BaseContainer) -> bool: """Called by Cinema 4D when the user interacts with one of the gadgets in the dialog. """ # The "Run" button has been pressed. if mid == MyDialog.ID_BUTTON: # Read the content of the file if it has been selected and put it into the multiline # text box, otherwise open an error dialog. filename = self.GetFilename(MyDialog.ID_FILENAME) if filename: self.SetString(MyDialog.ID_MULTILINE, MyDialog.ReadFile(filename)) else: c4d.gui.MessageDialog("Please select a file first.") return super().Command(mid, msg) def main(): """Opens the dialog. """ # Instantiate the dialog. dialog = MyDialog() # Open the dialog in modal mode, i.e., it will be the only thing the user can focus on. dialog.Open(dlgtype=c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=400, xpos=-2, ypos=-2) if __name__=='__main__': main()
    • delizadeD

      How can I get a Layer's objects with Python?

      Cinema 4D SDK
      • • • delizade
      4
      0
      Votes
      4
      Posts
      901
      Views

      ferdinandF

      Hello @delizade,

      we will set this topic to 'Solved' when there are no further questions or replies until Monday, November the 22th.

      Thank you for your understanding,
      Ferdinand

    • delizadeD

      Content Browser modifications via Python?

      General Talk
      • • • delizade
      2
      0
      Votes
      2
      Posts
      431
      Views

      ManuelM

      Hi,

      1- you can't with python. (I'm not even sure you can with c++)
      2 - I'm not sure to fully following you. I don't understand the "render preview image" is that a command? In the preferences there is a "Render scene" option. That's maybe the version I'm using. (R24)

      To fix the texture path in your material presets, you would need to set the preview with a file save on your harddrive. But this is not possible with Python.

      Cheers,
      Manuel

    • delizadeD

      How to make a GUI for getting user inputs for my python script?

      General Talk
      • • • delizade
      5
      0
      Votes
      5
      Posts
      922
      Views

      ferdinandF

      Hello @delizade,

      without further questions or replies, we will consider this topic as solved by Monday, the 30th and flag it accordingly.

      Thank you for your understanding,
      Ferdinand

    • delizadeD

      A GetClone problem about takes

      General Talk
      • • • delizade
      5
      0
      Votes
      5
      Posts
      818
      Views

      ferdinandF

      Hi @delizade,

      without further questions or feedback, we will consider this thread as solved by Monday and flag it accordingly.

      Cheers,
      Ferdinand

    • delizadeD

      A problem about getting an object width value with python

      Cinema 4D SDK
      • r23 python • • delizade
      7
      0
      Votes
      7
      Posts
      1.0k
      Views

      ferdinandF

      Hi @delizade,

      Thanks @a_block for helping out! @delizade you can find the description for the priority options in the Python Tag section of the user manual.

      Cheers,
      Ferdinand

    • delizadeD

      User data and take overriding issue

      Cinema 4D SDK
      • r23 • • delizade
      3
      0
      Votes
      3
      Posts
      465
      Views

      ferdinandF

      Hi,

      without further feedback, we will consider this thread as solved by Monday and flag it accordingly.

      Cheers,
      Ferdinand

    • delizadeD

      How to use/import another script file in Python tag correctly?

      Cinema 4D SDK
      • python • • delizade
      7
      0
      Votes
      7
      Posts
      1.2k
      Views

      ferdinandF

      Hi,

      without further feedback, we will consider this thread as solved by Monday and flag it accordingly.

      Cheers,
      Ferdinand

    • delizadeD

      How can I control a Python Tag's execution?

      Cinema 4D SDK
      • python • • delizade
      4
      0
      Votes
      4
      Posts
      516
      Views

      ferdinandF

      Hi,

      without further feedback, we will consider this thread as solved by Monday and flag it accordingly.

      Cheers,
      Ferdinand

    • delizadeD

      "Current Take" doesn't override layer processes that made by scripting

      Cinema 4D SDK
      • python • • delizade
      3
      0
      Votes
      3
      Posts
      563
      Views

      delizadeD

      thank you for your help.