Navigation

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

    x_nerve

    @x_nerve

    2
    Reputation
    26
    Posts
    89
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online
    Email xiuziye@qq.com

    x_nerve Follow

    Posts made by x_nerve

    • Gets the point weight of the Field object.

      I want to get the point weights of non-Python Field objects . I looked carefully at the Python Effectors code that came with it and knew that FieldOutput was an instance . Suppose you create a new Plain effect and create a cube field . Is there a way to get the weight of the cube field points?

      The fieldOutput.getValue (Index) function cannot get the point weights of other Field objects. So , is there any way to get the weights?That seems difficult to achieve.

      posted in Cinema 4D Development
      X
      x_nerve
    • RE: Data to Spline

      Hi:

      I think it might be faster to try to import the point location directly as an external library (.py). At the same time, C4D supports importing Illustrator files, and SVG can be processed in Illustrator before importing C4D. Here is a simple SplineObject code.

      import c4d
      
      def main():
          #The location of the point.
          Points = [c4d.Vector(0, 0, 0),c4d.Vector(0, 0, 2),c4d.Vector(0, 4, 4)]
          
          #Initializes the spline object.
          Spline = c4d.SplineObject(len(Points), c4d.SPLINETYPE_LINEAR
      )
          
          #Change the number of spline object segments, the number of points.
          Spline.ResizeObject(len(Points), 3)
          
          #Set the locations of all the points of the spline object.
          Spline.SetAllPoints(Points)
          
          #Set properties of the segment.
          Spline.SetSegment(0, len(Points), True)
          
          #Close the spline object.
          Spline[c4d.SPLINEOBJECT_CLOSED] = 1
          
          #Inserts the spline object into the current document.
          doc.InsertObject(Spline)
          
          #Update current document, routine code.
          c4d.EventAdd()
       
      if __name__=='__main__':
          main()
      
      posted in Cinema 4D Development
      X
      x_nerve
    • RE: How to use/import another script file in Python tag correctly?

      Hi:

      @delizade

      I don't think it's necessary to import external libraries, because such simple code can be used directly.I have a suggestion that you should add data in Python tag, not in the object where the Python tag are located. As for the Python tag running repeatedly, it is because your code has no conditional comparisons.Here is the Python tag code, based on the file you provided, that will only run when the frame changes.

      import c4d
      
      def myFunction(getObj):
          obj=getObj.GetObject()
          var1=obj[c4d.ID_USERDATA,1]
          print (var1)
          print ("myFunction: "+str(var1))
          #c4d.EventAdd()
      
      def main():
          frame = doc.GetTime().GetFrame(doc.GetFps())
      
          obj  = op.GetObject()
          var1 = obj[c4d.ID_USERDATA,1]
          
          if frame * 0.01 != var1:
              
              print (var1)
              print ("myFunction: "+str(var1))
              
              obj[c4d.ID_USERDATA,1] = frame * 0.01
              c4d.EventAdd()
      
      posted in Cinema 4D Development
      X
      x_nerve
    • RE: ZeroAxis R23 help

      Hi:

      @peXel

      Sorry, I was negligent. The reset code of rotation and zoom is as follows.

      import c4d
      
      #from c4d import Vector as V
      
      def main():
          
          if op.CheckType(c4d.Opolygon):
      
              #if op is None or not op.CheckType(c4d.Opoint):
                  #return False
          
              ObjMatrix = c4d.Matrix() #op.GetMg()
          
              #ObjPoints = op.GetAllPoints()
          
              #Pcount = op.GetPointCount()
          
              doc.StartUndo()
              doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
              #op.SetAbsRot(V(0))
              #op.SetAbsPos(V(0))
              op.Message(c4d.MSG_UPDATE)
              #NewMatrix = op.GetMg()
          
              point = [ op.GetAllPoints()[i] * op.GetMg() * ~ObjMatrix
                          for i in range(op.GetPointCount()) ]
          
              op.SetMg(ObjMatrix)
              op.SetAllPoints(point)
              op.Message(c4d.MSG_UPDATE)
              c4d.EventAdd()
              doc.EndUndo()
              
          else:
              doc.StartUndo()
              doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
      
              op.SetMg(c4d.Matrix())
      
              op.Message(c4d.MSG_UPDATE)
              c4d.EventAdd()
              doc.EndUndo()
      
      if __name__=='__main__':
          main()
      
      posted in Cinema 4D Development
      X
      x_nerve
    • RE: Python Effector not working with Fields

      Hi:

      @Motion4D @m_magalhaes

      The solution is very simple. The subset of the clone generator is set as a blank object.Create a new matrix generator, select the object mode, and put in the clone generator.Create a new clone generator, select the object mode, put in the matrix generator, and finally subset the original clone generator again as a subset.But this can lead to delays.

      1644.jpg

      posted in Cinema 4D Development
      X
      x_nerve
    • RE: ZeroAxis R23 help

      Hi:

      Your code should run in R23. The following provides additional reset axis code.Unless you're talking about point location resetting, which is non-destructive modeling, and if you want to implement it, you'll need to consider point deletion, etc. It's recommended to use the Python plug-in or the Python tag.

      import c4d
      
      #from c4d import Vector as V
      
      def main():
          #if op is None or not op.CheckType(c4d.Opoint):
              #return False
      
          ObjMatrix = op.GetMg()
          ObjMatrix.off = c4d.Vector(0, 0, 0)
      
          #ObjPoints = op.GetAllPoints()
      
          #Pcount = op.GetPointCount()
      
          doc.StartUndo()
          doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
          #op.SetAbsRot(V(0))
          #op.SetAbsPos(V(0))
          op.Message(c4d.MSG_UPDATE)
          #NewMatrix = op.GetMg()
      
          point = [ op.GetAllPoints()[i] * op.GetMg() * ~ObjMatrix
                      for i in range(op.GetPointCount()) ]
          
          op.SetMg(ObjMatrix)
          op.SetAllPoints(point)
          op.Message(c4d.MSG_UPDATE)
          c4d.EventAdd()
          doc.EndUndo()
      
      if __name__=='__main__':
          main()
      
      posted in Cinema 4D Development
      X
      x_nerve
    • RE: Help with Matrix Manipulation after c4d.MCOMMAND_JOIN

      Hi:

      @mogh

      The MCOMMAND_JOIN modeling command is now ready to execute properly.The merged object cannot be directly visible in the document, so the merged object must be inserted into the document.Also, the global matrix of the merged object is the same as the first object in the parent-child list.I also got it from the forum.

      import c4d
      from c4d import utils
      
      #e-mail : xiuziye@qq.com
      
      def main():
      
          nodes = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
          if nodes == None : return
          Objects = [i for i in nodes
                  if i.GetType() == 5100]
      
          settings = c4d.BaseContainer()
          settings[c4d.MDATA_JOIN_MERGE_SELTAGS] = True
          
          result = c4d.utils.SendModelingCommand(
              c4d.MCOMMAND_JOIN, Objects ,
              c4d.MODELINGCOMMANDMODE_ALL, settings, doc)
      
          doc.InsertObject(result[0])
          c4d.EventAdd()
          
          points = []
      
          Number_One = 0
          while Number_One < len(Objects):
      
              for i in Objects[Number_One].GetAllPoints():
      
                  n = i * Objects[Number_One].GetMg()
                  points.append(n * ~result[0].GetMg())
      
              Number_One = Number_One + 1
      
          result[0].SetAllPoints(points)
      
          result[0].Message(c4d.MSG_UPDATE)
          c4d.EventAdd()
          
          print (result[0])
      
      if __name__=='__main__':
          main()
      
      
      posted in Cinema 4D Development
      X
      x_nerve
    • RE: Finding Control ID in ObjectData Plugin Message() Override

      Hi:

      Assuming that you are creating a Python plug-in instead of a C++ plug-in, there are two solutions.

      The first is to compare the variable data after the control is updated after the plug-in's name stores the previous variable data.If the data is not the same, it is executed to avoid repeated runs.

      The second is to create a polygon cache, for example by storing the previous variable data with the local coordinates of the first point, and comparing variable data after the control is updated.If the data is not the same, it is executed to avoid repeated runs.

      Python plug-ins actually update automatically, even with every click of the mouse, which often leads to very heavy delays.All dirty systems can be used to detect if an update has occurred.

      There should be a better solution to your problem.

      Here are examples of Python tags and links to examples : link text

      import c4d
      #e-mail: xiuziye@qq.com
      
      def main():
             
          Name = op.GetName()
      
          Objects = op.GetObject()
          Changed = Objects.GetDirty(c4d.DIRTYFLAGS_SELECT)
      
          Text = ["xit" + str(Changed)[-1]]
          
          if str(Name).count(Text[0][:-1]) != 0 :
              
              if str(Name).find(Text[0][:-1]) != str(Name).rfind(Text[0][:-1]) :
                  
                  if str(Name)[str(Name).rfind(Text[0][:-1]):] == Text[0] :
                  
                      if str(Name).find(Text[0][:-1]) <= 0:
                          
                          #Do not execute, exit the program.
                          print ("Does not perform.")
                          op.SetName(str(Text[0]))
                          
                          return
                      
                      else:
                          #Do not execute, exit the program.
                          op.SetName(str(Name)[:str(Name).find(Text[0][:-1])] + str(Text[0]))
                          print ("Does not perform.")
                          
                          return
                          
                  else:
                      if str(Name).find(Text[0][:-1]) <= 0:
                          
                          op.SetName(str(Text[0]))
                          print ("Perform.")
                          
                      else:
                          
                          op.SetName(str(Name)[:str(Name).find(Text[0][:-1])] + str(Text[0]))
                          print ("Perform.")
      
              else:
                  
                  if str(Name)[str(Name).rfind(Text[0][:-1]):] == Text[0] :
                      #Do not execute, exit the program.
                  
                      print ("Does not perform.")
                      return
      
                  else:
      
                      op.SetName(str(Name)[:str(Name).find(Text[0][:-1])] + str(Text[0]))
                      print ("Perform.")
      
          else:
              print ("Perform.")
              op.SetName(str(Name) + str(Text[0]))
          
      
      
          print ("pass")
          #The next thing to execute.
      
      
      posted in Cinema 4D Development
      X
      x_nerve
    • RE: Help with Matrix Manipulation after c4d.MCOMMAND_JOIN

      Hi:

      The merge object simply generates a new polygon object, because the merge in the modeling command cannot be used, so it can be resolved in other ways.The answer to your question is, in fact, how the connection generator works.I've written it out, but I can't generate an N-gon face.Create a new blank object, the object to be connected as a subset of the blank object, and then click the middle key of the mouse to select all blank objects and all subsets to achieve the effect of connection generator.

      import c4d
      
      #e-mail : xiuziye@qq.com
      
      def main():
          nodes = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
          if nodes == None : return
          Object = [i for i in nodes
                  if i.GetType() == 5100]
      
          node = c4d.BaseObject(5100)
          doc.InsertObject(node)
          c4d.EventAdd()
      
          points = []
      
          Number_One = 0
          while Number_One < len(Object):
      
              for i in Object[Number_One].GetAllPoints():
      
                  n = i * Object[Number_One].GetMg()
                  points.append(n * ~node.GetMg())
      
              Number_One = Number_One + 1
      
          Polygons = [i.GetAllPolygons() for i in Object]
      
          Cpolygons = Polygons[0]
      
          Polygon_Indexe = []
          if len(Object) > 1:
      
              Number_Two = 0
              while Number_Two < len(Object) - 1:
      
                  Point_Count = [ Object[0].GetPointCount() ]
                  if Number_Two > 0:
      
                      for i in Object[:-1 * (len(Object) - Number_Two )]:
                          Point_Count.append(Point_Count[-1] + i.GetPointCount())
      
                  for i in Polygons[Number_Two  + 1]:
      
                      if str(i).count("d") == 1:
      
                          Polygon_Indexe.append(c4d.CPolygon(i.a + Point_Count[-1] ,i.b +Point_Count[-1] ,i.c + Point_Count[-1] ,i.d + Point_Count[-1] ))
      
                      else:
      
                          Polygon_Indexe.append(c4d.CPolygon(i.a + Point_Count[-1] ,i.b + Point_Count[-1] ,i.c +Point_Count[-1] ))
      
                  Number_Two  = Number_Two + 1
      
          Cpolygons += Polygon_Indexe
      
          node.ResizeObject(len(points),len(Cpolygons))
          node.SetAllPoints(points)
      
          for i in range(len(Cpolygons)):
              node.SetPolygon(i,Cpolygons[i])
      
              node.Message(c4d.MSG_UPDATE)
              c4d.EventAdd()
      
          node.Message(c4d.MSG_UPDATE)
          c4d.EventAdd()
      
      if __name__=='__main__':
          main()
      
      posted in Cinema 4D Development
      X
      x_nerve
    • RE: Selecting Different components but in Different modes

      HI:

      The modeling axis cannot be restored to its default state using the following sample code.Create a new cube object, collapse, and select any point.The world coordinates of points are all 0.

      """Script Manager script.
      
      Swizzles the modeling axis of the selected polygon object when run. As a
      side effect the active tool is changed to the LiveSelection tool and set
      into "Free" mode. You will have to pretty up the script yourself if you
      want a more streamlined experience.
      """
      
      import c4d
      
      def swizzle_modelling_axis(doc, op):
          """Swizzles the modeling axis of the passed object.
          
          Args:
              doc (c4d.documents.BaseDocument): The active document.
              op (c4d.PolygonObject): A node in the active document.
          
          Raises:
              TypeError: When op is not a PolygonObject.
          """
          def swizzle_matrix(m):
              """Swizzles a matrix, pushing in numerical and looping order of 
              its components (e.g. v1, v2, v3 becomes v3, v1, v2).
              """
              return c4d.Matrix(off=m.off, v1=m.v3, v2=m.v1, v3=m.v2)
      
          # Sort out non-polygon-objects.
          if not isinstance(op, c4d.PolygonObject):
              msg = ("swizzle_modelling_axis() requires a polygon object. "
                    "Received: {type}.")
              raise TypeError(msg.format(type=type(op)))
      
          # We need the axis to be free in order to be able to modify the axis.
          # For that we select the live selection tool and set it to free mode.
          doc.SetAction(c4d.ID_MODELING_LIVESELECTION)
          plugin = c4d.plugins.FindPlugin(c4d.ID_MODELING_LIVESELECTION, 
                                          c4d.PLUGINTYPE_TOOL)
          if plugin is None:
              return
          else:
              plugin[c4d.MDATA_AXIS_MODE] = c4d.MDATA_AXIS_MODE_FREE
      
          # Get the modeling axis, swizzle it and write it back.
          axis = swizzle_matrix(op.GetModelingAxis(doc))
          op.SetModelingAxis(axis)
          op.Message(c4d.MSG_UPDATE)
      
      def main():
          """Entry point.
          """
          swizzle_modelling_axis(doc, op)
          c4d.EventAdd()
      
      if __name__=='__main__':
          main()
      
      
      posted in Cinema 4D Development
      X
      x_nerve