VBA sketch deletes relation

Hi everyone
I want to make a VBA macro that removes ' edge-on-edge ' sketching relationships and wobbly constraints, such as converting entities, whether it's from an external part or another sketch of the same part

I am in the sketch to be dealt with
I run the macro that should check each element to see the type of constraint, if it's ' on edge › delete

I don't know how to select each item 1 by 1
I don't know how to check if it's equal to ' on edge ' or wobbly
I don't know how to remove the associated constraint

Here's my macro start

Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSketchMgr As SldWorks.SketchManager
Dim swSketch As SldWorks.Sketch
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim nSketchStatus As Long
Dim boolstatus As Boolean


Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSketchMgr = swModel.SketchManager
Set swSketch = swSketchMgr.ActiveSketch


If swSketch Is Nothing Then
MsgBox "Éditer une esquisse et relancer la macro"
Exit Sub
End If

'For i = 1 To Count
'selectionner i element
'if relation existante =sgOFFSETEDGE
'boolstatus = Part.Extension.SelectByID2(xx,  , ,, , , )
'swModel.EditDelete
'swModel.SketchManager.SketchConstraintsDel 1, "sgOFFSETEDGE"
'swModel.SketchConstraintsDel i, "sgOFFSETEDGE"
'Next i

swModel.ClearSelection2 True
End Sub

Item1.SLDPRT (120.0 KB)

Hello

Instead, use this API example and adapt it as needed: Get Sketch Relations Example (VBA) - 2021 - SOLIDWORKS API Help

1 Like

I have a bit of trouble seeing clearly, I'm not very good at vba if anyone has an idea

Hello @Bob_2000
Instead, explain what you're upset about in the code provided by @Cyril.f and then we can answer more specific questions.

I don't know what SkPoint ID variables are for, I don't see how to find the wobbly sides

The "SkPoint ID" and "SkSeg ID" are not variables but full text, to display in the debug window the point ID of the sketch (sk → sketch), and SkSeg the ID of the Segment.

You can notice that they are between " ", but above all that these words are not declared (with a dim for example), so cannot be variables.

ok but it doesn't tell me how to find the type of constraint of each selected element to know if it is wobbly

Hello
I didn't have time to test but there are filter criteria on what must scan this code. Basically, it's set to All and depending on the result, you can come across unidentified cases that can be wobbly sketches or other.
You would have to set the filter on the elements that are wobbly to make a specific loop on this status.
I don't have access to SW at least until the end of the week.

If anyone knows the parameters for odds
-Wobbly
-External
-Broken

For Wobbly Ribs IsDangling Method (IAnnotation) - 2018 - SOLIDWORKS API Help
See this topic (not tested):
https://r1132100503382-eu1-3dswym.3dexperience.3ds.com/?_gl=11jlxmvc_gaMjcxNTI5NDczLjE2NDAwNjkyNDQ._ga_XQJPQWHZHH*MTY3MDQxNDI5Ny42NS4xLjE2NzA0MTQzOTEuNTYuMC4w#community:yUw32GbYTEqKdgY7-jbZPg/iquestion:GjZHVgFpSo-VcVvyOZ1i9A
Test this track and give us feedback if possible.

And for a sketch:
https://help.solidworks.com/2018/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISketch~GetConstrainedStatus.html

I can't get away with it if someone has an idea for working code