Author Topic: output a .txt file  (Read 7684 times)

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« on: April 28, 2005, 12:34:04 PM »
i know this is possible. i want to output a .txt file with lisp. in that file it should contain text that i type in when the lisp file prompts me to. in other words i run a routine then the routine prompts me to write something in and it repeats this until i have provided all the information. then it writes a .txt file. the purpose for this is my idea of user interaction when making a plot. before the plot command executes this routine should pop-up and ask certain questions and after the questions are answered (by input from user) then it writes the text file. can somebody guide to the right direction?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
output a .txt file
« Reply #1 on: April 28, 2005, 12:57:47 PM »
To open a file for writing;
Code: [Select]
(setq file_open (open "c:\\name.txt" "w"))
then you want to write to it using;
Code: [Select]
(write-line "some string" file_open)
when you're done make sure you close the file
Code: [Select]
(close file_open)

that's a start anyway.
TheSwamp.org  (serving the CAD community since 2003)

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #2 on: April 28, 2005, 01:02:39 PM »
thanks, ill be be back later with a routine..hopefully......

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
output a .txt file
« Reply #3 on: April 28, 2005, 01:15:38 PM »
I'll be waiting... :)
TheSwamp.org  (serving the CAD community since 2003)

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #4 on: May 03, 2005, 12:36:06 PM »
UM...HOW do i make it so another lisp routine runs after i plot. in other words after i plot a drawing then this new command runs directly after that. and how do i get strings of information on the plotter's page setups? what im looking for is to get the size of the sheet of the current drawing that was sent to the plotter.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
output a .txt file
« Reply #5 on: May 03, 2005, 12:50:13 PM »
Are you thinking "plot log" ??
TheSwamp.org  (serving the CAD community since 2003)

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #6 on: May 03, 2005, 01:49:38 PM »
well..here is what ive got not much but.....here it goes...

Code: [Select]
;;Wynn Engineering Inc.
;;plog.LSP file CREATED BY SOUK
;;souksavanh nomichith
;;last update 03-05-05

;;text will be printed out in this format
;;job number;job name;sheet size;date;user;b/nb


;;date function from the help of "http://www.afralisp.com/lispa/lisp40a.htm"



(defun today( / d yr mo day)
;define the function and declare all variabled local
(setq d (rtos (getvar "CDATE") 2 6)
     ;get the date and time and convert to text

          yr (substr d 3 2)
 ;extract the year

          mo (substr d 5 2)
 ;extract the month

         day (substr d 7 2)
;extract the day

     );setq

     (strcat mo "/" day "/" yr)
     ;string 'em together
)

(defun c:plog ( / jn jna shts userN thedate bill stringoutput fileopen)
 
(setq jn (getstring "Job number: "))
(setq jna (getstring "Job name: "))
(setq shts (getstring "Sheet size: "))
(setq userN (getvar "loginname"))
(setq thedate (today))
(setq bill (getstring "Billable or Non-billable enter B or NB:"))
(setq stringoutput (strcat jn";"jna";"shts";"thedate";"userN";"bill";"))

(setq file_open (open "c:\\plotterlog.txt" "a"))
(write-line stringoutput file_open)
(close file_open)
(princ)
  );;end defun


no error checking
Quote
if, then, else
i also want it to grab the sheet size that i print out. rather than having to type it in. so what ya think...?

daron

  • Guest
output a .txt file
« Reply #7 on: May 03, 2005, 02:48:32 PM »
Code: [Select]

(setq jn (getstring "Job number: "))  
(setq jna (getstring "Job name: "))
(setq shts (getstring "Sheet size: "))
(setq userN (getvar "loginname"))
(setq thedate (today))
(setq bill (getstring "Billable or Non-billable enter B or NB:"))

My thinking is that if you want to use this to check each plot you want zero(0) user input. Therefore you need to figure out what is being used for each getstring and place it automatically. Job number? Would that be the same as the drawing name? If you use tabs, collect the drawing name and current tab. What is "Job name"? Can there be any variables manipulated to collect it? Sheet size should be able to be collected without UI. As for the B or NB, look into getinit and getkword. This will ensure users will put at least one proper value. Nice beginning though.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #8 on: May 03, 2005, 02:53:39 PM »
thanks man...i want to be able to have zero user input but im not familiar with the variables that define then...now getinit and getkword are new to me....im gonna go look those up. brb.

