Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I change where the open command saves the output file too?

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
396 Views, 1 Reply

How can I change where the open command saves the output file too?

The prorram below takes text from and AutoCAD drawing and outputs it to a text file. The problem I am having is that the file is then saved in my working directory. I would like to know how I can change where the file will be saved to. I bolded the line below that opens the output file. Please help me out with getting this question as it has been quite frustrating and I would very much appreciate it.

 

 

;This program gets text from an AutoCAD drawing and writes it to a text file.

;define program - listing your variable names here

; resets them to nil after the program finishes

(defun C:TEXTOUT(/ lts ernote filen fil eset en enlist cntr)

;turn echo off

(setvar "cmdecho" 0)

;get ltscale (Note: ltscale should always equal dimscale)

(setq lts(getvar "ltscale"))

;set the exit note to successful

(setq ernote "\n....TextOut Complete.")

;open file to write

(setq fName(strcat (substr (getvar "dwgname")1 (-(strlen (getvar "dwgname"))4 )) "_TBNO.txt"))

 

(if (setq fil(open fName "w"))

 

;progn necessary for multiple statements inside an if statement

(progn

;if ssget returns a valid selection set

(if (setq eset(ssget "X" '((8 . "TBNO"))))

 

;progn necessary for multiple statements inside an if statement

(progn

;set the entity counter to zero [the first entity in a set is zero]

(setq cntr 0)

;step through each entity in the selection set

(while (< cntr (sslength eset))

;get the entity name indexed by cntr

(setq en(ssname eset cntr))

;get the DXF group codes for the entity

(setq enlist(entget en))

;check the group code 0 to see if entity type = TEXT

(if(= "TEXT" (cdr(assoc 0 enlist)))

;progn necessary for multiple statements inside an if statement

(progn

;get the text string from the entity's DXF Group Code 1

(setq str(cdr(assoc 1 enlist)))

;print the string to the command line

(princ (strcat "\nOutput To File: " str))

;print the string to the file

(princ (strcat "\n" str) fil)

) ;close the if progn

) ;close the if statement

;increment the counter to get the next entity

(setq cntr(+ cntr 1))

) ;close the while loop

;close the text file

(close fil)

) ;close the if progn

;set the exit note as an error

(setq ernote "\nError - No Entities Selected.")

) ; close the if statement

) ;close the if progn

;set the exit note to be an error

(setq ernote (strcat "\nError - Could not create File: " filen))

) ;close the if statement

;turn the command echo back on

(setvar "cmdecho" 1)

;print the exit note to the command line

(princ ernote)

;clear the command line

(princ "\n ")

;supress last echo

(princ)

) ;close the program

 

 

Thank you,

Brad

1 REPLY 1
Message 2 of 2
markruys2
in reply to: Anonymous

you can ask the user to specify location and name by using the getfiled function,

or if you want an absolute fixed location, add to the fname ... just before the bolded thext you have ...

(setq fName (strcat "c:\\Temp\\" fName))

assuming that the folder C:\Temp exists on your system

HTH

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost