Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modifying unit system with macro 1

Status
Not open for further replies.

razzendahcuben

Mechanical
Jan 10, 2009
79
Code:
Private sub main()

Dim swApp As SldWorks.SldWorks
Dim swDoc As ModelDoc2

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc

    '3 is the const value for IPS
    swDoc.SetUserPreferenceIntegerValue swUnitSystem, 3

End sub

My default unit system is MMGS. When I run this macro and go into Tools-->Options-->Units it does have IPS selected. But the units in the document don't actually change---its still in MMGS.

Likewise, this does nothing either:
swDoc.SetUserPreferenceToggle swUnitSystem_IPS, True

What am I doing wrong? Thanks.
 
Replies continue below

Recommended for you

I don't think you can programmatically change the "Unit System" to IPS or MMGS, or any of the others.

But you can change each of the units individually (i.e. Length, Alt Units Length, Angular Units, Mass, etc.)

This will get your document units switched to inches.
Code:
    swModel.SetUserPreferenceIntegerValue swUnitsLinear, swINCHES
Ken
 
I appreciate that. Thanks. I'm only working with angles and length, so changes mm to in will do the trick.
 
I use "UnitManager" from Lenny's site. There are different toggles to switch from mm to inches, and these can be customized to your liking by changing an .ini file. For example, 2 decimal places, 4 decimal places, milimeters 2 decimal places etc.

Here is what my .ini looks like:
Code:
' Unit Name                Typ, Fra, Den/Plc
[UNITS]
"Inch (Decimal 2)",           3,   1,   2
"Inch (Decimal 4)",           3,   1,   3
"Inch (Fraction)",            3,   2,   32
"Millimeter (decimal 2)",     0,   0,   2

Download the macro here:
Flores
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor