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

0 Members and 1 Guest are viewing this topic.

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.