Navigation

    • Register
    • Login
    • Search
    • Categories
    1. Home
    2. eZioPan
    3. Best
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    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 Development
      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 Development
      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 Development
      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 Development
      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 Development
      eZioPan