Note - I am not very experienced with the SolidWorks API or programming in general - please be kind
Here is the relevant code. The lines in question are all the way at the bottom:
Code: Select all
Option Explicit
Const APPEND_SELECTION As Boolean = False
Const TYPE_NAME As String = "3DProfileFeature" '3DSketch
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
Dim swSelMgr As SldWorks.SelectionMgr
Set swSelMgr = swModel.SelectionManager
Dim Part As Object
Set Part = swApp.ActiveDoc
Dim bRet As Boolean
Dim i As Integer
Dim swFeat As SldWorks.Feature
Dim CurVal As Double
Dim MaxVal As Double
Dim MinVal As Double
Dim NewVal As Double
Dim IntegerSetting As Integer
If Not swModel Is Nothing Then
Dim vFeats As Variant
vFeats = GetAllFeaturesByType(swModel, TYPE_NAME)
swModel.Extension.MultiSelect2 vFeats, False, Nothing
'If swModel.Extension.MultiSelect2(vFeats, False, Nothing) = UBound(vFeats) + 1 Then
'Err.Raise vbError, "", "Failed to select features"
'End If
For i = 1 To swSelMgr.GetSelectedObjectCount
Set swFeat = swSelMgr.GetSelectedObject5(i)
If Not swFeat Is Nothing Then
bRet = swModel.EditSuppress2: 'Debug.Assert bRet
End If
Next i
Else
MsgBox "Please open model"
End If
'Reduce image quality
swModel.Extension.GetUserPreferenceDoubleValueRange swImageQualityShadedDeviation, CurVal, MinVal, MaxVal
NewVal = ((MaxVal - MinVal) * 0.2) + MinVal
swModel.SetUserPreferenceDoubleValue swImageQualityShadedDeviation, NewVal
'Reduce wireframe quality
swModel.SetUserPreferenceIntegerValue swImageQualityWireframeValue, 15
'Debug.Print swModel.swBOMPartNumberSource_e.swBOMPartNumber_ConfigurationName
'Set default BOM PN to Document Name - doesn't work yet
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swDefaultBOMPartNumberForNewConfig, swBOMPartNumberSource_e.swBOMPartNumber_DocumentName 'swBOMPartNumberSource_e.swBOMPartNumber_DocumentName
IntegerSetting = swModel.GetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swDefaultBOMPartNumberForNewConfig)
'Debug.Print IntegerSetting
End Sub