Hallo, ik kan geen gezicht selecteren en er vervolgens een kleur op leggen in mijn macro. Ik heb bedacht hoe ik het voor een functie moet doen, maar het lukt me niet om de code aan te passen om het voor één kant te laten werken. Probeer je hoe je het moet doen?
Dim swApp als SldWorks.SldWorks Dim swModel als SldWorks.ModelDoc2 Dim swModelExt als ModelDocExtension Dim deel als SldWorks.PartDoc Dim swConfig als SldWorks.Configuration Dim boolstatus als Booleaanse Zon swSelMgr As SldWorks.SelectionMgr Dim swFeat als SldWorks.Feature
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim vProp As Variant
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
If swModel Is Nothing Then MsgBox "Ouvrir une pièce": Exit Sub
If swModel.GetType <> swDocumentTypes_e.swDocPART Then MsgBox "Ouvrir une pièce": Exit Sub
If swSelMgr.GetSelectedObjectCount2(-1) = 0 Then MsgBox "Sélectionner une face": Exit Sub
Set swFace = swSelMgr.GetSelectedObject6(1, -1)
vProp = swFace.MaterialPropertyValues
If IsEmpty(vProp) Then vProp = swModel.MaterialPropertyValues
Debug.Print "Couleur courante: (" & vProp(0) * 255# & ", " & vProp(1) * 255# & ", " & vProp(2) * 255# & ")"
bRet = swModel.SelectedFaceProperties(RGB(0, 255, 0), vProp(3), vProp(4), vProp(5), vProp(6), vProp(7), vProp(8), False, "")
swModel.ClearSelection2 True
End Sub
Is het mogelijk om meerdere gezichten te selecteren en vervolgens de macro te starten om de kleur in te voeren, of moet je gezicht voor gezicht staan zoals de huidige code?
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim swEnt As SldWorks.Entity
Dim vProp As Variant
Dim bRet As Boolean
Dim i As Integer
Dim vFaces As New Collection
Dim vFace As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
If swModel Is Nothing Then MsgBox "Ouvrir une pièce": Exit Sub
If swModel.GetType <> swDocumentTypes_e.swDocPART Then MsgBox "Ouvrir une pièce": Exit Sub
If swSelMgr.GetSelectedObjectCount2(-1) = 0 Then MsgBox "Sélectionner une face": Exit Sub
For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)
vFaces.Add swSelMgr.GetSelectedObject6(i, -1)
Next
For Each vFace In vFaces
Set swFace = vFace
Set swEnt = swFace
vProp = swFace.MaterialPropertyValues
If IsEmpty(vProp) Then vProp = swModel.MaterialPropertyValues
Debug.Print "Couleur courante: (" & vProp(0) * 255# & ", " & vProp(1) * 255# & ", " & vProp(2) * 255# & ")"
swEnt.Select4 False, Nothing
bRet = swModel.SelectedFaceProperties(RGB(0, 255, 0), vProp(3), vProp(4), vProp(5), vProp(6), vProp(7), vProp(8), False, "")
Next vFace
swModel.ClearSelection2 True
End Sub