Hello I'm looking to remove the wobbly VBA sides of a part
if you copy a function from one part to another it loses the constraints of the sketch and I don't know how to remove these constraints
I started from this example but I can't find how to identify the constraints or problem sides
Sub main()
'Sélectionner une esquisse
'
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swSketch As SldWorks.Sketch
Dim vSketchSeg As Variant
Dim vConstraint As Variant
Dim i As Long
Dim j As Long
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Set swSketch = swFeat.GetSpecificFeature2
Debug.Print "Sketch = " & swFeat.Name
Debug.Print ""
Debug.Print " SketchConstraintStatus fully constrained = " & swSketch.GetConstrainedStatus
Debug.Print ""
' Put sketch into edit mode to get access
' to constraint information for each segment
' in the sketch
swModel.EditSketch
vSketchSeg = swSketch.GetSketchSegments
For i = 0 To UBound(vSketchSeg)
vConstraint = vSketchSeg(i).GetConstraints
For j = 0 To UBound(vConstraint)
Debug.Print " SketchSegConstraint[" & i & "] = " & vConstraint(j)
Next j
Next i
' Exit edit mode and do not rebuild the model
swModel.InsertSketch2 True
End Sub
Hello You would need to add code based on the code in this example: Get Types of Entities Attached to Selected Annotation Example (VBA) - 2022 - SOLIDWORKS API Help Just replace if you're on 2022 the vAttEntTypeArr = swAnn.GetAttachedEntityTypes2 with vAttEntTypeArr = swAnn.GetAttachedEntityTypes. If in the result of the debug print Type of attached entity(" & i & ") as defined in swSelectType_e = " & vAttEntTypeArr(i) there is the value sswSelectType_e = 0 it indicates that there is one of the fasteners of the dimension that is broken. From what I've tested, it doesn't work on diameter sides that would only have one attachment line.
Hello; Here's my macro for removing wobbly odds; Works under Solidworks 2022 (even if some variables should be updated...).
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swDraw As DrawingDoc
Dim swSheet As Sheet
Dim swView As View
Dim boolstatus As Boolean
Dim swAnn As Annotation
Dim swDispDim As DisplayDimension
Dim vSheetNames As Variant
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel.GetType <> SwConst.swDocumentTypes_e.swDocDRAWING Then Exit Sub
Set swDraw = swModel
swModel.ClearSelection2 (True)
vSheetNames = swDraw.GetSheetNames
For i = 0 To UBound(vSheetNames)
swDraw.ActivateSheet vSheetNames(i)
Set swSheet = swDraw.Sheet(vSheetNames(i))
Set swView = swDraw.GetFirstView ' This is the drawing template
Do While Not swView Is Nothing
Set swAnn = swView.GetFirstAnnotation3
Do While Not swAnn Is Nothing
If swAnn.IsDangling Then
boolstatus = swAnn.Select3(True, Nothing)
End If
Set swAnn = swAnn.GetNext3
Loop
Set swView = swView.GetNextView
Loop
boolstatus = swModel.DeleteSelection(True)
swModel.ClearSelection2 (True)
Next i
swModel.ClearSelection2 (True)
End Sub
Providing an example, a screenshot before copying and then of the cleaned result, would perhaps have been clearer? If people answer next to it, it may not be clear enough for them. In any case, it doesn't seem very simple.
Hello; @Bob_2000 indeed my answer does not correspond at all to your request, the macro provided can only be used on the dimension in the Drawings. Sorry.
Hello You must select the dimension in the sketch and not the sketch itself. In the screenshot on the other hand it seems to be the points that are in error and not the odds so not the same request.
The code I have put as an example does not do any deletions. Ability to share your file? As explained at first glance, it is not the odds that are at fault.
Future file, I'm in 2022. Otherwise basic my first example works on wobbly dimensions (in the example you have to select the dimension in question by hand, you just have to automate for this case). For wobbly constraints, I haven't seen anything in the API help yet. The code of the first post allows you to indicate that the sketch is not totally constrained but does not point out the constraint in error. Maybe look for the status of constraints (I haven't had time to look at it yet)