btw..is this the wrong area to put this topic?

daron

  • Guest
output a .txt file
« Reply #9 on: May 03, 2005, 03:01:51 PM »
Quote from: dubb
thanks man...i want to be able to have zero user input but im not familiar with the variables that define then...now getinit and getkword are new to me....im gonna go look those up. brb.

btw..is this the wrong area to put this topic?


You're welcome.

<btw...topic?
Where else would you put it? The Teach Me forum is for teaching others what you know and the Show Your Stuff forum is for your Alpha code that you'd like to give out because you're pleased by the outcome of your work. This forum is for beating the dead horse. I'd say it's in the right place.

Does the "Job number" relate to the drawing name, i.e. G32243-01.dwg?
What of "Job name"? What is it, generally?
Billable? Sounds like you want to keep track of what's being printed for charging your customer for sending them print jobs.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #10 on: May 03, 2005, 03:36:57 PM »
Quote
Does the "Job number" relate to the drawing name, i.e. G32243-01.dwg?
What of "Job name"?


the drawing names are written: 05-505S10.dwg
which means that the drawings is 2005 the project number is 505 and the sheet name is S10 (S-1.0)

Quote
What is it, generally?
Billable? Sounds like you want to keep track of what's being printed for charging your customer for sending them print jobs

the billable area are just like you say. the routine will probably not be entirely zero user input. maybe some comments as well.

i know that there are many programs that do this type of routine that im making. however, they charge per seat and they are usually done in other programming languages.

this one will be included in my custom menu and the routine will be ran directly after the "plot" command. which is still come.

daron

  • Guest
output a .txt file
« Reply #11 on: May 03, 2005, 04:52:28 PM »
I know CAB's batch plot routine, you'll find in Show Your Stuff can be overwhelming for a noob, but you might give it a look to see how you might integrate your own plot utility into this. As far as the job number goes, you can substr, strlen, and a few other utilities to break down and rebuild the info you want from the .dwg name.

What do your users put in place of job name?

I'll ponder the billable part. That may be something like putting a toggle in the dialog box of your own custom plot utility.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #12 on: May 03, 2005, 05:09:17 PM »
Quote
What do your users put in place of job name?
we put the last name of the client. should there be a list to choose from?

Quote
I know CAB's batch plot routine,....


hehe..his routine seems like it would work..but i tore up my hair trying to get it to work....so then i tried to create it myself.

daron

  • Guest
output a .txt file
« Reply #13 on: May 04, 2005, 08:11:14 AM »
Quote from: dubb
Quote
What do your users put in place of job name?
we put the last name of the client. should there be a list to choose from?

That would be a thought. You could put it in as a pulldown required in order to print with a non-billable field as a default, then you'd be able to remove the billable/non-billable field altogether.
Quote from: dubb

Quote
I know CAB's batch plot routine,....

hehe..his routine seems like it would work..but i tore up my hair trying to get it to work....so then i tried to create it myself.

Take it block by block. Learn what's going on in each defun and how it's happening. I know it's a bit higher level than what you're at, but you should be able to wade through it. Ask questions on it, when you don't understand how something works.

This seems like a very useful project; good for your learning and maybe others' might have a use for it.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #14 on: May 04, 2005, 04:08:47 PM »
is there  a way to execute another function after the "Plot" command in autocad?

my best guess....REACTOR?

daron

  • Guest
output a .txt file
« Reply #15 on: May 04, 2005, 04:35:37 PM »
That would be the way. Let's see if we could avoid using them though. Reactors are best left to last resort. Then, I'd use VBA. It's easier and there's less code involved. At least what I've seen.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #16 on: May 13, 2005, 12:08:18 PM »
i just want to post what ive done so far...i know its been a while but ive been using this new code it works for me but there are still little flaws

Code: [Select]

;;Wynn Engineering Inc.
;;plog.LSP file CREATED BY SOUK
;;souksavanh nomichith
;;last update 05-04-05

;;text will be printed out in this format
;;job number[jn];job name[jna];sheet size[shts];thedate;user;b/nb[billable or non-billable]


