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
    • Recent
    • Tags
    • Users
    • Login

    Python Generator Scaling [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 518 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      On 18/07/2016 at 09:27, xxxxxxxx wrote:

      Hello Forum,

      I'm working on a Python Generator and I'm confused about what is happening when the object is scaled.

      Here is the python generator simple setup:
      The python generator has a user data float gadget set to meter with id = 1;

      import c4d
        
      def main() :
          rad = op[c4d.ID_USERDATA, 1]
          cube = c4d.BaseObject(c4d.Ocube)
          cube[c4d.PRIM_CUBE_LEN, c4d.VECTOR_X] = rad * 2.0
          cube[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Y] = rad * 2.0
          cube[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Z] = rad *2.0
          return cube
      

      If the document is in 'Model' mode and I scale the python generator with the scale tool, the float gadget is updated and the object is scaled.  The attribute manager coordinates for scale are not changed.

      If the document is in 'Object' mode and I scale the python generator with the scale tool, the float gadget is not updated but the object is scaled.  The attribute manager coordinates for scale are changed.

      Scaling in 'Object' mode makes sense to me.  I can see that the matrix has changed so the mesh generated by the generator should be changed accordingly.

      Scaling in 'Model' mode is confusing to me.  How does the python generator know what parameters to change  when it is scaled in 'Model' mode?  Is there some magic going on behind the scenes?

      Thank you,

      Joe Buck

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 19/07/2016 at 01:36, xxxxxxxx wrote:

        Hello,

        when the "Scale" tool is applied in "Model" mode it will scale (multiply) float parameters with a "length" unit (cm, m, etc.). You can easily test this with a standard parametric cube, this is not specific to the Python Generator.

        Best wishes,
        Sebastian

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 19/07/2016 at 07:31, xxxxxxxx wrote:

          Thanks Sebastian,

          I think I got it.

          import c4d
            
          def main() :
              rad = op[c4d.ID_USERDATA, 1] # unit meter
              dummy_meter = op[c4d.ID_USERDATA, 2] # unit meter
              dummy_percent = op[c4d.ID_USERDATA, 3] # unit percent
              
              polys = [ [3,0,1,2], [3,4,5,0], [0,5,6,1], [1,6,7,2], [2,7,4,3], [5,4,7,6] ]
              points  = [ [0.707,0.707,0.707], [-0.707,0.707,0.707], [-0.707,-0.707,0.707], [0.707,-0.707,0.707],[0.707,-0.707,-0.707], [0.707,0.707,-0.707], [-0.707,0.707,-0.707], [-0.707,-0.707,-0.707] ]
              
              cube = c4d.PolygonObject(8, 6)
              
              for i in xrange(6) :
                  a = polys[i][0]
                  b = polys[i][1]
                  c = polys[i][2]
                  d = polys[i][3]
                  poly = c4d.CPolygon(a, b, c, d)
                  cube.SetPolygon(i, poly)
                  
              padr = list()
              for i in xrange(8) :
                  padr.append(c4d.Vector(points[i][0], points[i][1], points[i][2]) * rad)
                  
              cube.SetAllPoints(padr)
              return cube
          

          rad is scaled because its unit is meter.
          dummy is scaled because its unit is meter.
          dummy_percent is not scaled because its unit is percent.

          Is the scale data generated by the scale tool in model mode accessible somewhere in the object(I'm just curious. Even if it's only possible in c++)?

          Thanks again,

          Joe Buck

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 19/07/2016 at 09:09, xxxxxxxx wrote:

            Hello,

            what exactly do you mean with "scale data" ?

            best wishes,
            Sebastian

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 19/07/2016 at 10:31, xxxxxxxx wrote:

              Hi Sebastian,

              Doh!!!  I did not think before I typed.  You already answered the question.  The data is in the object's parameters of type meter.

              Thanks for your time and patients,

              Joe Buck

              1 Reply Last reply Reply Quote 0
              • First post
                Last post