hexagon logo

Loop in .cmd file to find row at a specific time.

I run a .cmd file after my sims to pull certain data and write it to a text file. I would like to get some numbers at a specific time in the sim. I'm trying to use a WHILE/END loop to do this per another example I found, but it isn't working. Code below...
 
var set var=CurrentAnalysis object=(eval(db_default(.system_defaults,"analysis")))
 
var set var=IP integer_value=1
 
While condition=((eval(CurrentAnalysis.object_value//".MyResult.time").values[IP])<2.5)
var set var=OneGTimeValue real_value=(eval(CurrentAnalysis.object_value//".MyResult.time").values[IP])
end
 
var del var=IP
 
Thoughts? Is there a better way?
  • First thing I notice is that you never increase the value of IP:
    var set var=IP int=(eval(IP+1))
    must be in there somewhere for it to work.
     
    Testing out syntax in the function builder sometimes is very helpful. I suspect that your construct might need a STOO to get the string to be seen as an object.
     
    But if you are just looking for the place where time=2.5, use VALI() or if you are looking for the value at some other signal when time=2.5, use VALAT().
  • Thanks, Jesper. I knew there had to be a better way.
     
    Now, syntax. Just to get something to run, I've been trying variations of this with no success...
     
    var set var=OneGTimeValue real_value=VALI(.Model_1.MyAnalysis.MyResult.TIME.values,2.5)
     
    Am I missing an "EVAL"? Something else?
  • parenthesis
    var set var=OneGTimeValue real_value=(VALI(.Model_1.MyAnalysis.MyResult.TIME.values,2.5))
  • Resurrecting this thread for help with my latest command syntax woes...Unamused
     
    This works...
     
    var set var=OneGTimeValue real_value=(VALI(.Model_1.MyAnalysis.MyResult.TIME.values,2.5))
     
    But I would like this to work with the default analysis, what ever that name may be. I've been trying many permutations of something like this to no avail...
     
    var set var=OneGTimeValue real_value=(VALI(".Model_1"//(eval(db_default(.system_defaults,"analysis")))//".MyResult.TIME.values,2.5))
     
    I never seem to know quite where to put the "eval". Open to someone pointing out my obvious mistake...
     
  • Something in this direction would do the job (not tested; minor tweaking may be required):
    var set var=OneGTimeValue real_value=(eval(VALI(db_default(.system_defaults,"analysis").MyResult.TIME.values,2.5)))
     
    Other than that I'd usually tend to work with macros instead of command files.
    In your case you'd introduce a macro with
    $analysis:t=analysis
    ....
    var set var=$_self.OneGTimeValue real_value=(eval(VALI($analysis.MyResult.TIME.values,2.5)))
     
    This makes the syntax so much easier to write and to understand.
     
    The culprit is that you still need a command file that reads the macro and calls it like
    my_macro analysis=(eval(db_default(.system_defaults,"analysis")))
     
    Concerning the eval:
    if you use
    var set var=$_self.OneGTimeValue real_value=(VALI($analysis.MyResult.TIME.values,2.5))
    then you created a variable OneGTimeValue that is dependent on the analysis.
    If you re-run the analysis, the variable will automatically change. If try to delete the variable, A/View will complain about dependent objects as the expression makes the variable being dependent on the analysis.
    If you eval the whole expression you kind of "snapshot" the value and save it to the variable. It just holds the number and not an expression.
    Consequences: There's no dependency. The variable will not change when the analysis is updated and nor will A/view complain about deleting the variable.
     
     
  • Thanks Martin, that did it.
     
    Every time I post questions about stuff like this you always patiently remind me I should be using macros instead. I promptly say to myself, "You know, Martin is right, I should be trying more macros!" I then just as promptly keep doing it the old way...Confounded
     
    Thanks again...
  • I think it might be time for you to start evaluating Python for your work....
  • Interesting idea. I know zero about Python, but have heard the term going by for years. Where would be a good (ADAMS specific) place to start...???
  • Start with a performance specification and ask yourself:
    • Do I need a very fast execution ?
    • Do I need to read/write a lot of stuff from/to textfiles ?
    • Do I concatenate a lot of sub-strings to longer strings and do something with it ?
    • Do I have to loop often / over a huge number of elements ?
     
    If one or more is answered with yes, you may have an advantage with Python.
    Other than that, macros may be the easier-to-create/maintain way.