Need Macro to change length units
- Jaylin Hochstetler
- Posts: 387
- Joined: Sat Mar 13, 2021 8:47 pm
- Location: Michigan
- x 380
- x 355
- Contact:
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!
I tried but my programming knowledge is simply too limited.
Thanks in advance!
A goal is only a wish until backed by a plan.
Re: Need Macro to change length units
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: The video of a newer version (private beta) so UI may differ a little.
Thanks,
Artem
xarial.com - making your CAD better
codestack.net - SOLIDWORKS API macros and tutorials
Artem
xarial.com - making your CAD better
codestack.net - SOLIDWORKS API macros and tutorials
-
- Posts: 423
- Joined: Tue Mar 09, 2021 10:11 am
- x 439
- x 233
Re: Need Macro to change length units
Would this work on a PDM system too @artem ?
Re: Need Macro to change length units
@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.
Thanks,
Artem
xarial.com - making your CAD better
codestack.net - SOLIDWORKS API macros and tutorials
Artem
xarial.com - making your CAD better
codestack.net - SOLIDWORKS API macros and tutorials
- Jaylin Hochstetler
- Posts: 387
- Joined: Sat Mar 13, 2021 8:47 pm
- Location: Michigan
- x 380
- x 355
- Contact:
Re: Need Macro to change length units
@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!
A goal is only a wish until backed by a plan.
Re: Need Macro to change length units
@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.
Thanks,
Artem
xarial.com - making your CAD better
codestack.net - SOLIDWORKS API macros and tutorials
Artem
xarial.com - making your CAD better
codestack.net - SOLIDWORKS API macros and tutorials
- Jaylin Hochstetler
- Posts: 387
- Joined: Sat Mar 13, 2021 8:47 pm
- Location: Michigan
- x 380
- x 355
- Contact:
Re: Need Macro to change length units
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.
A goal is only a wish until backed by a plan.
Re: Need Macro to change length units
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
Code: Select all
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
Re: Need Macro to change length units
Could you attach your file to check.loebotomy@gmail.com wrote: ↑Sat Feb 12, 2022 5:37 pm 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.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Need Macro to change length units
Sure. Here's the part file I'm testing with:
- Attachments
-
- Temp.SLDPRT
- (198.72 KiB) Downloaded 100 times
Re: Need Macro to change length units
No changes on my end. Can you please share a video showing the concern.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Need Macro to change length units
Try this swp with the part I attached earlier. Here it is:
- Attachments
-
- Macro1.swp
- (46.5 KiB) Downloaded 135 times
Re: Need Macro to change length units
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?loebotomy@gmail.com wrote: ↑Sun Feb 13, 2022 6:04 pm Try this swp with the part I attached earlier. Here it is:
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
-
- Posts: 9
- Joined: Wed Apr 07, 2021 1:04 pm
- Location: Olar, South Carolina
- x 3
- Contact:
Re: Need Macro to change length units
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?Jaylin Hochstetler wrote: ↑Tue May 04, 2021 5:00 pm 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!