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!

How to measure ejector pins in CATIA V5

xPAIVAx

Industrial
Jul 12, 2023
22
Hello community,

I'm working in the Mould Injection Automation and i want to create a macro in VBA to measure ejector pins, i want the macro to run in a specific product and measure the lenght and the body's diameter of the ejector pins, is it possible, can anyone help me with that?

But if the ejector is cut on the top i want to get the length according to the maximum height.

Extrator_sjs4iq.jpg


Thank you in advance,

P. Paiva
 
Replies continue below

Recommended for you

Is it going to be enough to read 'L' and 'D' parameters from each ejector pin part?
 
Code:
Option Explicit

Sub CATMain()
    Dim prd As product
    Dim prm As Parameter
    Dim bd As Body
    Dim result, lvalue, dvalue
    result = Join(Array("PartNumber", "Name", "Length", "Diameter"), vbTab) & vbNewLine
    For Each prd In CATIA.ActiveDocument.product.products
        For Each bd In prd.ReferenceProduct.Parent.part.bodies
            If bd.name = "__DrillHole" Then
                Exit For
            End If
        Next
        If Not bd Is Nothing Then
            lvalue = ""
            dvalue = ""
            For Each prm In prd.ReferenceProduct.Parameters
                If prm.name = "L" Then
                    lvalue = prm.ValueAsString()
                ElseIf prm.name = "D" Then
                    dvalue = prm.ValueAsString()
                End If
            Next
            result = result & Join(Array(prd.partNumber, prd.name, lvalue, dvalue), vbTab) & vbNewLine
        End If
    Next
    MsgBox result
End Sub
 
Hi Little Cthulhu,

This worked perfectlly, but i want to do that on a stp without parameters, is there a way to measure the ejector pin like that?

Best regards,
P. Paiva
 
In stp it is possible to measure parts overall boundary (i.e. height), but not pin diameter.

Or you could use "feature recognition" command first and then read parameters of recognized features.
 
Ok it wasn't what i expected, but going back to the first code you've sent me, can be modified to instead of a message giving me the info about the name, lenght and diameter on an excel, that automatically opens at the end of the code like the message?

Ty for you answers

Regards,

Paiva
 
Sure, use CATIA.FileSystem to write text to a file, name it .csv and then open it with Shell.Application
 
Can you point me in some more specific direction, beacuse what i tried didn't work
 
Hello guys, meanwhile i got it, and gonna post what i have.

Code:
Option Explicit

Sub CATMain()
    Dim prd As Product
    Dim prm As AnyObject ' Use AnyObject as a flexible type for CATIA objects
    Dim bd As Body
    Dim result As String
    Dim lvalue As String, dvalue As String
    Dim xlApp As Object ' Excel Application
    Dim xlBook As Object ' Excel Workbook
    Dim xlSheet As Object ' Excel Worksheet
    Dim row As Integer

    ' Initialize Excel application
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Sheets(1)
    
    ' Set up the header row in Excel
    xlSheet.Cells(1, 1).Value = "PartNumber"
    xlSheet.Cells(1, 2).Value = "Length"
    xlSheet.Cells(1, 3).Value = "Diameter"
    
    ' Start data entry at row 2
    row = 2
    
    ' Loop through the products
    For Each prd In CATIA.ActiveDocument.Product.Products
        Dim part As part
        Set part = prd.ReferenceProduct.Parent.part
        
        ' Loop through the bodies in the part
        For Each bd In part.Bodies
            If bd.Name = "__DrillHole" Then
                Exit For
            End If
        Next
        
        If Not bd Is Nothing Then
            lvalue = ""
            dvalue = ""
            
            ' Loop through the parameters of the product
            For Each prm In part.Parameters
                If prm.Name = "L" Then
                    lvalue = prm.ValueAsString
                ElseIf prm.Name = "Ø_Extrator" Then
                    dvalue = prm.ValueAsString
                End If
            Next
            
            ' Write data to the Excel sheet
            xlSheet.Cells(row, 1).Value = prd.PartNumber
            xlSheet.Cells(row, 2).Value = lvalue
            xlSheet.Cells(row, 3).Value = dvalue
            row = row + 1
        End If
    Next
    
    ' Save the workbook to a temporary location
    Dim filePath As String
    filePath = Environ$("TEMP") & "\CATIA_Report.xlsx"
    xlBook.SaveAs filePath
    
    ' Make Excel visible and open the saved file
    xlApp.Visible = True
    xlApp.Workbooks.Open filePath
    
    ' Clean up
    Set xlSheet = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing
End Sub

Thank you once again, Little Cthulhu :)
 

Part and Inventory Search

Sponsor