I get the message execution error 91 object variable not defined for line swDispDim.MarkedForDrawing = False
Dim swApp As SldWorks.SldWorks Dim swmodel As SldWorks.ModelDoc2 Dim swdraw As SldWorks.DrawingDoc Dim Reponse As Integer Dim swDispDim As SldWorks.DisplayDimension
Sub main()
Set swApp = Application.SldWorks Set swmodel = swApp.ActiveDoc
Set swApp = Application.SldWorks Set swmodel = swApp.ActiveDoc If swmodel Is Nothing Then swApp.SendMsgToUser2 "No documents open", swMbWarning, swMbOk Exit Sub End If
If swmodel. GetType <> 1 Then swApp.SendMsgToUser2 "Open Part File", swMbWarning, swMbOk Exit Sub End If
Answer = MsgBox("Have you edited your sketch", vbYesNo)
You have to define swDispDim before you can access it, for example with GetSelectedObject6 if the dimensions are already selected
For n = 1 to swModel.SelectionManager.GetSelectedObjectCount2
Set swDispDim = swModel.SelectionManager.GetSelectedObject6(n, -1)
swDispDim.MarkedForDrawing = False
Next n
or a faster method that doesn't require selecting dimensions beforehand:
Dim swDispDim As DisplayDimension
set swDispDim = swView.GetFirstDisplayDimension5
While not swDispDim Is Nothing
swDispDim.MarkedForDrawing = False
set swDispDim = swDispDim.GetNext5
Wend
This will work on a sketch that is open or selected in the tree
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSketch As SldWorks.Sketch
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDispDim As SldWorks.DisplayDimension
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
If swModel Is Nothing Then
swApp.SendMsgToUser2 "Pas de documents ouvert", swMbWarning, swMbOk
Exit Sub
End If
If swModel.GetType <> swDocumentTypes_e.swDocPART Then
swApp.SendMsgToUser2 "Ouvrir un fichier pièce", swMbWarning, swMbOk
Exit Sub
End If
If swSelMgr.GetSelectedObjectType3(1, -1) = swSelectType_e.swSelSKETCHES Then
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Else
Set swSketch = swModel.SketchManager.ActiveSketch
Set swFeat = swSketch
End If
If swFeat Is Nothing Then
swApp.SendMsgToUser2 "Ouvrir ou sélectionner une esquisse", swMbWarning, swMbOk
Exit Sub
End If
Set swDispDim = swFeat.GetFirstDisplayDimension
While Not swDispDim Is Nothing
swDispDim.MarkedForDrawing = False
Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
Wend
End Sub