Operation possible on parts, assemblies or drawings.

This operation provides access to the "Integer" options in the documents. For more information on using these parameters, see the API help.

This operation is for advanced users only.

The selection is made from a list of options corresponding to the enumerator " swUserPreferenceIntegerValue_e":

 

The value number is selected from a list. This number must be numeric. It can be entered using the keyboard or the drop-down list:                 

Version 6 corresponds to swDxfFormat_R2010 (see the API help for swDxfFormat_e Enumeration)

 


Example: How do I change the unit settings in a SOLIDWORKS document so that length is in mm and mass is in kg?


- 1. Set the system units to " custom."

The "swUnitSystem" option in the "Document Options (Integer)" list must be set to the enumerator " swUnitSystem_e," which contains:

swUnitSystem_CGS = 1

swUnitSystem_MKS = 2

swUnitSystem_IPS = 3

  swUnitSystem_Custom = 4

swUnitSystem_MMGS = 5


- 2. Change the units of length to " mm."

The "swUnitsMassPropLength" option in the "Document Options (Integer)" list must be set to the "swLengthUnit_e" enumerator, which contains:


swMM = 0

swCM = 1

swMETER = 2

swINCHES = 3

swFEET = 4

swFEETINCHES = 5

swANGSTROM = 6

swNANOMETER = 7

swMICRON = 8

swMIL = 9

swUIN = 10


- 3. Change the units of mass to " kg."

The "swUnitsMassPropMass" option in the "Document Options (Integer)" list must be equal to the enumerator " swUnitsMassPropMass_e," which contains:


swUnitsMassPropMass_Milligrams = 1

swUnitsMassPropMass_Grams = 2

  swUnitsMassPropMass_Kilograms = 3

swUnitsMassPropMass_Pounds = 4


Note 1:

To find these enumerators and their values, the easiest way is to record a macro. Here, for this same action, you'll find the values explained above.


Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e. swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e. swUnitsMassPropLength, 0, swLengthUnit_e.swMM)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e. swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Grams)

End Sub


However, the values (where the enumerators are stored) are not visible in the macro. To find the value contained in an enumerator, simply press F2 in the macro editor, and the Object Explorer will appear. By typing the enumerator’s name—for example , “swUnitsMassPropMass”—into the search box, you can view the variables and their values.

 

Note 2:

Using this method, you can control all SOLIDWORKS options

Checkbox (example: "Formatting/Always display text at the same size")

Integer (example: unit conversion as shown above)

Decimal number (example: "Annotation/Anchor Line Length")

Text (example: "Annotation/References/Next label")


Note 3:

Some options are related to one another, as in the example above.

If the system units had not been set to “custom,” changing the units of mass and length would have had no effect.


Note 4:

This allows you to adjust document options only (the "Document Properties" tab).

System options are not affected by batch processing.