Andy Kuo

Why my marco always stop on Sketch?

Discussion created by Andy Kuo on Feb 20, 2020
Latest reply on Feb 24, 2020 by Andy Kuo

Here is my Marco, I draw a rectangle and want to cut it.

I can draw rectangle and made Extrusion, then I can draw a sketch again. But it always stop on here, can't execute FeatureCut4 command. Why?

 

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks


' New Document
Dim swSheetWidth As Double
swSheetWidth = 0
Dim swSheetHeight As Double
swSheetHeight = 0
Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2019\templates\零件.prtdot", 0, swSheetWidth, swSheetHeight)
Dim swPart As PartDoc
Set swPart = Part
swApp.ActivateDoc2 "零件2", False, longstatus
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized

'draw rectangle

Set Part = swApp.ActiveDoc
'(2)
Set SketchManager = Part.SketchManager
'(3)
vSkLines = SketchManager.CreateCenterRectangle(0, 0, 0, 1, 1, 1)
Part.ClearSelection2 True
'(4)
Set myFeature = Part.FeatureManager.FeatureExtrusion3(True, False, False, 0, 0, 1, 1.5, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False)
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstToRectEntity, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True)
vSkLines = Part.SketchManager.CreateCenterRectangle(0, 0, 0, 0.5, 0.5, 0)
Part.ClearSelection2 True
Set myFeature = Part.FeatureManager.FeatureCut4(True, False, False, 0, 0, 0.01, 0.01, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, False, True, True, True, True, False, 0, 0, False, False)
Part.SelectionManager.EnableContourSelection = False
'save file
longstatus = Part.SaveAs3("C:\Users\andy.kuo\Desktop\solidworks marco\new create rectangle 0220.SLDPRT", 0, 2)

End Sub

Attachments

Outcomes