;;start of date function from the help of "http://www.afralisp.com/lispa/lisp40a.htm"
;;
(defun today( / d yr mo day)
;define the function and declare all variabled local
(setq d (rtos (getvar "CDATE") 2 6)
     ;get the date and time and convert to text

          yr (substr d 3 2)
 ;extract the year

          mo (substr d 5 2)
 ;extract the month

         day (substr d 7 2)
;extract the day

     );setq

     (strcat mo "/" day "/" yr)
     ;string 'em together
)
;;
;;end of date function

(defun c:plog ( / jn jna shts userN thedate bill stringoutput fileopen)

 
;;start of collected information starts here

(setq jn (getvar "dwgname"))
(substr jn 1 (- (strlen jn) 4)) ;;shortening the dwgname by 4 characters
(setq jna (getstring "Job name: "))

(initget "D D2 E E2 LD LT M _24x36 12x18 30x42 21x15 Ledger Letter Mylar")
(setq shts (getkword "What sheet size (D/D2/E/E2/LD (ledger)/LT (letter)/M (mylar): ")) ;;ask user for the sheet size according
  ;;to sheet letter

(setq userN (getvar "loginname"))
(setq thedate (today))
 
(initget "Yes No _B Nb")
(setq bill (getkword "Is this billable (Yes/No): ")) ;;ask user if its billable or not
  ;;Y for yest N for no
 
(setq stringoutput (strcat jn","jna","shts","thedate","userN","bill","))
;;end of collected information
 
;;start of editing output text
(setq file_open (open "S:\\WYNN-CAD\\plotterlog.CSV" "a"))
(write-line stringoutput file_open)
(close file_open)
  ;;end of output text
(princ)
  );;end defun



i changed it to make a .csv file so that it can be read from excel. one of the things that need to be done is a legit way to get it to execute after the autocad "plot" command.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #17 on: May 19, 2005, 07:33:39 PM »
how do i add a dialogue control box for this lisp file that i had created...?

daron

  • Guest
output a .txt file
« Reply #18 on: May 20, 2005, 08:38:40 AM »
The code's a nice start. I didn't see that last week. As for the dcl, I'll have to defer.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #19 on: May 20, 2005, 02:25:35 PM »
thanks, i have done some research myself, but it seems like vlisp or vba would be simple..is it? how about dcl in lisp format....can it be done without have a separate dcl file?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
output a .txt file
« Reply #20 on: May 20, 2005, 05:04:54 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
output a .txt file
« Reply #21 on: May 20, 2005, 06:16:58 PM »
See if this will get you started.
You have to debug it. :)

Code: [Select]
;;Wynn Engineering Inc.
;;plog.LSP file CREATED BY SOUK
;;souksavanh nomichith
;;last update 05-04-05

;;text will be printed out in this format
;;job number[jn];job name[jna];sheet size[shts];thedate;user;b/nb[billable or non-billable]


;;start of date function from the help of "http://www.afralisp.com/lispa/lisp40a.htm"
;;
(defun today (/ d yr mo day)
  ;;define the function and declare all variabled local
  (setq d   (rtos (getvar "CDATE") 2 6)
  ;get the date and time and convert to text
        yr  (substr d 3 2) ;extract the year
        mo  (substr d 5 2) ;extract the month
        day (substr d 7 2) ;extract the day

  ) ;setq

  (strcat mo "/" day "/" yr) ;string 'em together
)
;;end of date function

