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

    Search elements of a certain type

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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 23/05/2011 at 09:36, xxxxxxxx wrote:

      Hy there,

      what function can I use to check for a certain type of object?
      I tried CheckType, GetType(), GetName() ...

      I want to recourse over the hierarchy and put all matching objects into a list (say, all Sweep NURBS).

      The following will fail:

      import c4d
      sweeps = []

      def getSweeps(obj) :
        global sweeps
       
        if obj == None: return

      if obj.CheckType(c4d.Osweep) :
        sweeps.append(obj)
       
        print "obj: "+ str(obj)

      if obj.GetDown() : getSweeps(obj.GetDown)
        if obj.GetNext() : getSweeps(obj.GetNext)

      def main() :
        global reset

      reset = False

      print "Impulses: "+getSweeps(obj.GetDown())

      Error is:
      obj: <c4d.SplineObject object at 0x0000000015F8D3B0>
      Traceback (most recent call last) :
        File "<Python>", line 27, in main
        File "<Python>", line 18, in getSweeps
        File "<Python>", line 12, in getSweeps
      AttributeError: 'builtin_function_or_method' object has no attribute 'CheckType'

      BTW. I have this Python code in a XPresso Tag on top of the hierarchy I want to parse.

      Thank you,
      maxx

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 23/05/2011 at 09:45, xxxxxxxx wrote:

        You pass a method in your code: getSweeps(obj.GetDown) -> getSweeps(obj.GetDown () )

        Btw, I recommend you to avoid global variables if possible.

        import c4d
          
        def getSweeps(obj, sweeps) :
            if obj == None: return 
          
            if obj.CheckType(c4d.Osweep) :
                sweeps.append(obj)
          
            print "obj: "+ str(obj)
          
            getSweeps(obj.GetDown(),sweeps)
            getSweeps(obj.GetNext(),sweeps)
          
          
        def main() :
            obj=op
            sweeps=[]
            getSweeps(obj.GetDown(), sweeps)
            print sweeps
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 23/05/2011 at 10:00, xxxxxxxx wrote:

          ... 😠 ...

          I am so used to Java IDEs ... don't see the simple things anymore ... now I also understand the Traceback ...

          Thanx,
          maxx

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