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!

Working in a CATPart in a CATProduct VBA

Status
Not open for further replies.

LucasC

Automotive
Feb 18, 2019
157
US
I want my macro to create geometry in the active catpart that's inside a product. I don't want to have to open the catpart in a separate window.

I was thinking the below but I'm drawing a blank here...

Dim Documents1 As Documents
Set Documents1 = CATIA.Documents

Dim PartDocument1 As PartDocument
Set PartDocument1 = Documents1.Item("")

Dim Part1 As Part
Set Part1 = PartDocument1.Part
 
Replies continue below

Recommended for you

Isn't it the ”blue problem“ written here?
Link

I thought about the code to get the partDocument of the blue position by using plane search.
Code:
Sub CATMain()

    Dim doc As PartDocument
    Set doc = GetBluePosionPartDoc()
    
    Dim msg As String
    If doc Is Nothing Then
        msg = "There is no blue position PartDocument."
    Else
        msg = "The blue position PartDocument is " & doc.Name & " ."
    End If
    
    MsgBox msg

End Sub

Private Function GetBluePosionPartDoc() As PartDocument
    
    Set GetBluePosionPartDoc = Nothing
    
    Dim sel As selection
    Set sel = CATIA.ActiveDocument.selection
    
    CATIA.HSOSynchronized = False
    
    With sel
        .Clear
        .Search "CATPrtSearch.Plane,in"
        
        If .Count2 < 1 Then GoTo fin
        
        Set GetBluePosionPartDoc = .Item2(1).Value.Parent.Parent
        .Clear
    End With
    
fin:
    CATIA.HSOSynchronized = True
    
End Function

1_mmg1tr.png
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top