AnsweredAssumed Answered

Delete Sketch Dimension Problem

Question asked by Rob Edwards on Mar 4, 2019
Latest reply on Mar 5, 2019 by Rob Edwards

This one's absolutely doing my head in.. I swear it worked yesterday, but I could be wrong.

 

I'm editing a new sketch in context of an Assembly. I added a few dimensions that are driven.

If the value of a certain dimension is below a threshold I want to delete it.

I kept the DisplayDimension object returned from creating it and am following the advice in this post...

How to delete a IDisplayDimension

namely to get the annotation to select prior to deleting.

From what I can tell, I have the correct dimension. The call to select returns True but it doesn't get deleted.

I also get this box pop up with the messsge

"Entities that do not belong to the active sketch cannot be deleted."

 

When I add a break point after selection and manually select the dimension, it works just fine.

Somethings not right.. and I don't have a clue what else to try.

 

Here's the code

 

'Add dimensions

Dim Haunch_swDD As SldWorks.DisplayDimension
Set Haunch_swDD = AddDimensionBetweenSketchPointAndEntity(vSketchEntities(0), pm.Haunch, "ThisOne")
Haunch_swDD.GetDimension.DrivenState = swDimensionDriven

Select Case True
Case Haunch_swDD Is Nothing
Case IsVerySmall(Haunch_swDD.GetDimension)
Dim swAnn As SldWorks.Annotation
Debug.Print Haunch_swDD.GetNameForSelection
Set swAnn = Haunch_swDD.GetAnnotation()
If swAnn.Select3(False, Nothing) Then
Debug.Print "name:" & swAnn.GetName & vbCr & "Type:" & swAnn.GetType
Debug.Print swModel.Extension.DeleteSelection2(0)
End If
[...]

...

Private Function AddDimensionBetweenSketchPointAndEntity(ByVal p As SldWorks.SketchPoint, e As SldWorks.Entity, Optional DimName = "") As SldWorks.DisplayDimension
p.Select4 False, Nothing
e.Select4 True, Nothing
Dim swDD As SldWorks.DisplayDimension
Set swDD = swModel.AddDimension2(p.X, p.Y, p.Z)
If Not swDD Is Nothing And DimName <> "" Then
swDD.GetDimension.name = DimName
End If
Set AddDimensionBetweenSketchPointAndEntity = swDD
End Function

Outcomes