(defun c:plog (/ jn jna shts userN thedate bill stringoutput fileopen
               spicked ok)

  ;;start of collected information starts here

  (setq jn (getvar "dwgname"))
  (substr jn 1 (- (strlen jn) 4))
  ;;shortening the dwgname by 4 characters
  (setq userN (getvar "loginname"))
  (setq thedate (today))

  (setq sheets '("D" "D2" "E" "E2" "LD" "LT" "M" "_24x36" "12x18" "30x42"
                 "21x15" "Ledger" "Letter" "Mylar"
                )
  )

  ;;====================================================
  (cond
    ;;  open the dcl file
    ((not (setq dcl_id (load_dialog "job-data.dcl")))
     (alert "DCL File not found. - Aborting.")
     (exit)
    )
    ;;  verify the dialog name is in the dcl file
    ;;  here we are using "main_dialog_name"
    ((not (new_dialog "jobdata" dcl_id))
     (alert "DCL Label not found. - Aborting.")
     (exit)
    )
  ) ; end cond stmt

  ;; populate the list box
  (start_list "ssize")
  (mapcar 'add_list sheets)
  (end_list)
  (action_tile "jbn" "(setq jbn $value)")
  (action_tile "ssize" "(setq spicked (nth (atoi $value) sheets))")
  (action_tile "Billable" "(setq bill $value)")
  (setq ok (= (start_dialog) 1))
  (unload_dialog dcl_id)
  ;;===================================================
  (if (and spicked ok )
    (progn
      ;;  jbn = the job name - needs error checking for empty string
      ;;  spicked = the sheet size
      (if (and bill (= bill "1"))
        (setq bill "Yes")
        (setq bill "No")
      )
     
      (setq stringoutput
             (strcat jn "," jna "," spicked "," thedate "," userN "," bill ",")
      )
      ;;end of collected information

      ;;start of editing output text
      (setq file_open (open "S:\\WYNN-CAD\\plotterlog.CSV" "a"))
      (write-line stringoutput file_open)
      (close file_open)
      ;;end of output text
    (prompt "\n***  Log Created  ***")
    )
    (prompt "\n***  User Quit  ***")
  )
  (princ)
);end defun
(prompt "\n***  plog loaded, enter plog to run.  ***")
(princ)


DCL File
Code: [Select]
//DCL file name job-data.dcl
jobdata : dialog {
    label = " Job Log" ;
  : edit_box {
    label = "Job Name";
    key = "jbn";
    edit_width = 20;
  }

  : list_box {
    key = "ssize";
    width = 16;
    multiple_select = true;
  }
  : toggle {
    key = "Billable"; // Be careful as the key is case sensitive
    label = "Billable";
  }
  ok_cancel;
}  
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #22 on: May 23, 2005, 06:44:19 PM »
hey this is perfect to get me started..now all i have to do is add some more stuff...but thanks for getting the .dcl file for me....thanks

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
output a .txt file
« Reply #23 on: May 23, 2005, 07:52:52 PM »
You're welcome.

Enjoy.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dubb

  • Swamp Rat
  • Posts: 1105
output a .txt file
« Reply #24 on: May 25, 2005, 02:28:57 PM »
ok now i got the dialogue running and the lisp file working in order...maybenot any error checking but it does the job...what ya think?

the lisp file
Code: [Select]
;;Wynn Engineering Inc.
;;plog.LSP file CREATED BY SOUK
;;souksavanh nomichith
;;www.cadtechnic.theswamp.org
;;last update 05-04-05
;;last update 05-25-05
;;;integrated plog dialogue




;AUTOLISP CODING STARTS HERE
(prompt "\nType PLOG to run plot logging.....")
;;;thanks to www.theswamp.org
;;;getting the date function provided by www.afralisp.com
;;;
(defun today( / d yr mo day)
;define the function and declare all variabled local

(setq d (rtos (getvar "CDATE") 2 6)
     ;get the date and time and convert to text

          yr (substr d 3 2)
 ;extract the year

          mo (substr d 5 2)
 ;extract the month

         day (substr d 7 2)
;extract the day

     );setq

     (strcat mo "/" day "/" yr)
     ;string 'em together
)
;;end of date function
;;

(defun C:plog ( / dcl_id usern bill jn jna thedate ssize paper numplot file_open)

;;setting up data for the log
 
  (setq thedate (today))
  (setq userN (getvar "loginname"))
  (setq jn (getvar "dwgname"))
  (substr jn 1 (- (strlen jn) 4))
  ;;shortening the dwgname by 4 characters


;;load the dialog here
;;;
(setq dcl_id (load_dialog "plog.dcl"))
     (if (not (new_dialog "plog" dcl_id))
(exit )
     );if

;;callbacks for dialogs
;;
(set_tile "JNa" "Enter job name here")
(mode_tile "JNa" 2)
(action_tile "JNa" "(setq JNa $value)")
(action_tile "NumPlot" "(setq NumPlot $value)")
(action_tile "accept" "(val1)")

;;paper grade callbacks
(action_tile "bond" "(setq paper $key)")
(action_tile "vellum" "(setq paper $key)")
(action_tile "mylar" "(setq paper $key)")

;;paper size callbacks
(action_tile "24x36" "(setq ssize $key)")
(action_tile "12x18" "(setq ssize $key)")
(action_tile "30x42" "(setq ssize $key)")
(action_tile "21x15" "(setq ssize $key)")
(action_tile "11x17" "(setq ssize $key)")
(action_tile "8.5x11" "(setq ssize $key)")

;;billing section callbacks
(action_tile "Billed" "(setq bill $key)")
(action_tile "Not-Billed" "(setq bill $key)")


(start_dialog)
(unload_dialog dcl_id)
;;end of dialogue and unloading
;;;
 
;;gathered information to print into pop-up alert
;;message to confirm the collected information
(alert (strcat "The project " JNa " has been plotted " "on " ssize " " paper " " bill " " NumPlot " time(s) by " usern ))

(princ)

);defun

