構造

構造

全てのボディに内容の異なるコマンドを設定したい

    • yasuhiro.ogawa.j4a
      Subscriber

      ・ANSYS WorkbenchのMechanicalにおいて、ジオメトリ内のすべてのボディにコマンドを挿入したい。 ・挿入したコマンドには「mat1=matid」と設定したい。数字の"1"の部分はボディの数だけ1,2,3,・・・と連番とする。 ・ボディの数が多いのでスクリプティングで自動化したいです。 全てのボディのID取得から考えましたが、うまくいかずでしたので、質問させていただきます。よろしくお願いいたします。

    • Ashish Khemka
      Forum Moderator

      Translated: - In ANSYS Workbench Mechanical, I want to insert a command into all bodies in the geometry. - I want to set the inserted command to "mat1 = matid". The number "1" is numbered sequentially by the number of bodies, such as 1, 2, 3, and so on. ・ Since there are many bodies, I want to automate it by scripting.Are. I thought about getting IDs for all bodies, but it didn't work, so I'd like to ask a question. Best regards.

      • Aniket
        Forum Moderator

        you can traverse tree as shown in code snippet below: 

        https://ansyshelp.ansys.com/public/account/secured?returnurl=/Views/Secured/corp/v242/en/act_script/act_script_examples_get_GeoData.html 

        only first line is important, you can list all the children of each part by changing the number. now next part would be adding command snippets that can be done using following:

        https://ansyshelp.ansys.com/public/account/secured?returnurl=/Views/Secured/corp/v242/en/act_script/mech_apis_CommandSnippets.html

        -Aniket

        Forum Rules & Guidelines

    • yasuhiro.ogawa.j4a
      Subscriber

      Thank you for your response. Based on your comments, I was able to accomplish what I wanted to do. FYI, I am attaching the code.

      # Creating the content to write in the command
      mat_list = []
      for i in range(1, 100):
          mat_list.append("mat{}".format(i))

      # Creating the command and writing the contents
      for num in range(1, 100):

          treeBody = Model.Geometry.Children[0].Children[num-1]  
          cs = treeBody.AddCommandSnippet()
          cs.AppendText(mat_list[num-1])

Viewing 2 reply threads
  • このトピックに返信するには、ログインする必要があります。