Python Generator Scaling [SOLVED]



  • 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



  • 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



  • 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



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

    Hello,

    what exactly do you mean with "scale data" ?

    best wishes,
    Sebastian



  • 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


Log in to reply