Capturing hole qty's in a part.

Capturing hole qty's in a part.

wfisher
Enthusiast Enthusiast
539 Views
8 Replies
Message 1 of 9

Capturing hole qty's in a part.

wfisher
Enthusiast
Enthusiast

Looking for a way to capture the hole qty in a part file so that I can subtract (1) from it and add to a dimension the qty of spaces. Any direction on how to accomplish this would be appreciated. Using vb.net. Thanks

wfisher_0-1659547559794.png

 

 

0 Likes
Accepted solutions (1)
540 Views
8 Replies
Replies (8)
Message 2 of 9

A.Acheson
Mentor
Mentor

Are you looking to reach into the part file and insert information in the drawing? Or are your trying to modify the part only? A little more information would better target a solution that suits your needs. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 9

JelteDeJong
Mentor
Mentor

I assumed that your holes are in a pattern. Try running the following rule and first select a hole line and then the associated dimension.  (btw this does not work for flat pattern views)

Dim manager As CommandManager = ThisApplication.CommandManager

Dim curveSegment As DrawingCurveSegment = manager.Pick(
    SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a curve")

Dim curve As DrawingCurve = curveSegment.Parent
Dim edge As Edge = curve.ModelGeometry
Dim view As DrawingView = curve.Parent
Dim refDoc As PartDocument = view.ReferencedDocumentDescriptor.ReferencedDocument

Dim patterns = refDoc.ComponentDefinition.Features.RectangularPatternFeatures
For Each pattern As RectangularPatternFeature In patterns

    Dim patternFound = pattern.Faces.Cast(Of Face).
        SelectMany(Function(f) f.Edges.Cast(Of edge)).
        Where(Function(e) e Is edge).
        Any()

    Dim patternFound2 = pattern.ParentFeatures.Cast(Of PartFeature).
        SelectMany(Function(pf) pf.Faces.Cast(Of Face)).
        SelectMany(Function(f) f.Edges.Cast(Of edge)).
        Where(Function(e) e Is edge).
        Any()

    If (patternFound Or patternFound2) Then

        Dim dimension As DrawingDimension = ThisApplication.CommandManager.Pick(
            SelectionFilterEnum.kDrawingDimensionFilter, "Select a dimension")

        Dim count As Integer = pattern.XCount.Value - 1
        dimension.Text.FormattedText = String.Format("{0} x <DimensionValue/>", count)
    End If
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 9

wfisher
Enthusiast
Enthusiast

Thank you for the reply. I placed your code into a button and got the following error. Any suggestions?

wfisher_0-1659605498055.png

 

0 Likes
Message 5 of 9

wfisher
Enthusiast
Enthusiast
Thank you for your reply. Working from the idw I would like to be able to select one dimension and have it show how many spaces for the qty of same holes (pattern) in the part.
0 Likes
Message 6 of 9

JelteDeJong
Mentor
Mentor

The variable "e" (green) in the lambda expression hides the argument "e" (red) of the function. this is not allowed. I would change the argument variable (red) because you don't use it. For example you can change it to "eventArgs" 

JelteDeJong_0-1659606050013.png

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 7 of 9

wfisher
Enthusiast
Enthusiast

Changed the "e" to "a". New error. Sorry for all the novice questions. 

wfisher_0-1659606787497.png

 

0 Likes
Message 8 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

Not sure what this message means but I expect that it has something to do with the LINQ commands used. Therefore I rewrote the rule to not use LINQ (but way too many nested loops 😉 Give it a go and let me know.

Dim manager As CommandManager = ThisApplication.CommandManager

Dim curveSegment As DrawingCurveSegment = manager.Pick(
        SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a curve")

Dim curve As DrawingCurve = curveSegment.Parent
Dim edge As Edge = curve.ModelGeometry
Dim view As DrawingView = curve.Parent
Dim refDoc As PartDocument = view.ReferencedDocumentDescriptor.ReferencedDocument

Dim patterns = refDoc.ComponentDefinition.Features.RectangularPatternFeatures
For Each pattern As RectangularPatternFeature In patterns

    Dim patternFound As Boolean = False
    For Each f As Face In pattern.Faces
        For Each e As edge In f.Edges
            If (E Is edge) Then
                patternFound = True
            End If
        Next
    Next

    For Each pf As PartFeature In pattern.ParentFeatures
        For Each f As Face In pf.Faces
            For Each e As edge In f.Edges
                If (E Is edge) Then
                    patternFound = True
                End If
            Next
        Next
    Next

    If (patternFound) Then

        Dim dimension As DrawingDimension = ThisApplication.CommandManager.Pick(
            SelectionFilterEnum.kDrawingDimensionFilter, "Select a dimension")

        Dim count As Integer = pattern.XCount.Value - 1
        dimension.Text.FormattedText = String.Format("{0} x <DimensionValue/>", count)
    End If
Next

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 9 of 9

wfisher
Enthusiast
Enthusiast

Magnificent Job! Works just liked I'd hoped. Thank you very much for your help. I tweaked the string format to meet my needs. I will study the rest of the code you provided and learn something new. I attached a small video showing it in action. 

0 Likes