3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

Script for subtracting models

    • p.vintr
      Subscriber

      Hello, I would like to ask experienced users a question.
      Is it possible to use a script(# Python Script, API Version = V251) to find models that are inside other models and then subtract them?

      It's about ajdustin cabinets parts, where are joints represented by model. see simple example.

       

      I want to find all inner models and remove them and before subtract them from whole panel.

      Now I am able to go through parts in document, but I cant find the way how create condition for it.

      Thank you for any answer.

       

      Kind Regards.

      Pavel

    • Atharv Joshi
      Forum Moderator

      Hi Pavel, 

      You can record the operations in SpaceClaim/Discovery. 
      Activate the script editor and use Interference tool from Prepare Tab.

      That should find and fix all the interference in the geometry. 
      It will also record the command or API used.

      You can fix all the interference and also use for removing between specific selections.
      If you want to the interference to be removed from smaller body, then you need to select it from options.

      Thanks and Regards
      Atharv

    • p.vintr
      Subscriber

      HI,

      thank you for your reply.

      I know about recording the procedure.
      What I can't figure out is how to use a loop to go through all the models in the drawing and subtract the models defining the hole from the large piece. 
      The image of the part I sent is only part of the entire assembly; it will be a kitchen with many more components. If this can be solved, the customer will probably purchase SpaceClaim.

      I didn't mention that I am a SpaceClaim sales representative in the Czech Republic.

      Thanks for any help.

      Kind Regards.

      Pavel

       

      • NickFL
        Subscriber

         

        Hello p.vintr,

        I am not exactly sure what you mean by models. You should be able to create loops over the different components within the model. For example:

         

        numberOfComponents = GetRootPart().GetAllComponents().Count

        for component in GetRootPart().GetAllComponents():
          for body in component.GetAllBodies():
              print(component.GetName(), body.GetName())
            print(‘new Component’)

         

        Note this will not evaluate bodies that are directly under the RootPart, only those in a component. If I am miss reading your question, please let me know and I am sure there is a solution. If you could show the structure tree from an example problem, that would help.

         

    • p.vintr
      Subscriber

      Hi Nick,

      thank you so much.

      The target is to make subtract of the models(bodies) which are all of their volume inside the another (its cabinet's parts).

       

      It's simplyfy for one part but in the reality there will be a lot of them. This is one cabinet from the customer as example. Whole kitchen will be here in future.

       

      Kind Regards.

      pavel

       

       

      • NickFL
        Subscriber
        1. Is there a naming convention that will ALWAYS be there? It looks like you have that Pevne is removed from Telesco. Will that always be the case? 

        2. These will be in the same component, correct? 

         

        • p.vintr
          Subscriber

          HI,

          script based on the name is not good. It's third party assembly and I can't rely on the names.

           

          Kind Regards.

          pavel

           

           

      • Atharv Joshi
        Forum Moderator

        Hi Pavel, 

        You can create selection based on the geometry name, through named selection or use geometric details like volume etc
        Let’s assume that the parts have name plate and cylinder always.

        You can make selections using the names, volumes (cubic meter) as shown below.
        Then execute the delete operation on the selection.

        Regards
        Atharv

        • p.vintr
          Subscriber

          Hi, I also thought about filtering by volume, but I'm not sure if that will be sufficient, because the elements will be different. I would like to be able to evaluate whether one model is inside another.

        • NickFL
          Subscriber

          It seems like most of your bodies are planar/cylindrical. In that case you could compare the bounding boxes to see if they overlap. With more generic shapes the bounding boxes could overlap but not the bodies themselves which could cause problems when you try and subtract them. 

        • NickFL
          Subscriber

          If you wanted to use the interference command like you had earlier, try something like this:

          for component in GetRootPart().GetAllComponents(): 
              # Activate the current component
              sel = ComponentSelection.Create(component)
              result = ComponentHelper.SetActive(sel,None)
              
              # Use Interference to create holes in larger Body
              sel = Selection.Create(component.GetBodies())
              FixInterference.FindAndFix(sel)
Viewing 3 reply threads
  • You must be logged in to reply to this topic.