Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Recursively scan through product structure (simple program is failing)

Status
Not open for further replies.

pirateincognito

Automotive
Mar 4, 2015
20
US
I'm a novice programmer but new to CATIA VBA. For a starting program, I'm simply trying to traverse the current product structure and print each part number.

The code runs perfectly as a .CATSCRIPT but when loaded into a CATVBA module, it fails spectacularly.

Run time error 438 'Object doesn't support this property or method' on line 10 ' Analyze (Prod)'

Usually this means your syntax is wrong. VBA seems to have trouble passing Prod as a parameter to the subroutine.

I have verified through debugging that Prod is in fact a VarType 'Product' with a valid assignment.

Nothing I've tried has worked. Any ideas eng-tips? Thanks.
Code:
Public Sub CATMain()
    Dim AD As Document
    Dim Prod As Product
    
    Set AD = CATIA.ActiveDocument
    Set Prod = AD.Product
'    Debug.Print TypeName(AD)
'    Debug.Print VarType(AD)
'    Debug.Print TypeName(Prod)
'    Debug.Print VarType(Prod)
    Analyze (Prod)
End Sub
Public Sub Analyze(P As Product)
    Debug.Print P.PartNumber
    
    Dim PP As Products
    Dim i As Integer
    i = 0
    Set PP = P.Products

    Do While i < PP.Count
        i = i + 1
        Analyze (PP.Item(i))
    Loop
End Sub
 
Replies continue below

Recommended for you

Try using the CALL keyword in front of the line calling your subroutine in CATMain(). VBA will only use the parenthesis around the arguments when the call keyword is used. I think CATScript ignores this syntax.

--Doug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top