hexagon logo

CMD problem from A/Car 2017 to A/Car 2018

I have a cmd file I've used for many years to extract info about my A/Car suspension assemblies. It seems to be crashing now on the last line below in A/Car 2018 and I can't see why. Any thoughts...???
 
defaults function_references show_as = partial_name
!
!------------------------------------------------------------------------------------------------------------
!>>>>>> Capture model, analysis, and subsystem names...
!
var set var=Model_Name object=(eval(db_default(.system_defaults,"model")))
var set var=Analysis_Name object=(eval(db_default(.system_defaults,"analysis")))
var set var=Subsystem_Name string_value=(str_substr(eval(Model_Name.object_value[1]),1,(str_length(eval(Model_Name.object_value[1]))-1)))
var set var=Analysis_Subsystem_Name object=(eval(Analysis_Name.object_value)//eval(Subsystem_Name.string_value))
  • Hi Jim. I don't know why it would crash. Did you get a .dmp file on crash? That might help us debug the code.
    But anyway, the expression looks a little odd to my eyes... I'd write it like this:
     
    var set var=Analysis_Subsystem_Name object=(eval(Analysis_Name//"."//Model_Name[1].name))
     
    the ".name" is a built-in way to get any object's name (not including any of its parents).
     
    And in general, you only need one eval() function per expression.
  • Hi Greg,
     
    Sorry, that was poorly worded. By "crash" I meant I get an error on that line. If I run it as I always have I get...
     
    ERROR: ---------------------------------------------------------------------ERROR: Error detected on line number 9, character 112 of aaa.cmd.
    ERROR: Database object ".D27150_310_43pt5_77pt5_14RH_8HH_VS_C21800.SPD12210__Static_Load_Wheel_Center_Height.D27150_310_43pt5_77pt5_14RH_8HH_VS_C21800" does not exist
    ERROR: The command was not executed.
    ERROR: >> var set var=Analysis_Subsystem_Name object=(eval(Analysis_Name.object_value)//eval(Subsystem_Name.string_value))
    ERROR: ---------------------------------------------------------------------
     
    If I change it to your suggestion I get...
     
    ERROR: ---------------------------------------------------------------------ERROR: Error detected on line number 9, character 89 of aaa.cmd.
    ERROR: Database object ".D27150_310_43pt5_77pt5_14RH_8HH_VS_C21800.SPD12210__Static_Load_Wheel_Center_Height.D27150_310_43pt5_77pt5_14RH_8HH_VS_C21800" does not exist
    ERROR: Database object ".D27150_310_43pt5_77pt5_14RH_8HH_VS_C21800.SPD12210__Static_Load_Wheel_Center_Height.D27150_310_43pt5_77pt5_14RH_8HH_VS_C21800" does not exist
    ERROR: The command was not executed.
    ERROR: >> var set var=Analysis_Subsystem_Name object=(eval(Analysis_Name//"."//Model_Name[1].name))
    ERROR: ---------------------------------------------------------------------
     
    Weird it doubles up on the "ERROR: Database object" line...
  • Aha. Did you verify that object does exist with that name?
    Notice my expression generated the same name as yours, so that's good...
  • Found the problem. I'm a bonehead! I had a typo in my subsystem name...Persevere
     
    Always fun to find my dumb mistakes in a big group! Sunglasses
  • Some useful 0.02$ :
    Check out the function
    subsystem_lookup(db_default(.system_defaults,"model"),"suspension","rear")
    that returns the desired subsystem object.
    Usually much more elegant than building strings ....
     
    And another one:
    var set var=xxx can turn out ambiguous. It creates the variable under the default library/model and if you do that multiple times within a session, it's likely to create a var with the same name under different locations which will throw an error.
    I always create a full path/name like:
    library create library_name = .my_own_stuff
    var cre var = .my_own_stuff.my_unique_var
    If I'm lazy, I'm using existing libs like .acar:
    var cre var = .acar.my_unique_var
     
  • Aaaand another last proposal:
     
    It seems you prefer command files, but using macros makes the syntax soooo much easier.
    For your case you could use
    !$Model_Name:t=model:A
    !$Analysis_Name:t=analysis:A
     
    The :A makes the according $ variable holding the system default for the type, thus you don't need to call the macro with model_name = xxx.
    Basically the macro replaces all occurrences of the $xxx with the string that was fed to the macro (or which is default).
     
    In the macro you'd refer everything like
    var set var = $_self.Analysis_Subsystem_Name string = (eval("$'Analysis_Name'." // subsystem_lookup($Model_Name,"suspension","rear").name ))
     
  • As usual, your $0.02 (and Greg's!) are very helpful.
     
    I'll give that "subsystem_lookup" a try.
     
    I have occasionally been getting complaints from ADAMS about a variable existing in more than one place, so I like your suggestion about that, too.
     
    And you're right, I'm absolutely bogged down in my old ways using cmd files. This isn't the first (or last! Blush ) time you've reminded me of the superiority of macros. Old dog...