Getting Spline Object Angle!



  • On 25/01/2018 at 21:26, xxxxxxxx wrote:

    Hi Guys!

    I know its been a while guys!
    Hope yall are good and having a good year so far.

    Will I am trying to get the spline angle data but its not getting it.
    I would love to know what I am doing wrong.

    ########################################
    # IMPORTS
    ########################################
    import c4d, os, sys, subprocess, webbrowser, collections, math, random, urllib, glob, time
    from c4d import plugins, gui, bitmaps, documents, storage, utils
    #--------------------------------------#
      
    def main() :
        
        doc = c4d.documents.GetActiveDocument()
        
        obj = doc.GetActiveObject()
        
        SplineName = obj.GetName()
        
        GetSplineType = obj[c4d.SPLINEOBJECT_TYPE]
        if GetSplineType == 0: print SplineName + " - Type - Linear"
        if GetSplineType == 1: print SplineName + " - Type - Cubic"
        if GetSplineType == 2: print SplineName + " - Type - Akima"
        if GetSplineType == 3: print SplineName + " - Type - B-Spline"
        if GetSplineType == 4: print SplineName + " - Type - Bezier"    
        
        GetSplineClose = obj[c4d.SPLINEOBJECT_CLOSED]
        if GetSplineClose==False: print SplineName + " - CloseSpline : UnCheck"
        if GetSplineClose==True:  print SplineName + " - CloseSpline : Check"
       
        GetInterpolation = obj[c4d.SPLINEOBJECT_INTERPOLATION]
        if GetInterpolation == 0: print SplineName + " - Points - None"
        if GetInterpolation == 1: print SplineName + " - Points - Natural"
        if GetInterpolation == 2: print SplineName + " - Points - Uniform"
        if GetInterpolation == 3: print SplineName + " - Points - Adaptive"
        if GetInterpolation == 4: print SplineName + " - Points - Subdivided"
           
         # //  Its not getting the value !!!! //
        GetAngle = obj[c4d.SPLINEOBJECT_ANGLE]
        if GetAngle == 0.087:
            print "Its 5" 
      
        c4d.EventAdd()   
        
    if __name__=='__main__':
        main()
    

    Result when execute:

    Any tips or help will be very appreciate!

    Cheers,
    Ashton



  • On 26/01/2018 at 04:38, xxxxxxxx wrote:

    Hi Ashton,

    this actually has nothing to do with reading the actual parameter. You are doing this correctly.
    The problem is the comparison afterwards. You can not compare float values in this way. Well, of course you can, but the condition will rarely be true due to small imprecision (without going into too much detail, these are related to the way floating point numbers are stored and processed by a processor).
    So, you need to do a somewhat tolerant comparison. Either by a condition "value greater as min and value smaller than max" or by rounding before the comparing (here I'd recommend multiplying both values by lets say e.g. 1000 and then doing an integer comparison, to avoid further pitfalls).

    Lastly, as you found the parameter is stored in radians, but you seem to be interested in a value in degree. Here we have RadToDeg() in our API, which does the math for you.



  • On 27/01/2018 at 01:28, xxxxxxxx wrote:

    Thnaks Andreas

    ########################################
    # IMPORTS
    ########################################
    import c4d, os, sys, subprocess, webbrowser, collections, math, random, urllib, glob, time
    from c4d import plugins, gui, bitmaps, documents, storage, utils
    #--------------------------------------#
      
    def main() :
        
        doc = c4d.documents.GetActiveDocument()
        
        obj = doc.GetActiveObject()
        
        SplineName = obj.GetName()
        
        GetSplineType = obj[c4d.SPLINEOBJECT_TYPE]
        if GetSplineType == 0: print SplineName + " - Type - Linear"
        if GetSplineType == 1: print SplineName + " - Type - Cubic"
        if GetSplineType == 2: print SplineName + " - Type - Akima"
        if GetSplineType == 3: print SplineName + " - Type - B-Spline"
        if GetSplineType == 4: print SplineName + " - Type - Bezier"    
        
        GetSplineClose = obj[c4d.SPLINEOBJECT_CLOSED]
        if GetSplineClose==False: 
            print SplineName + " - CloseSpline : UnCheck"
        else:
            print SplineName + " - CloseSpline : Check"
       
        GetInterpolation = obj[c4d.SPLINEOBJECT_INTERPOLATION]
        if GetInterpolation == 0: 
            print SplineName + " - Points - None"
            
        if GetInterpolation == 1: 
            print SplineName + " - Points - Natural 
                    
        if GetInterpolation == 2: 
           print SplineName + " - Points - Uniform"
           
        if GetInterpolation == 3:
            GetSplineAngle = obj[c4d.SPLINEOBJECT_ANGLE]
            deg = obj[c4d.SPLINEOBJECT_ANGLE]*180 / math.pi
            rad = (GetSplineAngle*math.pi)/180
            print SplineName + " - Points - Adaptive - Angle : " + str(int(deg)) + " = " +  str(rad)
      
        if GetInterpolation == 4: 
            print SplineName + " - Points - Subdivided"       
        
        c4d.EventAdd()   
        
    if __name__=='__main__':
        main()
    

    thanks again and Cheers,
    Ashton🙂


Log in to reply