I have been working on a solution that allows a user to save a DXF file to where it had been originally opened. CATIA immediately forgets the PATH for any DXF file, instead it recalls the document name to be CATDrawing1.CATDrawing or something of that sort.
To add this functionality, I created a VBA script that successfully allows the user to choose a DXF file to open, then it opens that file, then it opens a TXT file and saves the name and PATH to that text file.
I then have another script which attempts to check the ActiveDocument and look up its CATIA.ActiveWindow.Name (title of the window it is in) in the TXT file and then grab the PATH from the TXT file so I can pefrom: drawingDocument1.ExportData strFilePath, "dxf"
Unfortunately, when I get to the very end, I get an error:
It's that last line that fails. And I cannot figure out why. Any ideas?
To add this functionality, I created a VBA script that successfully allows the user to choose a DXF file to open, then it opens that file, then it opens a TXT file and saves the name and PATH to that text file.
I then have another script which attempts to check the ActiveDocument and look up its CATIA.ActiveWindow.Name (title of the window it is in) in the TXT file and then grab the PATH from the TXT file so I can pefrom: drawingDocument1.ExportData strFilePath, "dxf"
Unfortunately, when I get to the very end, I get an error:
CATIA said:Error: The file has not been correctly created. Please check disk space, privileges, Memory...
Code:
Option Explicit
Sub CATMain()
Dim openDXFRecord As File
Dim iStream As TextStream
Dim alltext() As String
Dim strFilePath As String
Dim strFileName As String
Dim test As Boolean
Dim x As Long
Dim documents1 As Documents
Dim dump As Variant
Set documents1 = CATIA.Documents
Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument
strFileName = CATIA.ActiveWindow.Name
Call CleanFileList.CATMain
test = True
Set openDXFRecord = CATIA.FileSystem.GetFile("C:\temp\OpenDXFlist-19657621943.txt")
Set iStream = openDXFRecord.OpenAsTextStream("ForReading")
Do While test
If ArrayMod.IsArrayAllocated(alltext) Then
Call ArrayMod.ChangeBoundsOfArray(alltext, 1, UBound(alltext) + 1)
Else
ReDim alltext(1 To 1)
End If
alltext(UBound(alltext)) = iStream.ReadLine
If iStream.AtEndOfStream Then
test = False
End If
Loop
iStream.Close
''' THIS is where I begin checking the filename for the path. It works correctly until the last line. All variables have the values I would expect until the end of this script. All external function and subroutine calls work fine. The function ArrayMod is modArraySupport By Chip Pearson, chip@cpearson.com, [URL unfurl="true"]www.cpearson.com[/URL]
If ArrayMod.IsArrayEmpty(alltext) Then
dump = MsgBox("The current file was not opened with the 'OpenDXF' Feature.", , "File Error:")
Exit Sub
End If
strFilePath = ""
For x = 1 To UBound(alltext) Step 2
If strFileName = Left(alltext(x), Len(strFileName)) Then
strFilePath = Left(alltext(x + 1), Len(alltext(x + 1)) - 1)
x = UBound(alltext)
End If
Next
If strFilePath = "" Then
dump = MsgBox("The current file was not opened with the 'OpenDXF' Feature.", , "File Error:")
Exit Sub
End If
drawingDocument1.Activate
drawingDocument1.ExportData strFilePath, "dxf"
End Sub
It's that last line that fails. And I cannot figure out why. Any ideas?