Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

How to loop through already opened .CATDrawing files in catia v5 using vba

Sidtha

Aerospace
Nov 25, 2012
34
Hello,

Is there any possiblity to loop through already opened .CATDrawing files in catia v5 using vba.

If yes please help me with code


I found below code but its counting sheets inside the same CATDrawing file.

Dim drawingDocument1 As Document
Set drawingDocument1 = CATIA.ActiveDocument
Set oDrwView = drawingDocument1.Sheets.ActiveSheet.Views

Debug.Print drawingDocument1.Sheets.Count

For i = 1 To drawingDocument1.Sheets.Count
Set oSheet = drawingDocument1.Sheets.Item(i)
oSheet.Activate
Debug.Print oSheet.Name
Next

BR Siddu
 
Replies continue below

Recommended for you

Code:
Sub CATMain()
Dim V As Integer
Dim StrWindows As String
Dim DrawingExists As Boolean
DrawingExists = False
Set windows2 = CATIA.Windows
For V = 1 To windows2.Count
    StrWindows = windows2.item(V).name
    MsgBox windows2.item(V).Parent.name
    If InStr(StrWindows, "Drawing") Then
        DrawingExists = True
        MsgBox StrWindows
    End If
Next
End Sub
 
You can loop through CATIA.Documents, check whether the type of a Document is DrawingDocument.
Code:
Sub Main()
    Dim n As Long, i As Long
    n = CATIA.Documents.Count
    
    Dim doc As Document
    For i = 1 To n
        Set doc = CATIA.Documents.Item(i)
        If TypeOf doc Is DrawingDocument Then
            Debug.Print doc.Name
        End If
    Next i
End Sub
 
Use LWolf's solution as it enumerates "opened" documents meaning the ones that have their own window.

Although I'd adjusted "if" condition, because right now it matches ANY documents that have word "Drawing" in them (i.e. "AssemblyForDrawing.CATProduct")

Code:
Sub CATMain()
  Dim win, doc, drawingExists
  drawingExists = False
  For Each win in CATIA.Windows
    Set doc = win.Parent
    If TypeName(doc) = "DrawingDocument" Then
      drawingExists = True
      MsgBox doc.Name
    End If
  Next
End Sub
 

Part and Inventory Search

Sponsor