Sub Main() ' Ensure the active document is a Part Document Dim oDoc As Document = ThisApplication.ActiveDocument If Not TypeOf oDoc Is PartDocument Then MessageBox.Show("This rule can only be run in a part document.", "Invalid Document") Return End If ' Prompt the user for a dimension name Dim dimName As String = InputBox("Enter the name of the dimension to find:", "Dimension Name") If String.IsNullOrWhiteSpace(dimName) Then MessageBox.Show("Dimension name cannot be empty.", "Invalid Input") Return End If ' Search for the dimension in all sketches Dim oPart As PartDocument = CType(oDoc, PartDocument) Dim targetSketch As Sketch = Nothing Dim found As Boolean = False For Each oCompDef As Sketch In oPart.ComponentDefinition.Sketches For Each oDim As DimensionConstraint In oCompDef.DimensionConstraints If oDim.Parameter.Name.Equals(dimName, StringComparison.OrdinalIgnoreCase) Then targetSketch = oCompDef found = True Exit For End If Next If found Then Exit For Next If targetSketch IsNot Nothing Then ' Notify user and offer to open the sketch Dim result As MsgBoxResult = MessageBox.Show("Dimension '" & dimName & "' found in sketch '" & targetSketch.Name & "'. Would you like to open the sketch and select the dimension?", "Dimension Found in Another Sketch", MessageBoxButtons.YesNoCancel) If result = MsgBoxResult.Yes Then ' Open the target sketch using Edit targetSketch.Edit() Dim oSelectSet As SelectSet = oDoc.SelectSet oSelectSet.Clear() For Each oDim As DimensionConstraint In targetSketch.DimensionConstraints If oDim.Parameter.Name.Equals(dimName, StringComparison.OrdinalIgnoreCase) Then oSelectSet.Select(oDim) Exit For End If Next ElseIf result = MsgBoxResult.Cancel Then ' Exit without further action Return End If Else MessageBox.Show("No dimension with the name '" & dimName & "' exists in the part.", "Dimension Not Found") End If End Sub