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 check user input for CATPart or CATProduct?

Status
Not open for further replies.

Kattmandu

Automotive
Oct 31, 2022
7
How do I add code to check the user input for .CATPart or .CATProduct?

Code:
Dim strFilename As String
strFilename = InputBox("Enter filename with extension", strFilename)

Dim partDocument1 As Document
Set partDocument1 = CATIA.Documents.Item(strFilename)

Dim viewBehavior As DrawingViewGenerativeBehavior
Set viewBehavior = drawingView1.GenerativeBehavior

[COLOR=#CC0000]If (strFilename is a CATPart) Then[/color]
viewBehavior.Document = partDocument1
viewBehavior.Update

[COLOR=#CC0000]ElseIf (strFilename is a CATProduct) Then[/color]
viewBehavior.Document = partDocument1.Product
viewBehavior.Update

[COLOR=#CC0000]Else (Neither CATProduct or CATPart)[/color]
MsgBox "Neither CATPart nor CATProduct!"

End If
 
Replies continue below

Recommended for you

Hello,
Please see my code below. I'm using DELMIA instead of CATIA (the same family), but I think it should work for you too.

Code:
Option Explicit
Sub CATMain()
    Dim oSelection 'As Selection 'I've sometimes issues when type "Selection"
    Dim testedObj As Object

    Set oSelection = CATIA.ActiveDocument.Selection
    Set testedObj = oSelection.Item2(1).Value

    testedObj.ApplyWorkMode (2) 'need to use changemode from visualization mode
    Set oprod = testedObj.ReferenceProduct.Parent

    If TypeName(oprod) = "PartDocument" Then
        MsgBox "Part selected"
    Else
        MsgBox "Product selected"
    End If

    testedObj.ApplyWorkMode (1)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor