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?
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.
#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)