Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng 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
Joined
May 16, 2023
Messages
3
Location
IT
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
 
First, I Would suggest to find hole feature, and analyse the dimensions of the feature, and as well if thread is defined or not!
Then you have the patterns. Lets make the first step and then we will figure out something!

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
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

 
Thanks guys, I'll work on it now and later I'll share what I got
 
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

Back
Top