Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto-Counting and Sorting Threads in a Part

Status
Not open for further replies.

Francesco Rossi

Automotive
May 16, 2023
3
Hi everyone :)
I want to create a macro in Catia v5 R2020 that replicates the Thread/Tap Analysis feature from previous versions of the software. My goal is for the macro to automatically detect all threads in my part, categorize them by diameter, and provide a count of each thread size (ex. Total Threads = 130. M6 = 126, M24 = 4).

I’ve tried searching for every Thread in the Technological Results, but I’m not sure how to sort them by diameter. This, i think, is complicated by the fact that threads are generated by various features like Threaded Hole, TapHole Assemble (with isolated body), Mirrored holes, and User/Circ Patterns.

Is there a way to do this?

Thanks in advance
 
Replies continue below

Recommended for you

I started and you can continue to code :)

just fill the points you need to add your choices.

Code:
Sub ThreadAnalysis()
    Dim partDocument As PartDocument
    Set partDocument = CATIA.ActiveDocument
    
    Dim part As Part
    Set part = partDocument.Part
    
    ' Dictionary to store thread diameter and count
    Dim threadCounts As New Scripting.Dictionary
    
    Dim features As HybridBodies
    Set features = part.HybridBodies
    
    ' Loop through hybrid bodies
    ' ...

        Dim hybridBody As HybridBody
        Set hybridBody = ' ...

        Dim feat As HybridShape
        For Each feat In hybridBody.HybridShapes
            ' Check if feat is a thread feature and extract relevant information
            ' ...

            ' Categorize and count threads
            ' ...

        Next feat

    ' ...

    ' Display the results to the user
    ' ...

End Sub

 
Hi everyone,

unfortunately, I haven't been able to find a solution to this problem yet. I tried to complete the code provided by Dialga1, but, due to my lack of VB experience, I couldn't get it to work.

I think a good strategy is to detect all the Holes in a part and detect the holes that have a diameter equal to a value stored in a dictionary (I don't need to check if a hole is threaded or not). Then I just have to count how many objects there are in the various groups of the dictionary.

Please, can you help me to do that?

Thanks,
Francesco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor