question

royjuventus29 avatar image
1 Like"
royjuventus29 asked Jason Lightfoot commented

How to get the "Unit" of an object property value

FlexSim 24.0.1
flexsim script
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Jason Lightfoot commented

You need to pass the GET_PROPERTY_FLAG_UNITS flag into the Object.getProperty() method.

If you pass that flag it will return a 2-length array with the display value in the first element and the display units in the second. Without that flag it will return the value in model units.

For example, say you set the Process Time of Processor1 to be 10 minutes in a model with seconds as the model time unit. Then the getProperty method will return:

Object obj = Model.find("Processor1");
obj.getProperty("ProcessTime", GET_PROPERTY_FLAG_UNITS);     // [10, min]
obj.getProperty("ProcessTime");                              // 600


· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

royjuventus29 avatar image royjuventus29 commented ·

Do you know how to get the "Unit" of a Source Object's "InterArrivalTime" property? I use the code below for "Processor" it works fine but for this property of a "Source" object, it does not work..

  
                    
  • Object obj = Model.find("Source");
  • obj.getProperty("InterArrivalTime", GET_PROPERTY_FLAG_UNITS)[2]; 
0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ royjuventus29 commented ·

getProperty() only returns the units if the value is a number. That property probably has code for its value instead of a straight number and so it's just returning the string of code. If you have a different unit defined for that code though it will be written into the code.


You could parse that text though and find the model unit, something like this:

Object obj = Model.find("Source1");
string units = obj.getProperty("InterArrivalTime").match(/unitConversion:[a-z]*/)[1];
return units.split(":")[2];
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Matthew Gillespie ♦♦ commented ·

If it's using the model time unit then you'll want to check that search finds a value and otherwise return the model unit.


Object p=Model.find("Processor1");
Variant v= p.getProperty("ProcessTime").match(/unitConversion:[a-z]*/);
if (v.type==VAR_TYPE_ARRAY&&v.length>0) {
    string units=v[1];
    return units.split(":")[2];
}
return getmodelunit(MODEL_TIME);
0 Likes 0 ·