Need Macro to change length units

I need a macro to open each component in an assembly and change the document units to 0.123.
I tried but my programming knowledge is simply too limited.

Thanks in advance!

Macro recorded should record this for modification of a single part. Then you can run this macro for all components in the assembly using Batch+: https://cadplus.xarial.com/batch/assembly/ (just test it on a spare part before running batch to make sure it is modifying units correctly). Here is the video: https://www.youtube.com/watch?v=5akBj5gd68Q. The video of a newer version (private beta) so UI may differ a little.

Would this work on a PDM system too artem ?

berg_lauritz, yes, as long as the files are locally cached. The future version will have full support for PDM so no need to cache files locally.

artem I installed CAD+. This is a wonderful tool! Then I recorded a macro to change my units and ran a batch to change all of the units. I had to make the macro save the file after changing the units b/c for some reason the files would fail if I told CAD+ to save it. But, hey, it worked!

Jaylin Hochstetler , great, glad it helped. Do you remember what was the error when you check ‘Automatically Save’? I am now building a new version of CAD+ and will be keen to fix this issue as well.

It didn’t give me any errors but in the summary it said the files failed. And if I went into the files I ran the macro on the units weren’t changed. Does CAD+ only save it if the SW gives a save warning? The reason I am asking is b/c I noticed if I change the units and close the document it won’t give a save warning neither will it save it.

I have the following code that works on one file. It works, but has the strange effect of turning on Scene Shadows and Reflections for inactive configurations. Here’s the code

Option Explicit
Sub main()
    Dim swApp                       As SldWorks.SldWorks
    Dim swModel                     As SldWorks.ModelDoc2
    Dim BoolStatus                  As Boolean
    
    Dim SystemOfUnits               As Integer
    Dim DualSystemOfUnits           As Integer
    Dim PrimaryLengthDecPlaces      As Integer
    Dim AngularUnits                As Integer
    Dim MassDecPlaces               As Integer
    Dim DualLengthDecPlaces         As Integer
    Dim AngularDecPlaces            As Integer
    Dim DecimalRoundingMethod       As Integer
    Dim TimeDecPlaces               As Integer
    
    SystemOfUnits = swUnitSystem_e.swUnitSystem_IPS
    DualSystemOfUnits = swMM
    PrimaryLengthDecPlaces = 3
    DualLengthDecPlaces = 1
    AngularUnits = swDEGREES
    AngularDecPlaces = 0
    MassDecPlaces = 3
    DecimalRoundingMethod = swUnitsDecimalRounding_e.swUnitsDecimalRounding_HalfAway
    TimeDecPlaces = 2
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    If swModel Is Nothing Then
        swApp.SendMsgToUser2 "No drawing document open.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOkCancel
        Exit Sub
    End If

    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, SystemOfUnits)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, DualSystemOfUnits)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, 0, PrimaryLengthDecPlaces)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinearDecimalPlaces, 0, DualLengthDecPlaces)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsAngular, 0, AngularUnits)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsAngularDecimalPlaces, 0, AngularDecPlaces)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropDecimalPlaces, 0, MassDecPlaces)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDecimalRounding, 0, DecimalRoundingMethod)
End Sub

Could you attach your file to check.

Sure. Here’s the part file I’m testing with:

No changes on my end. Can you please share a video showing the concern.

Try this swp with the part I attached earlier. Here it is:
Macro1.swp (46.5 KB)

Have used the cods you posted earlier and now even with this macro I see no changes in the model. Can you post pictures/video showing before and after?

I’ve been unsuccessfully looking for a similar application with a different function.: A simple macro (or something similar) to change all the documents’ units of measure in an assembly to MMGS. Any suggestions or pointers?