How to automatically change units in CATIA

change units in catia

Today, I’m going to show you how to automatically change units in CATIA with a CATScript macro. This is useful if you need have another code that needs the units set to metric or English in order to run properly. The first lines of code from CATIA Change Units.CATScript are:

 

1
2
3
4
5
6
7
Dim oSettingControllers As SettingControllers
Set oSettingControllers = CATIA.SettingControllers
 
 
 
Dim oUnitsSheetSettingAtt As SettingController
Set oUnitsSheetSettingAtt = oSettingControllers.Item("CATLieUnitsSheetSettingCtrl")

 

The SettingControllers manages the parameters available in the property pages of the Tools > Options menus. Each parameter setting may be represented by one or several attributes in the underlying setting repository.

All setting controllers share the five methods of the SettingController object to deal with the whole set, or a subset of the setting attributes:

  • Commit to make a memory copy of the setting attribute values
  • Rollback to restore the last memory copy of the setting attribute values
  • ResetToAdminValues to restore the administered values of all the attributes
  • ResetToAdminValuesByName to restore the administered values of a subset of the attributes
  • SaveRepository to make a persistent copy of the setting attribute values on file

You may have also noticed the code with UnitSheetSetting which is the interface to be used to read or modify the CATIA\Tools\Options settings for values of Units. The next part of the change units macro:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Dim oMagnitude as String
oMagnitude = "LENGTH"
 
Dim oUnit as String
oUnit = ""
 
Dim oGetDecimal as Double
Dim oGetExpo as Double
 
oUnitsSheetSettingAtt.GetMagnitudeValues oMagnitude, oUnit, oGetDecimal, oGetExpo
 
If (oUnit = "Inch") Then
 
 
 
            Dim oUnitInch as String
            oUnitInch = "Millimeter"
            oUnitsSheetSettingAtt.SetMagnitudeValues oMagnitude, oUnitInch, 6.000000, 3.000000
 
            oUnitsSheetSettingAtt.SaveRepositoryForUnits()
            oUnitsSheetSettingAtt.CommitForUnits()
            oUnitsSheetSettingAtt.Commit()
            MsgBox "The Current Unit is now: " & oUnitInch
 
 
End If

 

Here you can see where you use Commit and how it comes into play. Commit saves the current values of the setting attributes managed by the setting controller in a specific memory area. Successive calls to Commit overwrite the memory area. The values saved by the last call to Commit can be restored from that memory area using the Rollback method.

 

Magnitude is where you set the type of unit you want to change, in our case “Length” (as opposed to Angle, Time, Mass, etc.). Next, set the units to Millimeter or Inch. The numbers are then to set the exponential notation for values greater than 10e+/-.

 

Download the complete code from our CATIA Macros Download Page.

 

Now you know how to change units in CATIA. If there are any other terms you don’t understand then use the CATIA visual basic help file to figure it out.