Resizing Spline According to a Poly Object



  • On 15/07/2015 at 07:56, xxxxxxxx wrote:

    Ouch
    Hello,
    I am trying to create a xpresso setup, there will be custom spline drag&drop field and spline will automatically center and resize according to general polygon object's size.

    I had figured out centering object with plugincafe authors help but I got stucked comparing size of spline object and polygon object.

    Basically I would like to resize and fit my spline object according to a poly object.

    I'm able to find their size values with;
     sizeobj1 = obj1.GetRad()*2
     sizeobj2 = obj2.GetRad()*2

    It's ok but I cannot figure out how to resize my spline object proportionally according polygon object.

    I have searched net for an answer but could not find anything.

    I'll be gladly appreciated for any answer. An example would be even better since I'm a beginner in python.

    Thank you,
    Best Regards.

    https://www.dropbox.com/s/mm9qhtpjcrp24hu/size_comparision_02.c4d?dl=0



  • On 16/07/2015 at 04:04, xxxxxxxx wrote:

    Hi,

    not sure I got your request completely. I think, you want to resize a spline according to the bounding box of an object.

    First a general note:
    In an Xpresso Python node, you should not directly influence the scene. Instead you should rather do calculations, feed the results to the node outputs and then use other Xpresso nodes to accomplish this.

    Or as our docs say:
    There are some limitations with regard to what Python does within a Python Node. Python Nodes are not allowed to directly access the CINEMA 4D project document or objects in the scene via Python. If, for example, you want to ascertain an object's current position within Python you can use XPresso Nodes to do this and pass this information via Ports to Python.
    _
    _
    The Python Node is better suited for processing mathematical calculations and simple program structures, e.g., if-then-else. More complex Python applications should be executed via Python scripts in the Python Script Manager.

    Actually I expected this to be possible with just Xpresso (almost) without any need for Python. Out of interest, I tried it and cam up with the following solution:

    In the Python node, I use the following simple code:

    import c4d
      
    def main() :
        global lastObj
        global Unequal
        if Obj == inLastObj:
            lastObj = inLastObj
            Unequal = False
        else:
            lastObj = Obj
            Unequal = True
    

    And here's a scene file, if somebody wants to take closer look.
    I should mention this works only with polygonal objects and non-parametric splines.



  • On 16/07/2015 at 05:24, xxxxxxxx wrote:

    Hi Andreas,
    Thank you very much for a detailed answer,

    In fact I'm trying to build kinda "logo generator xpresso setup" . User will be able to drag&drop custom spline, and spline will be centered and resized according to bounding box. So it should be both dynamic, that's why I'm looking for a python way. Actually It should not need to be in xpresso as a node. I would also add a python tag doing this.

    I want my spline proportionally fit into a bounding box with a margin option.
    Do you think that I should modify spline or just scale it in python?
    It would be great if you show me another python tag example.
    Thanks a lot for your helps.



  • On 16/07/2015 at 05:44, xxxxxxxx wrote:

    Hi,

    actually we (the SDK Support team) are not supposed to develop solutions. The example above I did in my spare time, just because I was interested, how to do it.
    By the way, if you tried my scene, you'd see, that the object and the spline can actually be dynamically set via link fields.
    If it is better to modify or scale the spline, I can't tell. Probably depends on the spline and your requirements.
    Also I think, my example shows all elements you'd need.
    If you want to do it with a Python tag and encounter any specific SDK problems, please feel free to ask.



  • On 16/07/2015 at 07:16, xxxxxxxx wrote:

    Hi Andreas,
    Again thank you for very much, you're sparing your time. Unfortunately I'm having hard times to find examples for learning python. I also checked for a book dedicated to Cinema 4D Python but could not find any. In my opinion SDKs can be extended with examples. As a beginner level Python learner even SDKs are hard to understand. For example why there isn't any snippet library for most common tasks?

    By the way (again thanks for previous answer) my goal was to make it proportional uniscale after calculating longest side.

    Still thank you,
    Best Regards.



  • On 17/07/2015 at 07:33, xxxxxxxx wrote:

    Hi,
    If anyone intrested I have found a script by tcastudios and modified it a bit,
    There it is..
    Python Tag - There are spline and poly objects in doc (obj1-spline,obj2-poly)

    import c4d
    from c4d import documents
    from c4d import Vector as v, utils as u
     
    def main() :
        doc = c4d.documents.GetActiveDocument()
        obj1 = doc.SearchObject('obj1')
        obj2 = doc.SearchObject('obj2')
        target = obj1
        if not target or not target.CheckType(c4d.Opoint) : return True
        source = obj2
        if not source: return True
        tBB = target.GetRad()   # Target BoundingBox
        sBB = source.GetRad()   # Source BoundingBox
        sSc = source[c4d.ID_BASEOBJECT_ABS_SCALE] # Source Scale
        try:    xdif = sBB.x / tBB.x 
        except: xdif = 1.0
        try:    ydif = sBB.y / tBB.y 
        except: ydif = 1.0
        try:    zdif = sBB.z / tBB.z 
        except: zdif = 1.0
        for i in xrange(target.GetPointCount()) :
            ppos = target.GetPoint(i)
            target.SetPoint(i,v(ppos.x * xdif * sSc.x , ppos.y * ydif * sSc.y , ppos.z * zdif * sSc.z)) 
        target.Message(c4d.MSG_UPDATE)

    Still It would be better if someone show me how to make it uniform - proportional...


Log in to reply