Hello everyone.
Wishing to create a macro in order to automate the creation of a function to move face => to the surface + subsequently other function, I wrote the following code.
However, the function is not created and I really don't see the why or how. I have selected my starting and finishing faces with the required marks but nothing is created.
Do you have an idea??
Dim swApp As Object
Dim swmodel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeat As SldWorks.Feature
Dim swMoveFaceFeat As SldWorks.MoveFaceFeatureData
Sub main()
Set swApp = Application.SldWorks
Set swmodel = swApp.ActiveDoc
'Verify that the open file is a part file
If swmodel. GetType <> swDocPART Then
MsgBox "Please open a part file", vbApplicationModal + vbOKOnly + vbCritical, "Part file required"
Exit Sub
End If
Dim Selectmanager As SelectionMgr
Set Selectmanager = swmodel. SelectionManager' recover selection
swmodel. ClearSelection2 True ' Clear Selection
' Loop for waiting selection
Dim bool1 As Boolean
Sun y
bool1 = False
Do Until bool1 = True
If Selectmanager.GetSelectedObjectType3(1, -1) = 2 Then
bool1 = True
End If
For y = 1 To 50000
DoEvents
Next y
Loop
Dim coord as variant
Coord = Selectmanager.GetSelectionPointInSketchSpace2(1, -1)
Dim x0 As Single
Sun y0 As Single
Dim z0 As Single
x0 = Coord(0)
y0 = Coord(1)
z0 = Coord(2)
swmodel. ClearSelection2 (True)
Set swModelDocExt = swmodel. Extension
Set swFeatMgr = swmodel. FeatureManager
swmodel. ClearSelection2 (True)
' Loop for waiting selection
bool1 = False
Do Until bool1 = True
If Selectmanager.GetSelectedObjectType3(1, -1) = 2 Then
bool1 = True
End If
For y = 1 To 50000
DoEvents
Next y
Loop
Coord = Selectmanager.GetSelectionPointInSketchSpace2(1, -1)
x1 = Coord(0)
y1 = Coord(1)
z1 = Coord(2)
swmodel. ClearSelection2 (True)
bret = swmodel. Extension.SelectByID2("", "FACE", x0, y0, z0, True, 1, Nothing, 0)
bret = swmodel. Extension.SelectByID2("", "FACE", x1, y1, z1, True, 8, Nothing, 0)
Set swFeat = swFeatMgr.InsertMoveFace3(swMoveFaceTypeTranslate, False, 0, 0, Nothing, Nothing, swEndConditions_e.swEndCondUpToSurface, 0)
End Sub
Thank you in advance
Happydad