Spaces in filename

Spaces in filename

dbrblg
Collaborator Collaborator
1,582 Views
8 Replies
Message 1 of 9

Spaces in filename

dbrblg
Collaborator
Collaborator

I'm trying to print with the following code:

With ThisDrawing
    sTxt = Replace("sTxt is Z:\A\B\Design\2017 Projects\Test Stage\2.dsd", "\", "/")
    
    .SetVariable "FILEDIA", 0
    .Regen acActiveViewport
    
    .SendCommand "(command " & Chr(34) & "-PUBLISH" & Chr(34) & " " & Chr(34) & sTxt & Chr(34) & ")" & vbCr

End With

but I am getting the following error in the text window:

Could not locate sheet list file.
Enter name of sheet list <>: nil

I believe it has something to do with the spaces in the filename because if I change to this:

With ThisDrawing
    sTxt = Replace("sTxt is C:\2.dsd", "\", "/")
    
    .SetVariable "FILEDIA", 0
    .Regen acActiveViewport
    
    .SendCommand "(command " & Chr(34) & "-PUBLISH" & Chr(34) & " " & Chr(34) & sTxt & Chr(34) & ")" & vbCr

End With

everything works fine, so I know the DSD file is ok (not that the error indicates it is a problem with the DSD file anyway!!)

 

What can I do to fix,or prove, this issue?

0 Likes
1,583 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

try with double quotes (non tested):

 

sTxt = Replace("sTxt is ""sTxt is Z:\A\B\Design\2017 Projects\Test Stage\2.dsd""", "\", "/")
0 Likes
Message 3 of 9

dbrblg
Collaborator
Collaborator

Sorry, copy / paste error on my part.

 

Code should read:

 

With ThisDrawing
    sTxt = Replace("Z:\A\B\Design\2017 Projects\Test Stage\2.dsd", "\", "/")
    
    .SetVariable "FILEDIA", 0
    .Regen acActiveViewport
    
    .SendCommand "(command " & Chr(34) & "-PUBLISH" & Chr(34) & " " & Chr(34) & sTxt & Chr(34) & ")" & vbCr

End With

 

Unfortunately the editor does not let me put in double quotes so this does not work. Smiley Mad

 

 

0 Likes
Message 4 of 9

Ed__Jobe
Mentor
Mentor

Try using the backslash escape character. \" Doing that, you also shouldn't need the replace function. The lisp interpreter at the command line won't see the backslashes in the quoted path name as escape characters.

sTxt = "\"Z:\A\B\Design\2017 Projects\Test Stage\2.dsd\""

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 9

norman.yuan
Mentor
Mentor

This is VBA code, where you cannot use \" to escape for literal double-quote in string. It should be double the double-quote, as RICVBA suggested.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 9

norman.yuan
Mentor
Mentor

@dbrblg wrote:

... 

Unfortunately the editor does not let me put in double quotes so this does not work. Smiley Mad

 

 


You do write code in AutoCAD VBA editor, don't you? The VBA Editor does accept doubled double-quote as literal double quote in a string value. Try it again, and make sure your typing is correct.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 7 of 9

dbrblg
Collaborator
Collaborator

Appears that double quotes is still not accepted by AutoCAD....

 

This is the latest code (tidied up):

Private Function Test_Function()

    Dim s As String
    
    s = "C:\dsd\spaces in\file name\2.dsd"

    Call PublishProject(s)

End Function

Private Function PublishProject(strDSDFileName As String)

    Dim strDSDCommandFileName As String
    Dim fso As New Scripting.FileSystemObject
    
    If (fso.FileExists(strDSDFileName)) Then
        With ThisDrawing
            strDSDCommandFileName = Replace(strDSDFileName, "\", "/")
                        
            .SetVariable "FILEDIA", 0
            .Regen acActiveViewport
            .SendCommand "(command " & Chr(34) & "-PUBLISH" & Chr(34) & " " & String(2, 34) & strDSDCommandFileName & String(2, 34) & ")" & vbCr
            .SetVariable "FILEDIA", 1
        
        End With
    
        If (bDeleteDSDFile) Then
            On Error GoTo err
    
            Call fso.DeleteFile(strDSDFileName)
    
            On Error GoTo 0
        End If
        
    End If
    
    Exit Function
    
err:
    If (err.Number = 70) Then
        Call MsgBox("Failed to delete DSD File due to permissions", vbCritical, "Warning")
    End If
        err.Clear
        Resume Next

End Function

and this is what is shown on the command line.....

Untitled.png

It does not seem to be able to find the DSD file.  I've seen many posts which say that double quotes are required but for some reason this fails Smiley Surprised

0 Likes
Message 8 of 9

Anonymous
Not applicable

to obtain the result of double quote use:

 

strDSDCommandFileName = Replace("""" & strDSDFileName & """", "\", "/")

then you have to get rid of those:

String(2, 34)

 

0 Likes
Message 9 of 9

dbrblg
Collaborator
Collaborator

Thanks for the suggestion, unfortunately it still does not work....

        With ThisDrawing
            strDSDCommandFileName = Replace("""" & strDSDFileName & """", "\", "/")
                        
            .SetVariable "FILEDIA", 0
            .Regen acActiveViewport
            .SendCommand "(command " & Chr(34) & "-PUBLISH" & Chr(34) & " " & strDSDCommandFileName & ")" & vbCr
            .SetVariable "FILEDIA", 1
        
        End With

I do however get a slightly different error:

Untitled10.png

 

 

So with a little adjustment to get the double quotes in the way you suggested:

        With ThisDrawing
            strDSDCommandFileName = Replace("""""" & strDSDFileName & """""", "\", "/")
                        
            .SetVariable "FILEDIA", 0
            .Regen acActiveViewport
            .SendCommand "(command " & Chr(34) & "-PUBLISH" & Chr(34) & " " & strDSDCommandFileName & ")" & vbCr
            .SetVariable "FILEDIA", 1
        
        End With

gave me this error:

 Untitled20.png

I did get the double quotes, but a different error too...

 

 

0 Likes