Remove the line string quotes or go to single backslashes....

Remove the line string quotes or go to single backslashes....

MBestSNZMY
Contributor Contributor
1,023 Views
10 Replies
Message 1 of 11

Remove the line string quotes or go to single backslashes....

MBestSNZMY
Contributor
Contributor

I'm working on a script file to batch import dgn files into Acad templates then save them as dwg's.

But.....I'm running into multiple limitations.........
-Import works, if I remove backslashes to singles..... But the when I pull the directory and file name from the list, AutoCAD automatically adds the additional backslashes.
EX: "D:\\DGN\\All_Files\\Process_Files\\D17017.dgn"
This I can insert below
i.e. "D:\DGN\All_Files\Process_Files\D17017.dgn"

-Attach and -dgnimport works, but I need to remove the quotes. If I edit manually they work. Trying to do it with command line they do not work.............

A little help and understanding would be greatly appreciated!!

0 Likes
Accepted solutions (1)
1,024 Views
10 Replies
Replies (10)
Message 2 of 11

MBestSNZMY
Contributor
Contributor

;;To remove quotes, (Works with -attach and -dgnimport) this works but I can't use strname as the name in -import or attach.  I'm guess strname needs to be changed to something else to use as the filename and location?

I did find this:

(setq strName (read "D:\\DGN\\All_Files\\Process_Files\\D17017.dgn"))
Returns:  D:\\DGN\\ALL_FILES\\PROCESS_FILES\\D17017


;;To remove backslashes, (Works with -import) this works but I can't use strname as the name in -import or attach.  I'm guess strname needs to be changed to something else to use as the filename and location?

 

i.e. "D:\DGN\All_Files\Process_Files\D17017.dgn"

 

 

0 Likes
Message 3 of 11

paullimapa
Mentor
Mentor

Questions

Are you using lisp code to create a script file for AutoCAD to run at a later date?

How are you getting the dgn files names?

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 11

MBestSNZMY
Contributor
Contributor
I need to do all this in a .scr file

I create a text file with the dgn full path and file name listed.
Read the file name and save it as txtline (setq txtline (read-line f))
Soooo, this file name looks like "D:\\DGN\\ALL_FILES\\PROCESS_FILES\\D17017.dgn"

Using vl-string-translate, I get the slashes opposite
(setq txtline (vl-string-translate "\\" "/" txtline))
"D:/COOL_ORANGE/MITSUBISHI/ALL_FILES/PROCESS_FILES/D17017"

Then using the read command (setq strName (read txtline))
(setq txtline (read TXTLINE))
D:/COOL_ORANGE/MITSUBISHI/ALL_FILES/PROCESS_FILES/D17017
If I copy and paste the above in the save line it works. I can't get the string to save to the file name and dir.

Running the -save or .save command txtline or !txtline will not present the file name and location to save it. It will always save it as txtline.dwg

This is driving me nuts!! I've read 1000's of lines of code today and nothing really pops up and "Oh crap, you're overthinking it!!


0 Likes
Message 5 of 11

Moshe-A
Mentor
Mentor

@MBestSNZMY  hi,

 

why do you have to change th "\\"  to   "/" ?  you can leave it as it is.

when you call the (read) function with a string args, it returns the string as a SYMbol type but for the script you need string. there is a different when input is coming from keyboard versus script \ autolisp. 

 

So to conclude:

do not use (vl-string=translate)

do not use (read)

 

Moshe

 

0 Likes
Message 6 of 11

MBestSNZMY
Contributor
Contributor

Sounds simple but.

Read the file name and location in the txt file

Command: (setq f (open "D:\\All_Files\\Process_Files\\DGN_file.txt" "R"))
#<file "D:\\All_Files\\Process_Files\\DGN_file.txt">

Command: (setq txtline (read-line f))
"D:\\All_Files\\Process_Files\\D17017.dgn"

Command: (close f) nil

 

Remove the .dgn extension

Command: (setq txtline (strcat (vl-filename-directory txtline) "\\" (vl-filename-base txtline)))
"D:\\All_Files\\Process_Files\\D17017"

 

Check the file name

Command: !txtline
"D:\\All_Files\\Process_Files\\D17017"

 

Attempt to save the file using !txtline string as the new filename.  This ends up saving the file as !txtline.dwg instead of the new file name....

Command: -SAVE
SAVE Save drawing as <C:\Users\mikeb\OneDrive\Documents\Drawing19.dwg>: !txtline

0 Likes
Message 7 of 11

Moshe-A
Mentor
Mentor
Accepted solution

@MBestSNZMY 

 

Read about TEXTEVAL sysvar and tell me what did you think?

0 Likes
Message 8 of 11

MBestSNZMY
Contributor
Contributor
Moshe-A,
I can stop drinking now! Setting that to took care of all my issues!! I was overthinking it.

Thank You!!
Mike
0 Likes
Message 9 of 11

MBestSNZMY
Contributor
Contributor
Moshe-A, if you're going to AU this year, I owe you a beer!!

Mike
0 Likes
Message 10 of 11

Moshe-A
Mentor
Mentor

@MBestSNZMY 

 

Was thrill to see your respond.

I do not know what AU is and do not drink mush beers so pass this to your love one from me 😍

 

Thank you

0 Likes
Message 11 of 11

MBestSNZMY
Contributor
Contributor
Autodesk University in Las Vegas Nov. 13-15, 2023. CAD nerd fest.
0 Likes