3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

Ansys SpaceClaim scripting – replicating objects

    • Joana Almeida
      Subscriber

      I have successfully replicated BlockBodies using a function (‘def’) and a ‘for’ loop (as per shown in image below). However, when I try to replicate different types of bodies (cylinders, spheres, ellipsoids, pyramids, …) it gives me an error. I believe the problem lies either in how I store the created object in a variable (‘ta = result.CreatedBody’) or on the identification of said object when creating a List (‘bodyList = List[IDocObject]()’). However, I do not know how to fix it… could anyone help me out?

    • Atharv Joshi
      Forum Moderator

      Hi Joana, 

      Let me check this and get back to you. 

      Thanks and Regards
      Atharv

    • Atharv Joshi
      Forum Moderator

      Hi Joana, 

      Can you please try "ta=result.CreatedBodies" instead of "ta=result.CreatedBody"? 

      Let me know if this resolves your problem. 

      Thanks and Regards
      Atharv

      • Joana Almeida
        Subscriber

         

        Hi Atharv,

        Thank you so much for the quick response, though I’m afraid it didn’t solve my problem yet. Once I switch to what you suggest, an error appears concerning the creation of the list to store the cylinders (‘ expected IDocObject, got List[IDesignBody] ‘ ). Do you have any idea on how I can fix it?

         

         

         

    • Atharv Joshi
      Forum Moderator

      Hi Joana, 

      "ta=result.CreatedBodies" forms a list of bodies. You can check this using the type function.
      You need to include the index of the element to overcome the problem "bodylist.Add(ta[0])"

      Is their a specific reason you are creating a bodylist with IDocObjects?
      What's your exact goal with this script? 

      Thanks and Regards
      Atharv

      • Joana Almeida
        Subscriber

        Hi Atharv,

        Once I include the index of the element “bodylist.Add(ta[0])”, a new error appears: “’bool’ object is unsubscriptable”.

         

        The only reason I created the bodylist with IDocObjects was because I checked the examples provided by SpaceClaim and the one where it generated stairs did their list with IDocObjects.

         

        My goal with the script is to be able to duplicate one single (varying) object (cube, cylinder, sphere, pyramid, …) in a certain pattern that I have designed and tested with cubical tools (as it can be seen above). For the cubical solids, the bodylist with IDocObjects worked, but with every other different type of object it does not…

        Thank you again for the help

        Joana

         

         

         

    • Joana Almeida
      Subscriber

      Once I include the index of the element “bodylist.Add(ta[0])”, a new error appears: “’bool’ object is unsubscriptable”.

Viewing 4 reply threads
  • The topic ‘Ansys SpaceClaim scripting – replicating objects’ is closed to new replies.