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
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. eZioPan
    • Profile
    • Following 0
    • Followers 0
    • Topics 6
    • Posts 30
    • Best 5
    • Controversial 0
    • Groups 0

    eZioPan

    @eZioPan

    12
    Reputation
    208
    Profile views
    30
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    eZioPan Unfollow Follow

    Best posts made by eZioPan

    • RE: Example Python Code "Add a Custom User Data": Not Working

      Hi @bentraje,

      Here is the code that can do:

      import c4d
      
      def AddLongDataType(obj):
          if obj is None: return
      
          bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG) # Create default container
          bc[c4d.DESC_NAME] = "Test" # Rename the entry
      
          element = obj.AddUserData(bc) # Add userdata container
          obj[element] = 30 # Assign a value
          c4d.EventAdd() # Update
      
      def main():
          obj = doc.GetActiveObject()    # Here you get selected/active object from scene
          AddLongDataType(obj)           # Call the AddLongDataType function to add user data to selected object
      
      if __name__=='__main__':           # The "actual" place that code start to execute 
          main()                         # Call "main" function, start the processing
      
      
      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • RE: n-gones with python

      hi @passion3d,
      There is no actual n-gon in the underlying layer of Cinema 4D.
      Adjacent polygons use hidden edge to create n-gon-like shape(s).

      Following code creates a 5-side polygon object:

      import c4d, math
      from c4d import utils
      #Welcome to the world of Python
      
      def main():
          pointCount = 5
          polygonCount = math.ceil(pointCount/4.0)                    # caculate minimum needed polygon number
          polyObj = c4d.BaseObject(c4d.Opolygon)                      # create an empty polygon object
      
          polyObj.ResizeObject(pcnt=pointCount, vcnt=polygonCount)    # resize object to have 5 points, 2 polygons
      
          # manually set all point position
          polyObj.SetPoint(id=0, pos=c4d.Vector(200,0,-200))
          polyObj.SetPoint(id=1, pos=c4d.Vector(-200,0,-200))
          polyObj.SetPoint(id=2, pos=c4d.Vector(-200,0,200))
          polyObj.SetPoint(id=3, pos=c4d.Vector(200,0,200))
          polyObj.SetPoint(id=4, pos=c4d.Vector(300,0,0))
      
          # associate points into polygons
          polygon0 = c4d.CPolygon(t_a=0, t_b=1, t_c=2, t_d=3)
          polygon1 = c4d.CPolygon(t_a=0, t_b=3, t_c=4)
      
          # set polygon in polygon object
          polyObj.SetPolygon(id=0, polygon=polygon0)
          polyObj.SetPolygon(id=1, polygon=polygon1)
      
          # set hidden edge
          nbr = utils.Neighbor()
          nbr.Init(op=polyObj, bs=None)                               # create Neighor counting all polygon in
          edge = c4d.BaseSelect()
          edge.Select(num=3)                                          # set selection, which is the id of the edge to be hidden
          polyObj.SetSelectedEdges(e=nbr, pSel=edge, ltype=c4d.EDGESELECTIONTYPE_HIDDEN)  # hide the edge
      
          polyObj.Message(c4d.MSG_UPDATE)
      
          doc.InsertObject(polyObj)
      
          c4d.EventAdd()
      
      if __name__=='__main__':
          main()
      
      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • RE: getting 3D noise values

      Hi @ruckzuck ,

      Please check this document:

      c4d.utils.noise.C4DNoise

      Here is a sample code:

      import c4d
      from c4d import utils
      #Welcome to the world of Python
      
      def main():
          
          pos = c4d.Vector(0,0,0) # Here is the input
          
          seed = 12346
          
          noiseGen = utils.noise.C4DNoise(seed)
          result = noiseGen.Noise(t=c4d.NOISE_NOISE,two_d=False,p=pos) # Here is the result
          
          print(result)
      

      You can then remap result float number into a color using other methods.

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • RE: Creating a Circle (spline) with varying number of points.

      Hi @pim,
      As far as I know, there is no way to make a "perfect circle" with any type of spline in Cinema 4D.
      I search on the Internet, based on this answer: How to create circle with Bézier curves?.
      I write the following code to create a circular-like spline shape:

      import c4d, math
      #Welcome to the world of Python
      
      deg = math.pi/180.0
      
      def main():
          pCnt = 4             # Here is the point count
          radius = 200         # Here is the radius of circle
          subdAngle = 5*deg    # Here is the subdivision angle
      
          #Prepare the data
          tangentLength = (4/3)*math.tan(math.pi/(2*pCnt))*radius # single side tangent handle length
          pointPosLs = []
          tangentLs = []
          for i in range(0,pCnt):
      
              angle = i*(2*math.pi)/pCnt    # caculate the angle
      
              # caculate point position
              y = math.sin(angle)*radius
              x = math.cos(angle)*radius
              pointPosLs.append(c4d.Vector(x, y, 0))
      
              # tangent position
              lx = math.sin(angle)*tangentLength
              ly = -math.cos(angle)*tangentLength
              rx = -lx
              ry = -ly
              vl = c4d.Vector(lx, ly, 0)
              vr = c4d.Vector(rx, ry, 0)
              tangentLs.append([vl, vr])
      
          # init a bezier circle
          circle = c4d.SplineObject(pcnt=pCnt, type=c4d.SPLINETYPE_BEZIER)
          circle.ResizeObject(pcnt=pCnt, scnt=1)
          circle.SetSegment(id=0, cnt=pCnt, closed=True)
          circle[c4d.SPLINEOBJECT_CLOSED] = True
          circle[c4d.SPLINEOBJECT_ANGLE] = subdAngle
          
          circle.SetAllPoints(pointPosLs) # set point position
      
          # set tangent position
          for i in range(0, pCnt):
              circle.SetTangent(i, tangentLs[i][0], tangentLs[i][1])
      
          circle.Message(c4d.MSG_UPDATE)
      
          return circle
      

      You can try put this code in a Python Generator object to get the result.

      I'm not very sure about my answer, waiting for more convincing answers.

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • RE: Pointcount from bevel deformer

      Hi @bonsak,
      Try use op.GetObject().GetDeformCache().GetPointCount() in a Python Tag on the Polygon Object.
      Here you can get more information: GetDeformCache().

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan

    Latest posts made by eZioPan

    • RE: How to add Button User Data with a Button GUI in python script?

      It works like a charm!

      Thanks a lot!

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • How to add Button User Data with a Button GUI in python script?

      Hi,

      How can I add a button to an object with python?

      I'm trying to add a button to a Null Object, but only get a button userdata without button itself. Here is the code:

      import c4d
      
      def main():
          null_object = c4d.BaseObject(c4d.Onull)
      
          ud_btn_bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BUTTON)
          ud_btn_bc.SetString(c4d.DESC_NAME, "Click")
          ud_btn_bc.SetString(c4d.DESC_SHORT_NAME, "click")
          null_object.AddUserData(ud_btn_bc)
      
          doc.InsertObject(null_object)
       
          c4d.EventAdd()
      
      if __name__ == "__main__":
          main()
      
      

      It seems that creating a button user data from GUI is different from Python. But I don't know how to do it correctly in Python.

      Thanks!

      posted in Cinema 4D SDK s24 python
      eZioPanE
      eZioPan
    • RE: Get and Set Move Tool's XYZ Axis Lock State

      Thank you @ferdinand for the detailed answer and code.
      I will do more reading in the sdk document.

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • RE: Get and Set Move Tool's XYZ Axis Lock State

      Thanks again @cairyn!
      I will use the method your introduced, and keep this topic open, hoping someone could make this more clearly.

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • RE: Get and Set Move Tool's XYZ Axis Lock State

      Thanks @cairyn! When i read c4d.IsCommandChecked(id), it says Forbidden to call in expressions (Python generator, tag, XPresso node, etc.). Is it safe to use this in a Interaction Tag?

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • Get and Set Move Tool's XYZ Axis Lock State

      Hi,

      How can I get and set Move Tool's XYZ Axis Lock state? when I click the buttons, the Script Log display as:

      c4d.CallCommand(12153) # X-Axis / Pitch
      c4d.CallCommand(12154) # Y-Axis / Heading
      c4d.CallCommand(12155) # Z-Axis / Bank
      

      axis lock.png

      I append an Interaction Tag on a object, when I select this object, I want it automaticly change to Move Tool and lock the Y axis and Z axis,
      when I deselect the object, it restore the original axis lock state, then change back to last active tool.

      Here is the code I put in the tag:

      import c4d
      from c4d import gui
      
      def onSelect():
          #Code for what happens when the object gets selected goes here
          global last_tool
          last_tool = doc.GetAction() # store the active tool
          
          c4d.CallCommand(c4d.ID_MODELING_MOVE) # change to Move Tool
          gui.ActiveObjectManager_SetObject( # change Attribute Manager to Object Mode
              c4d.ACTIVEOBJECTMODE_OBJECT, op, c4d.ACTIVEOBJECTMANAGER_SETOBJECTS_OPEN)
      
          # TODO: Get Move Tool current axis lock state, then change the state
      
      def onDeselect():
          #Code for what happens when the object gets unselected goes here
      
          # TODO: Restore Move Tool's last axis lock state
      
          doc.SetAction(last_tool) # restore the last active tool
      
      #def onHighlight():
          #Code for what happens when the object gets highlighted goes here
      
      #def onUnhighlight():
          #Code for what happens when the object gets unhighlighted goes here
      

      by the way, what is the difference between "onSelect" and "onHighlight"?

      Thanks!

      posted in Cinema 4D SDK python
      eZioPanE
      eZioPan
    • RE: How to get spline offset by spline point index ?

      @s_bach thank you for your answer! I think I have the same question as mike do, so it has been solved now. Thank you again!

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • RE: [XPresso] How to add numeric data from an In-/Exclusion Userdata?

      Hi, @m_adam

      Thank you for your kindness and the inspiring answer! It's a GREAT Christmas present for me!

      So sorry asking XPresso related questions in this forum.
      The problem I faced is a little bit complex than this: I need sample Effectors' total Output Strengths in the position from a Polygon Object's Points, and store the result into a Vertex Color Map attached for further use.
      This problem bothers me for months, and I didn't find any clue until your post. I have never think about using Python Node with global variable in XPresso Network can keep the data as I need and do the magic!

      From the bottom of my heart, I want to say THANK YOU.
      The answer you give not only solve this problem, but also inspire me re-thinking of ObjectList Node and Python Node, and how these nodes executed in an XPresso Network.

      Just let me THANK YOU AGAIN!

      Best wishes for you to have a wonderful holiday!

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan
    • [XPresso] How to add numeric data from an In-/Exclusion Userdata?

      Hi,

      I have a Null Object with an In-/Exclusion Userdata attached. In In-/Exclusion Userdata some Mograph Effector have been added. I want to use Sample Node to get all Strength of Mograph Effector, then add output Strength together. How can I do?

      Here is the snapshot of the scene.

      0_1545379610503_ss.jpg

      The problem I meet is that I can't use Python to sample the output of a Mograph Effector(Sample Node With Python), and I haven't found a way to cumulate output of an Object List Node.

      Thanks!

      posted in Cinema 4D SDK python r19
      eZioPanE
      eZioPan
    • RE: How to get spline offset by spline point index ?

      Hi @r_gigante,
      Thank you for replying. I'd like to know more about this topic: if I only know the Control Point Index from PointObject.GetPoint(id) of a spline, how could I get the Spline Position of this point?

      posted in Cinema 4D SDK
      eZioPanE
      eZioPan