Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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. pyr
    3. Posts
    P
    • Profile
    • Following 1
    • Followers 0
    • Topics 23
    • Posts 55
    • Best 6
    • Controversial 0
    • Groups 0

    Posts made by pyr

    • RE: save/keep cache of generator plugin

      Could you provide an snipped where you show how to cache it in a plugin?

      posted in Cinema 4D SDK
      P
      pyr
    • RE: How to create a Track on a Vector Userdata?

      Works! Thank you!

      posted in Cinema 4D SDK
      P
      pyr
    • How to create a Track on a Vector Userdata?

      I have a Python Tag that loads on button press a json with some animation data. Position / Rotation working fine but i still haven't figured out how to create a track on a userdata with the type vector. i think i'm missing the desc ids or something like that

      def CreateOrUpdateKey(curve, time, value, interpolation):
          keyDict = curve.FindKey(time)
          if keyDict:
              key = keyDict["key"]
              key.SetValue(curve, value)
              key.SetInterpolation(curve, interpolation)
          else:
              keyDict = curve.AddKey(time)
              if not keyDict:
                  raise MemoryError("Failed to create key")
              key = keyDict["key"]
              index = keyDict["nidx"]
              key.SetValue(curve, value)
              curve.SetKeyDefault(doc, index)
              key.SetInterpolation(curve, interpolation)
      
      def LoadJsonToTracks(obj, path):
          if not os.path.isfile(path):
              raise FileNotFoundError(f"JSON file not found: {path}")
          with open(path, "r") as f:
              rawData = json.load(f)
      
          fps = doc.GetFps()
          interpolation = c4d.CINTERPOLATION_LINEAR
      
          # --- POSITION TRACKS ---
          pos_curves = []
          for axis in [c4d.VECTOR_X, c4d.VECTOR_Y, c4d.VECTOR_Z]:
              descID = c4d.DescID(
                  c4d.DescLevel(c4d.ID_BASEOBJECT_REL_POSITION, c4d.DTYPE_VECTOR, 0),
                  c4d.DescLevel(axis, c4d.DTYPE_REAL, 0)
              )
              track = obj.FindCTrack(descID)
              if not track:
                  track = c4d.CTrack(obj, descID)
                  obj.InsertTrackSorted(track)
              curve = track.GetCurve()
              curve.FlushKeys()
              pos_curves.append(curve)
      
          # --- ROTATION TRACKS ---
          rot_curves = []
          for axis in [c4d.VECTOR_X, c4d.VECTOR_Y, c4d.VECTOR_Z]:
              descID = c4d.DescID(
                  c4d.DescLevel(c4d.ID_BASEOBJECT_REL_ROTATION, c4d.DTYPE_VECTOR, 0),
                  c4d.DescLevel(axis, c4d.DTYPE_REAL, 0)
              )
              track = obj.FindCTrack(descID)
              if not track:
                  track = c4d.CTrack(obj, descID)
                  obj.InsertTrackSorted(track)
              curve = track.GetCurve()
              curve.FlushKeys()
              rot_curves.append(curve)
      
          # --- Add keyframes from JSON ---
          for entry in rawData:
              frame = entry.get("frame")
              pos = entry.get("position", [0, 0, 0])
              rot = entry.get("rotation", [0, 0, 0])
              if frame is None or len(pos) != 3 or len(rot) != 3:
                  continue
      
              time = c4d.BaseTime(frame, fps)
      
              for i in range(3):
                  CreateOrUpdateKey(pos_curves[i], time, pos[i], interpolation)
                  CreateOrUpdateKey(rot_curves[i], time, rot[i], interpolation)
      
      posted in Cinema 4D SDK python
      P
      pyr
    • RE: save/keep cache of generator plugin

      I would also be interested.

      I cache all kinds of things, but not the mesh at the end.

      #         check if any dependency changed
          def CacheCheck(self, op, doc):
      
      
              """
      
              :param op:
              :param doc:
              :return:
              """
      
              if op[res.GRIDDER_CACHE] is not None:
      
                  preOption = op[res.GRIDDER_CACHE].GetString(1001)
                  preNoise = op[res.GRIDDER_CACHE].GetFloat(1002)
                  preField = op[res.GRIDDER_CACHE].GetFloat(1003)
                  preFrame = op[res.GRIDDER_CACHE].GetFloat(1004)
      
                  rd = doc.GetActiveRenderData()
                  self.rs.SetStartFrame(rd[c4d.RDATA_FRAMEFROM].GetFrame(doc.GetFps()))
      
                  force = op[res.GRIDDER_EVERYFRAME]
                  frame = doc.GetTime().GetFrame(doc.GetFps())
                  noise, shaderAnimated = self.CacheShader(op, doc)
      
                  if force is 1 and preFrame != frame:
                      return False
      
                  if preOption != self.HelperGetOptions(op):
                      return False
      
                  if preNoise != noise:
                      return False
      
                  field = self.CacheField(op, doc)
      
                  if preField != field:
                      return False
      
                  return True
      
              return False
      
      #-----------------------------------------------------------------
      # after everything is calculated:
              bc = c4d.BaseContainer()
      
              bc.SetData(1001, self.HelperGetOptions(op))
              bc.SetData(1002, self.CacheShader(op, doc)[0])
              bc.SetData(1003, self.CacheField(op, doc))
      
              if doc != None:
                  bc.SetData(1004, frame)
      
              op[res.GRIDDER_CACHE] = bc
      
      
      posted in Cinema 4D SDK
      P
      pyr
    • RE: How to check if document is rendering?

      Hey sorry for gravedigging.

      i have the problem that my tag plugin recognises the difference between rendering and not rendering. unfortunately it also always changes the state in the doc itself and not only in the doc that is rendered

      grafik.png

      posted in Cinema 4D SDK
      P
      pyr
    • RE: Negative Vertex Map values

      hey,

      found the error. works exactly as i had planned. my code was correct, but i forgot to switch off use fields on the new vertex i mapped.

      thanks for the help anyway!

      grafik.png

      posted in General Talk
      P
      pyr
    • Negative Vertex Map values

      i use a vertext map to manipulate the motion blur in redshift from an object. positive directions are no problem, but the vertext map only seems to store positive values. manipulating it afterwards via python script didn't help either.

      which surprises me in particular because the documentation mentions a float as the data type.

      in other tools it is easily possible to use negative float values to create the desired effect.

      posted in General Talk python r25
      P
      pyr
    • RE: Polygon Islands Convenience Method?

      this script breaks an poly object into island, colorized it by random, offset to center of bounding box and some noise. after that i connects all islands again.

      its super fast compared to my older "solution"

      import c4d
      from c4d import gui
      import random
      
      def AddVertexColor(s,center,rad):
      
          cnt = s.GetPointCount()
          tag = c4d.VariableTag(c4d.Tvertexcolor, cnt)
      
      
          data = tag.GetDataAddressW()
      
          bs = s.GetPointS()
          bs.SelectAll(cnt)
          done = []
      
          points = s.GetAllPoints()
      
      
          r = random.random()
      
      
      
          for i in range(cnt):
      
              g = (points[0]-center).GetLength()    / rad
              b = c4d.utils.noise.Noise(points[0]*0.01,rad)
              c = c4d.Vector(r,g,b)
      
              c4d.VertexColorTag.SetColor(data, None, None, i, c)
      
      
          s.InsertTag(tag)
      
      
      def main():
          random.seed(666)
      
      
          selection  = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_NONE)
          for s in selection:
              center = s.GetMp()
              rad    = s.GetRad().GetLength()
              c4d.CallCommand(12298)
              c4d.CallCommand(17891)
              mesh = s.GetDown()
      
              while mesh:
      
                  AddVertexColor(mesh,center,rad)
                  mesh = mesh.GetNext()
      
              c4d.CallCommand(100004768)
              c4d.CallCommand(16768)
      # Execute main()
      if __name__=='__main__':
          main()
      
      posted in Cinema 4D SDK
      P
      pyr
    • MergeDocument under a selected Null

      Hey,

      i use

      c4d.documents.MergeDocument(doc , f,  c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS | c4d.SCENEFILTER_MERGESCENE)
      
      

      now i would like to group this new scene under a NULL. if i do the whole thing via obj.InsertUnder(null) i miss the materials.
      which is totally logical but unfortunately not what i have in mind.

      So one idea would be to insert the materials separately into the scene by checking the tags. The problem is that I can't be 100% sure that all the materials that are needed will be migrated.

      Another approach would be to check which objects are already in the scene and then simply move the newly loaded ones under the zero.

      So what is the best way to extend the functionality of MergeDocument to be able to specify a null object as root?

      posted in Cinema 4D SDK python
      P
      pyr
    • Encouraging evaluation when a document is opened

      I have several object plugins and they all have the same problem - my custom caching functions work as expected until the document is saved and reopened. In that case the generator object returns an empty object. is there any kind of event I could use to force an update?

      posted in Cinema 4D SDK python
      P
      pyr
    • CENTER AN OBJECT IN THE VIEW AND MAXIMIZE ITS SIZE

      I got a setup with a stationary camera. i need to keep the object centered in my view and maximize its size but i can't change the rotation / position of my camera.

      what i have so far is the following:

      i calculate the center of the objekt and change the offset accordingly to center the object. now if i want to zoom in my offset calculations are wrong again.

      correct.PNG

      fovProblem.c4d

      edit:

      can someone please move the thread into the right subforum?

      posted in Cinema 4D SDK python
      P
      pyr
    • RE: Polygon Islands Convenience Method?

      here is a script i use to color polygon groups. unfortunately a bit slow

      import c4d
      from c4d import gui
      import random
      
      def main():
          random.seed(666)
      
          c4d.CallCommand(12139) # point mode
          selection  = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_NONE)
          for s in selection:
      
              cnt = s.GetPointCount()
              tag = c4d.VariableTag(c4d.Tvertexcolor, cnt)
      
      
              data = tag.GetDataAddressW()
      
              bs = s.GetPointS()
      
              done = []
      
              for i in range(cnt):
      
                  if i in done: continue
      
                  r = random.random()
                  g = random.random()
                  b = random.random()
      
                  c = c4d.Vector4d(r,g,b,1)
      
                  bs.DeselectAll()
                  bs.Select(i)
      
                  c4d.CallCommand(12557)
      
                  sel = bs.GetAll(cnt)
      
                  for index, selected in enumerate(sel):
                      if not selected: continue
      
                      done.append(index)
                      c4d.VertexColorTag.SetColor(data, None, None, index, c)
      
                  done = list(set(done))
      
              s.InsertTag(tag)
      
      # Execute main()
      if __name__=='__main__':
          main()
      
      posted in Cinema 4D SDK
      P
      pyr
    • RE: How to remove generator childs when converting via "c"

      forget about it. i removed the c4d.OBJECT_INPUT flag during development and forgot to add it back.

      posted in Cinema 4D SDK
      P
      pyr
    • RE: How to remove generator childs when converting via "c"

      @m_magalhaes said in HOW TO REMOVE GENERATOR CHILDS WHEN CONVERTING VIA "C":

      Something you can do is touching the objects either with a dependency list or directly.

      Ah - i thought that touch only works with GVO. Never tried it to be honest. This solve at least the visibilty problem.

      posted in Cinema 4D SDK
      P
      pyr
    • How to remove generator childs when converting via "c"

      Hey,

      i have built a spline gernerator that modifies a spline, when i convert the object i get my modified spline but also the hirachie remains. however i only need the new spline object.

      Since GetContour() unfortunately doesn't support HirachyHelper I don't know how to hide the original objects and how to prevent the original splines from being present after the conversion.

      https://gumroad.com/l/spliner

      posted in Cinema 4D SDK python r20 r21 s22 r23
      P
      pyr
    • RE: How to change the EXR compression method via python

      <3<3<3<3

      posted in Cineware SDK
      P
      pyr
    • RE: How to change the EXR compression method via python

      The script change the compression method to zip not to Zips or what i expected: RLE because rle was the given value.

      posted in Cineware SDK
      P
      pyr
    • How to change the EXR compression method via python

      I need to change my exr compression to one scanline at a time but beside using a c4d default document is there any other way to change it directly in a script?

      posted in Cineware SDK
      P
      pyr
    • RE: urllib2.urlopen fails on C4D for Mac

      R23 still has the same Error

      posted in Cinema 4D SDK
      P
      pyr
    • Plugin is evaluated for all frames

      How do I prevent the cinema from running my plugin if I don't start rendering at frame 0?

      posted in Cinema 4D SDK r21 s22 r23 r20 python
      P
      pyr