How to control the order in which command snippets are written to ds.dat in Mechanical?
Rohith Patchigolla
Member, Moderator, Employee Posts: 193
✭✭✭✭
in Structures
I have 100s of Command Snippets in Mechanical. I want to control the order in which they are written to the ds.dat file for Loadstep 1. I don't see any native options for this. Is this possible?
Tagged:
0
Comments
-
Unfortunately, we don't have any native options in Mechanical GUI to control the order of writing of the command snippets.
But, there is a way using "Python Code" object in Mechanical. Here are the steps.
- Preparation of command objects:
- For this example, I am indentifying the command snippet using the number in its name. For example in the below example, 5 command objects are named as shown below and there is a number at the end.
- Group all the command objects into a folder with a name, "AllCommandObjects" and suppress the folder.
- RMB on analysis and insert Python code.
- Paste the below script in the Python code window.
- Here there are two inputs.
- First is the order list in which command snippets are written. These numbers will connect with the numbers in the name of the command snippet (one could also use Input Arguments in the details of the command object to specify the order number).
- Second is the loadstep number at which you would like to write the inputs. For now, its set to 1. But, it can be changed as per your needs.
#Inputs # Order of command snippets - We will use the number at the end of the name of the command snippet (please maintain the naming convention for the script to work) order = [4,5,3,2,1] #Load step number for which the command snippets should be written. stepNum = 1 allCommandObjects = DataModel.GetObjectsByName("AllCommandObjects")[0].Children replaceString = """! Commands inserted into this file will be executed just prior to the ANSYS SOLVE command. ! These commands may supersede command settings set by Workbench. ! Active UNIT system in Workbench when this object was created: Metric (m, kg, N, s, V, A) ! NOTE: Any data that requires units (such as mass) is assumed to be in the consistent solver unit system. ! See Solving Units in the help system for more information.""" allcmds = [] allcmdNums = [] for CommandObj in allCommandObjects: cmds = CommandObj.Input.replace(replaceString,"") cmdNum = int(CommandObj.Name.Split(" ")[-1]) allcmds.append(cmds) allcmdNums.append(cmdNum) for item in order: index = allcmdNums.IndexOf(item) cmd = allcmds[index] if solver_data.CurrentStep == stepNum: solver_input_file.WriteLine("\n!Command Snippet Num " + str(item) + "\n") solver_input_file.WriteLine(cmd)
1