Macro to change Decimal Length
Macro to change Decimal Length
No matter how many times I set the length of Decimals to .12 but after a while it reverts to .123456
- -
The templates I use are set to .12 but as soon as I add several features or edit an existing feature, it goes back to .123456
Now 2 questions:
1- Does anybody know why it happens or how to prevent it?
2- I'm tired of opening the options and correct it every several minutes. Is there a macro that can change it to .12
I appreciate any kind of help/advice.
- -
The templates I use are set to .12 but as soon as I add several features or edit an existing feature, it goes back to .123456
Now 2 questions:
1- Does anybody know why it happens or how to prevent it?
2- I'm tired of opening the options and correct it every several minutes. Is there a macro that can change it to .12
I appreciate any kind of help/advice.
1. As you mentioned, this is a document template setting so every new part should match your template. I've never seen this change as I'm working on something without me explicitly accessing the menu and changing it.
2. Yes, it's possible. The code below should set it to 2 for your active document. Note that this only affects the linear "Length" decimal places that you've circled in your screenshot.
Go to Tools -> Macro -> New and delete everything in the new macro document and paste the below code in there and save.
Go to full post2. Yes, it's possible. The code below should set it to 2 for your active document. Note that this only affects the linear "Length" decimal places that you've circled in your screenshot.
Go to Tools -> Macro -> New and delete everything in the new macro document and paste the below code in there and save.
Code: Select all
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swModelExtension As ModelDocExtension
Set swApp = Application.SldWorks '
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swModelExtension = swModel.Extension
swModelExtension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified, 2
End If
End Sub
Re: Macro to change Decimal Length
1. As you mentioned, this is a document template setting so every new part should match your template. I've never seen this change as I'm working on something without me explicitly accessing the menu and changing it.
2. Yes, it's possible. The code below should set it to 2 for your active document. Note that this only affects the linear "Length" decimal places that you've circled in your screenshot.
Go to Tools -> Macro -> New and delete everything in the new macro document and paste the below code in there and save.
2. Yes, it's possible. The code below should set it to 2 for your active document. Note that this only affects the linear "Length" decimal places that you've circled in your screenshot.
Go to Tools -> Macro -> New and delete everything in the new macro document and paste the below code in there and save.
Code: Select all
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swModelExtension As ModelDocExtension
Set swApp = Application.SldWorks '
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swModelExtension = swModel.Extension
swModelExtension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified, 2
End If
End Sub
Re: Macro to change Decimal Length
Is it possible this setting is somehow conflicting with the Units setting?
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Re: Macro to change Decimal Length
Yea, the units precision is usually not much of an issue, it's the setting under dimensions where you usually have to change it on drawings. I wouldn't want to design anything with a 2 decimal precision, everything rounding to the nearest 10th doesn't sound like a great idea.
Re: Macro to change Decimal Length
In my short testing, one appears to control the display dimension precision and the other controls the decimal places of the dimension in other places in the UI like the Edit Dimension window.
Re: Macro to change Decimal Length
I've never seen one conflict with the other, but I've never seen the document unit precision change either.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Re: Macro to change Decimal Length
The macro works just fine.AlexB wrote: ↑Thu Mar 09, 2023 8:15 am 1. As you mentioned, this is a document template setting so every new part should match your template. I've never seen this change as I'm working on something without me explicitly accessing the menu and changing it.
2. Yes, it's possible. The code below should set it to 2 for your active document. Note that this only affects the linear "Length" decimal places that you've circled in your screenshot.
Go to Tools -> Macro -> New and delete everything in the new macro document and paste the below code in there and save.
Code: Select all
Option Explicit Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As ModelDoc2 Dim swModelExtension As ModelDocExtension Set swApp = Application.SldWorks ' Set swModel = swApp.ActiveDoc If Not swModel Is Nothing Then Set swModelExtension = swModel.Extension swModelExtension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified, 2 End If End Sub
I really appreciate your help.
Thank you.
Re: Macro to change Decimal Length
Thanks to all. For now the macro works great.
I will have an eye on the timing this setting is changed and drill down what is causing this.
Will update this thread if I find anything on this.
Thanks again.
I will have an eye on the timing this setting is changed and drill down what is causing this.
Will update this thread if I find anything on this.
Thanks again.
Re: Macro to change Decimal Length
Hi,
I would like to have a macro (run on a drawing document) change from this: to this: Code as posted previously:
I run the posted code, I get this:
I changed the 2 to a 1 in the above code:
Run it and I get this:
I am not sure how to do this.
edit:
I would like it to change the Primary & Dual precision. Not the units "Decimals"
Any help would be appreciated.
Thanks
I would like to have a macro (run on a drawing document) change from this: to this: Code as posted previously:
Code: Select all
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swModelExtension As ModelDocExtension
Set swApp = Application.SldWorks '
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swModelExtension = swModel.Extension
swModelExtension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified, 2
End If
End Sub
edit:
I would like it to change the Primary & Dual precision. Not the units "Decimals"
Any help would be appreciated.
Thanks
Re: Macro to change Decimal Length
swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces is for properties under Unit page in Document Properties
If you are planning to change the precision under Dimensions page in Document properties, you will need to use
swUserPreferenceIntegerValue_e.swDetailingLinearDimPrecision and swUserPreferenceIntegerValue_e.swDetailingAltLinearDimPrecision
Ref:
https://help.solidworks.com/2016/englis ... nsions.htm
See code below:
Code: Select all
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swModelExtension As ModelDocExtension
Set swApp = Application.SldWorks '
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swModelExtension = swModel.Extension
swModelExtension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swDetailingLinearDimPrecision, swUserPreferenceOption_e.swDetailingDimension, 2
swModelExtension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swDetailingAltLinearDimPrecision, swUserPreferenceOption_e.swDetailingDimension, 2
End If
End Sub
Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
Re: Macro to change Decimal Length
EXACT same issue. One that I've been fighting since upgrade from 2022 to 2023. You name it we tried it. The macro works but since it happens nearly 2000000 times an hour it was not a viable option for me.
I think it's fixed. Fingers crossed. Two days ago I completely uninstalled SW. Erased all SW registry entries. Re-installed and it's been performing as it should. It did burp once, but I think that was a legacy from a previous model.
You must preform a "clean" uninstall. Find instructions from your VAR and follow them exactly.
Good luck
DDD
I think it's fixed. Fingers crossed. Two days ago I completely uninstalled SW. Erased all SW registry entries. Re-installed and it's been performing as it should. It did burp once, but I think that was a legacy from a previous model.
You must preform a "clean" uninstall. Find instructions from your VAR and follow them exactly.
Good luck
DDD
-
- Posts: 34
- Joined: Wed Jul 28, 2021 9:09 am
- x 1
- x 31
Re: Macro to change Decimal Length
I have had the same issue. There was a bug introduced in 2023 that would change the decimal precision to 6 decimal places at random times and wasn't anything to do with any of the user settings. It appears that they have found that bug and fixed it in 2023 SP3. I have not had any issues with this since updating to 2023 SP3
-
- Posts: 1
- Joined: Tue Aug 01, 2023 12:06 am
Re: Macro to change Decimal Length
hii
How do we change the unit of the parts in the assembly, what kind of macro should be
"
Const UNIT_SYSTEM As Integer = swUnitSystem_e.swUnitSystem_MMGS 'sets the custom units individually as per the constants below
Const MMGS_LENGTH_UNIT As Integer = swLengthUnit_e.swMETER
Const MMGS_ANGLE_UNIT As Integer = swAngleUnit_e.swDEGREES
Const MMGS_MASS_UNIT As Integer = swUnitsMassPropMass_e.swUnitsMassPropMass_Grams
Const MMGS_VOLUME_UNIT As Integer = swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3
Const MMGS_TIME_UNIT As Integer = swUnitsTimeUnit_e.swUnitsTimeUnit_Second
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitSystem, swUserPreferenceOption_e.swDetailingNoOptionSpecified, UNIT_SYSTEM
If UNIT_SYSTEM = swUnitSystem_e.swUnitSystem_Custom Then
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsLinear, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_LENGTH_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsDualLinear, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_LENGTH_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsAngular, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_ANGLE_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsMassPropLength, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_LENGTH_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsMassPropMass, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_MASS_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_VOLUME_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsTimeUnits, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_TIME_UNIT
End If
Else
Err.Raise vbError, "", "Model is not opened"
End If
End Sub
"
How do we change the unit of the parts in the assembly, what kind of macro should be
"
Const UNIT_SYSTEM As Integer = swUnitSystem_e.swUnitSystem_MMGS 'sets the custom units individually as per the constants below
Const MMGS_LENGTH_UNIT As Integer = swLengthUnit_e.swMETER
Const MMGS_ANGLE_UNIT As Integer = swAngleUnit_e.swDEGREES
Const MMGS_MASS_UNIT As Integer = swUnitsMassPropMass_e.swUnitsMassPropMass_Grams
Const MMGS_VOLUME_UNIT As Integer = swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3
Const MMGS_TIME_UNIT As Integer = swUnitsTimeUnit_e.swUnitsTimeUnit_Second
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitSystem, swUserPreferenceOption_e.swDetailingNoOptionSpecified, UNIT_SYSTEM
If UNIT_SYSTEM = swUnitSystem_e.swUnitSystem_Custom Then
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsLinear, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_LENGTH_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsDualLinear, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_LENGTH_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsAngular, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_ANGLE_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsMassPropLength, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_LENGTH_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsMassPropMass, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_MASS_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_VOLUME_UNIT
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitsTimeUnits, swUserPreferenceOption_e.swDetailingNoOptionSpecified, CUSTOM_TIME_UNIT
End If
Else
Err.Raise vbError, "", "Model is not opened"
End If
End Sub
"