Otrzymuję komunikat o błędzie wykonania 91 zmienna obiektu nie jest zdefiniowana dla linii swDispDim.MarkedForDrawing = False
Dim swApp jako SldWorks.SldWorks Dim swmodel As SldWorks.ModelDoc2 Przyciemnij swdraw jako SldWorks.DrawingDoc Dim Reponse As Liczba całkowita Dim swDispDim As SldWorks.DisplayDimension
Przed uzyskaniem do niego dostępu należy zdefiniować swDispDim, na przykład za pomocą GetSelectedObject6, jeśli wymiary są już wybrane
For n = 1 to swModel.SelectionManager.GetSelectedObjectCount2
Set swDispDim = swModel.SelectionManager.GetSelectedObject6(n, -1)
swDispDim.MarkedForDrawing = False
Next n
lub szybsza metoda, która nie wymaga wcześniejszego wybierania wymiarów:
Dim swDispDim As DisplayDimension
set swDispDim = swView.GetFirstDisplayDimension5
While not swDispDim Is Nothing
swDispDim.MarkedForDrawing = False
set swDispDim = swDispDim.GetNext5
Wend
Będzie to działać na szkicu, który jest otwarty lub wybrany w drzewie
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