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. pyr
    P
    • Profile
    • Following 1
    • Followers 0
    • Topics 23
    • Posts 54
    • Best 6
    • Controversial 0
    • Groups 0

    pyr

    @pyr

    8
    Reputation
    190
    Profile views
    54
    Posts
    0
    Followers
    1
    Following
    Joined Last Online

    pyr Unfollow Follow

    Best posts made by pyr

    • RE: Python Autocomplete in Script Manger

      here you go:

      https://developers.maxon.net/forum/topic/10784/14228_autocomplete-for-pycharm/2

      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
    • RE: Close any C4D Window

      can't test it right now, but this should do the trick.

      you'll need to install these packages to your c4d installation to make it work

      import win32gui
      import win32ui
      import win32co
      from pynput.keyboard import Key, Controller
      handle = win32gui.FindWindow(0, "Texture Manager")
          try:
              if handle:
                  
                  keyboard = Controller()    
                  win32gui.SetForegroundWindow(handle)
                  keyboard.press(Key.ctrl)
                  keyboard.press(w)
      
                  keyboard.release(Key.ctrl)   
                  keyboard.press(w)
          except:
              pass
      
      
      posted in Cinema 4D SDK
      P
      pyr
    • RE: Python Generator: Getting polygon data from new generators

      The default python generator returns a parametric object (c4d.Ocube). So you have to convert it to a editable poly in the generator itself. So you don't need a cso in your script but in the generator when using parametric objects.

      Python Generator

      import c4d
      #Welcome to the world of Python
      
      
      def main():
          c = c4d.BaseObject(c4d.Ocube)
          return c4d.utils.SendModelingCommand(command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,list    = [c],
                                                       bc      = c4d.BaseContainer(),
                                                       mode    = c4d.MODELINGCOMMANDMODE_ALL,
                                                       doc     = doc,
                                                       flags   = 0)[0]
      

      script

      import c4d
      
      doc = c4d.documents.GetActiveDocument()
      gen =doc.GetActiveObject()
      print gen.GetCache()
      
      
      
      
      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: 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

    Latest posts made by 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