Hello, all!
I'm currently working on a solidworks API macro. In our current process, special geometry on sheet-metal parts for etching and opening pathing is done by creating a sketch of the desired cut/etch, and then later, before saving to a DXF, creating the layer "ETCH" or "OPEN", selecting the sketch from the drawing view feature tree, and using "convert entities".
Thus, certain sketches are on the "ETCH" layer, and others are on the "OPEN" layer.
In my current code, I can locate the sketches of interest and create the drawing layers, but I can't seem to figure out how to properly select and convert the sketches. I've tried selecting both the sketch feature and the sketch segments and using SketchUseEdge3 (which returns true, yet doesn't seem to convert entities as the UI does...), as well as trying to simply assign segment.layer, but both have come up short.
Am I targeting the incorrect sketch, somehow? Can I iterate through the view's feature tree directly in some way, rather than going through the part's features?
Attached is an image of the drawing tree, noting the sketches I want to target and put onto two different DXF layers. Simplified code is below.
Set swApp = CreateObject("SldWorks.Application")
Debug.Print "Starting right nooooowwww"
For i = 1 To pathList.Count
Set swModel = swApp.OpenDoc(pathList(i), 1) 'Can I force-open a drawing of the doc if I make the integer 3?
'Set swDraw = swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2025\\templates\\Drawing.drwdot", 0#, 0#, 0#)
Set swDraw = swApp.OpenDoc4("C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\DXF_Transfer\\SLDDXF.SLDDRW", 3, 0, "", longstatus)
'Set swDraw = swApp.activateDoc("SLDDXF - Sheet1")
Set layMgr = swDraw.GetLayerManager
retInt = layMgr.AddLayer("ETCH", "", RGB(0, 255, 0), 0, 0)
retInt = layMgr.AddLayer("OPEN", "", RGB(255, 0, 0), 0, 0)
'place view
swDraw.ShowConfiguration "Default"
Set swView = swDraw.CreateFlatPatternViewFromModelView3(pathList(i), "Default", 0, 0, 0, True, False)
swDraw.ViewZoomtofit2
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
Set sktMgr = swModel.SketchManager
Set swFeat = swModel.FirstFeature
Do While Not swFeat Is Nothing:
swFeatName = swFeat.GetTypeName2
If swFeatName = "ProfileFeature" Or swFeatName = "3DProfileFeature" Then
sketchTitle = swFeat.Name
If sketchTitle Like "ETCH_*" Then
Debug.Print "Found an Etch"
retInt = layMgr.SetCurrentLayer("ETCH")
Set swSketch = swFeat.GetSpecificFeature2
layRet = swSketch.Select2(False, 0)
Debug.Print layRet
'swView.Select2 False, 0
'segList = swSketch.GetSketchSegments
'Dim j As Integer
'For j = 0 To UBound(segList)
' Set segment = segList(j)
' segment.Layer = "ETCH"
' Debug.Print layRet
'Next j
swModel.EditSketch
layRet = sktMgr.SketchUseEdge3(True, True)
Debug.Print layRet
ElseIf sketchTitle Like "OPEN_*" Then
Debug.Print "Found a Open"
'retInt = layMgr.SetCurrentLayer("OPEN")
'layRet = swFeat.Select2(False, 0)
'swModel.EditSketch
'layRet = swView.Select2(False, 0)
'layRet = sktMgr.SketchUseEdge3(False, True)
'Debug.Print layRet
End If
End If
Set swFeat = swFeat.GetNextFeature
Loop
