Search code examples
vbacatia

Is there a command or string in CATIA V5 VBA that returns the name of the current open file?


I´m making a macro that does some actions in Catia v5, I got all the code written by recording it, and it works wonders! But, now i want to be able to just run the code on another catproduct, catpart, etc. But without having to manually change the file name on the code.

CODE:

Sub CATMain()

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item("Sheet.1")

Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views

Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.Add("AutomaticNaming")

Dim drawingViewGenerativeLinks1 As DrawingViewGenerativeLinks
Set drawingViewGenerativeLinks1 = drawingView1.GenerativeLinks

Dim drawingViewGenerativeBehavior1 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim productDocument1 As ProductDocument
Set productDocument1 = documents1.Item("*FILENAME.CATProduct*")

Dim product1 As Product
Set product1 = productDocument1.Product

drawingViewGenerativeBehavior1.Document = product1

drawingViewGenerativeBehavior1.DefineIsometricView 0.707107, 0.707107, 0#, -0.408248, 0.408248, 0.816497

drawingView1.X = -1262.192063

drawingView1.Y = -1262.192063

drawingView1.[Scale] = 1#

Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

drawingViewGenerativeBehavior1.Update

Set drawingViews1 = drawingSheet1.Views

Set drawingView1 = drawingViews1.Add("AutomaticNaming")

Set drawingViewGenerativeLinks1 = drawingView1.GenerativeLinks

Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

Set documents1 = CATIA.Documents

Set productDocument1 = documents1.Item("FILENAME.CATProduct")

Set product1 = productDocument1.Product

drawingViewGenerativeBehavior1.Document = product1

drawingViewGenerativeBehavior1.DefineIsometricView -0.707107, 0.707107, 0#, -0.408248, -0.408248, 0.816497

drawingView1.X = 7266.177117

drawingView1.Y = -1262.192063

drawingView1.[Scale] = 1#

Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

drawingViewGenerativeBehavior1.Update


End Sub

Solution

  • Use the Name or FullName properties of the Document object.

    CATIA.ActiveDocument.Name 'returns the name of the active document
    CATIA.ActiveDocument.FullName ' returns the full path to the document including the name
    

    In your case since you assign CATIA.ActiveDocument you can just use DrawingDocument1.Name or DrawingDocument1.FullName.