Skip to main content
1-Visitor
April 26, 2011
Question

Import Unit/Dimension

  • April 26, 2011
  • 2 replies
  • 3159 views

Is it possible to import the unit/dimension of a variable from Mathcad to VBA? I understand that Mathcad stores all values in SI units, therefore, the GetValue function will always import a length dimension in units of meters. My programming, however, cycles through a list of variables (of varying dimensions) and imports their values (using GetValue) from a given Mathcad worksheet, and I would like to convert units within VBA.

The following demonstrates what I'd like to do. It would import variables of length, mass, dimensionless, or text and convert from their standard SI units to what I typically use (in, lb, dimensionless, and text):

McadValue = WS.GetValue(VariableName)

Select Case WS.GetDimension(VariableName) <--- is there something equivalent to GetDimension?

Case “Length”

Mult = 39.3701 ‘Convert meters to inches

Case “Mass”

Mult = 2.20462 ‘Convert kg to lb

Case “Dimensionless”

Mult = 1

Case Else

Mult = 0 <--- I use this for text fields, I can modify as necessary if text is handled differently.

End Select

If Mult = 0 Then

vbValue = McadValue ‘for variables which contain text

Else

vbValue = McadValue * Mult ‘for variables which contain numeric values

End If

I searched some other threads and only found discussions of trying to obtain a variable’s unit. I do not need the unit, just the dimension.

Please let me know if anything like this is possible (I realize if it exists, it’s probably not in as nice of a format as I’d like, so I’ll need to make some modifications to my example script above).

Thank you in advance.

2 replies

1-Visitor
April 26, 2011

Stuart posted a worksheet a while back which might be of some use, but I'm struggling to find it. I think it was called Parsing units, or something similar.

Mike

1-Visitor
April 26, 2011

Stuart posted a worksheet a while back which might be of some use, but I'm struggling to find it. I think it was called Parsing units, or something similar.

Found the worksheet I was talking about.

Have a look if it helps.

Mike

19-Tanzanite
April 26, 2011

There was a long discussion about this recently, here:

http://communities.ptc.com/thread/34270

This is the only possibility.