-----------------------;;job name error checking

(defun val1 ()

(if (= (get_tile "JNa") "Enter Job Name Here")
(progn
  (set_tile "error" "You must enter a job name!")
  (mode_tile "JNa" 2)
);progn
(val2)
);if

);defun

-------------------;;number of plots error checking

(defun val2 ()

(if (< (atoi (get_tile "NumPlot")) 1)
(progn
 (set_tile "error" "Invalid number - Please Try Again!!")
 (mode_tile "NumPlot" 2)
);progn
(done_dialog)
  )
 
(setq stringoutput (strcat thedate "," jn "," jna "," ssize "," userN "," bill "," numplot "," ))
;;end of collected information
 
;;start of editing output text
(setq file_open (open "S:\\Plog\\plotterlog.CSV" "a"))
(write-line stringoutput file_open)
(close file_open)
;;end of output text

(princ)
  );;end defun


the dcl file
Code: [Select]

//Wynn Engineering Inc.
//plog.LSP file CREATED BY SOUK
//souksavanh nomichith
//last update 05-25-05
//plot log dcl file needed to run plog


plog

: dialog

{

label = "Wynn Engineering PlotLog";

//job name
: edit_box
{
label = "Enter the job name :";
mnemonic = "N";
key = "JNa";
alignment = centered;
edit_limit = 30;
edit_width = 30;
}
: edit_box
{

//number of plots
label = "Enter the number of plots :";
mnemonic = "A";
key = "NumPlot";
alignment = centered;
edit_limit = 3;
edit_width = 3;
value = "";
}

//paper grade
  : boxed_radio_row {
    label = "Select Paper Grade";
    mnemonic = "S";
  : radio_button {
    label = "Bond";
    mnemonic = "B";
    key = "bond";
  }
  : radio_button {
    label = "Vellum";
    mnemonic = "V";
    key = "vellum";
  }
  : radio_button {
    label = "Mylar";
    mnemonic = "M";
    key = "mylar";
}
}
//sheet sizes
: boxed_radio_row {
label = "Select sheet size";
mnemonic = "ss";
:radio_button {
label = "24x36";
mnemonic = "D";
key = "24x36";  
}
:radio_button {
label = "12x18";
mnemonic = "D";
key = "12x18";  
}
:radio_button {
label = "30x42";
mnemonic = "D";
key = "30x42";  
}
:radio_button {
label = "21x15";
mnemonic = "D";
key = "21x15";  
}
:radio_button {
label = "11x17";
mnemonic = "D";
key = "11x17";  
}
:radio_button {
label = "8.5x11";
mnemonic = "D";
key = "8.5x11";  
}
}
//billing section
: boxed_radio_row {
label = "Select billing";
mnemonic = "b";

:radio_button {
label = "Billable";
mnemonic = "D";
key = "Billed";  
}
:radio_button {
label = "Non-Billable";
mnemonic = "D";
key = "Not-Billed";  
}
       
    }ok_cancel;
 }
 

//DCL CODING ENDS HERE

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
output a .txt file
« Reply #25 on: May 25, 2005, 02:51:07 PM »
dubb,
If it works, I consider that a success.
I wish I had time to look at it but I'm packing & won't return till the 6th.
So if I were you, just use it and if it breaks find out what needs to be done
to prevent that from happening again.
If you wand a real test ask Dan to test it for you. :)
Just kidding.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.