×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Modifying unit system with macro

Modifying unit system with macro

Modifying unit system with macro

(OP)

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.

RE: Modifying unit system with macro

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
 

RE: Modifying unit system with macro

(OP)
I appreciate that. Thanks. I'm only working with angles and length, so changes mm to in will do the trick.

RE: Modifying unit system with macro

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: http://www.lennyworks.com/solidworks/default.asp?ID=20

Flores

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources