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

    Getting Spline Object Angle!

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 461 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 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

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

        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.

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

          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🙂

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