×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Saving a DXF to its original path

Saving a DXF to its original path

Saving a DXF to its original path

(OP)
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:

Quote (CATIA)

Error: The file has not been correctly created. Please check disk space, privileges, Memory...

CODE --> VBA

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, www.cpearson.com

    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?

RE: Saving a DXF to its original path

(OP)
I should mention, I am able to perform the document1.ExportData strFilePath, "dxf" command in other scripts that save a file that had been opened from THE SAME VBA script that is trying to export it. Also, I can manually export the file that was giving me an error. I just can't do it in VBA within this particular script.

So, I have no idea why I'm getting...

Quote (CATIA)

Error:
The file has not been correctly created.
Please check disk space, privileges, Memory...

RE: Saving a DXF to its original path

Hi,

I suppose you are using "BrowseForFolder" method to impose to the user from where he has to open the dxf file.

In this case I would suggest to store that path and use it later. An example bellow, in CATScript.

CODE --> CATScript

Sub CATMain()

Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.BrowseForFolder _
 (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\") 
Set objFolderItem = objFolder.Self 
objPath = objFolderItem.Path
MsgBox objPath

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: Saving a DXF to its original path

(OP)
Fernando,

I was not using that method but I would love to know more about it. Does CATIA recall the definition of that object once the script has "Open File" Script has finished running? I know Global Variables are lost once their defining script has finished.

I'm a bit new to VBA and haven't even used the CreateObject function before. I can't find it in the book I have by Ziethen. I assume it's a standard VBA function?

My method for opening the DXF was as such:

CODE --> VBA

Option Explicit

Sub CATMain()
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' This script allows the user to chose 1 DXF file to open and opens it in the new Managed DXF process.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Call CleanFileList.CATMain
    
    Dim dump As Variant
    Dim strFilePath As String
    Dim documents1 As Documents
    Dim document1 As Document

    Set documents1 = CATIA.Documents

    strFilePath = CATIA.FileSelectionBox("Select DXF file:", "*.dxf", CatFileSelectionModeOpen)
    If strFilePath = "" Then
        dump = MsgBox("No DXF file was chosen.", , "File Error")
        Exit Sub
    End If

    Set document1 = documents1.Open(strFilePath)
    Call AddFileList.CATMain(document1.Name, strFilePath) 'Script to update the file list of DXF's currently opened with this managed method.  It's been debugged and seems to work perfectly.
        
End Sub 

RE: Saving a DXF to its original path

(OP)
Unfortunately, this part of the process must be manually performed. This is where they perform Sketch Analysis and manually fix any broken geometry. That's why I'm using the text file.

But do you have any idea why my solution won't work? It fails on drawingDocument1.ExportData strFilePath "dxf" with a reason I do not understand.

RE: Saving a DXF to its original path

I didn't look at your code but you can compare with what I'm doing in CATScript to read a txt file line by line

CODE --> CATScript

Sub CATMain()

Dim objFSO, strTextFile, strData, strLine, arrLines
CONST ForReading = 1

'name of the text file
strTextFile = "c:\temp\test.TXT"

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject") '<<< 

'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'~ 'Step through the lines
For Each strLine in arrLines
'~ ''''''''''''''''''''''''''''''''''''''''
MsgBox strLine
Next
'Cleanup objFSO
Set objFSO = Nothing

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources