I created a macro that allows you to reduce the image quality, facetization and curve in library parts to optimize their use. The difficulty is that I can only run when the part is open on Solidworks.
Do you know any method to run this task directly with the Task Scheduler by choosing the desired directory?
Thanks in advance
If you have the MyCadtools tool you can do it with Integration otherwise take advantage of the 1 month trial version!
In 1 you select your file.
In 2 you create a new rule
In 3 the systematic condition that you drag onto the AND folder
In 4 Operation Miscellaneous, Launch of a macro
In 5 you fill in the macro (path to go and find)
In 6 the method (Main?)
In 7 you drag your macro into operation
In 8 you filter if necessary (Part, Assembly, Drawing)
Finally apply
Solidworks will then batch process the picklist 1 by one and apply your macro to it.
And I forgot just below action you can change if you save or not by exiting. (for your case saved the modification)
Hello
indeed it must be the main method
Here's the macro
Option Explicit
’ ******************************************************************************
' by F.PENNERAS
' DEC 27, 2023
’ ******************************************************************************
Early bound variables
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim Part As SldWorks.ModelDoc2
' Variables To Add (Variable Variables)
Dim CurVal As Double
Dim MaxVal As Double
Dim MinVal As Double
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swTextFormat As SldWorks.TextFormat
Dim TextFormatObj As Object
Dim ModelDocExtension As ModelDocExtension
Sub main()
• Connection to the currently active SolidWorks document
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set Part = swApp.ActiveDoc
Set ModelDocExtension = Part.Extension
'Error handler if no documents are loaded
If Part Is Nothing Then MsgBox "A Solid Works file must be active!", vbCritical: Exit Sub
' Get the current, minimum, and maximum values from the image quality shading deviation preferences.
' Load these values into the variables 'CurVal', 'MinVal' and 'MaxVal'.
swDoc.Extension.GetUserPreferenceDoubleValueRange swImageQualityShadedDeviation, CurVal, MinVal, MaxVal
' Sets a new value for the shading deviation
swDoc.SetUserPreferenceDoubleValue swImageQualityShadedDeviation, MaxVal
' Uncheck the 'Optimize Edge Length' checkbox.
Part.SetUserPreferenceToggle swImageQualityUseHighQualityEdgeSize, False
' Uncheck the 'Save Facetization' box.
Part.SetUserPreferenceToggle swImageQualitySaveTesselationWithPartDoc, False
' Uncheck the 'Improve curve quality' box.
Part.SetUserPreferenceToggle swImageQualityWireframeHighCurveQuality, False
' Set a new value for 'Wireframe resolution and high quality HLR/HLV'.
Part.SetUserPreferenceIntegerValue swImageQualityWireframeValue, 1
End Sub
You can find the link to the installation of the MyCadTools tools here:
1-month trial version.
Then you use Integration and see the tips and image from the previous post to guide you.
It's perfect I'll test it, thank you very much
Test it on 2-3 pieces to see and be careful it must be accessible in writing.
But already used and it works very well (if the macro is functional)
it's at the top of it to work the first time! The big big time saver! 4 minute per piece save!!
Thank you so much
Yes, that's why we invested in MYcad tools! Because it is very useful for batch tasks.
And the blow for us is largely cushioned over the year
You can automate your macro in SolidWorks Task Scheduler by using a workaround. First, save your macro as a separate file. Then, create a batch script that opens SolidWorks, loads each part from the desired directory, and runs the macro on it. You can set this batch script to run at scheduled times through Task Scheduler. Unfortunately, SolidWorks Task Scheduler doesn’t natively support running macros directly, so this method adds a bit of automation. You might also explore SolidWorks PDM if you have access, as it has more robust automation options.