Author Topic: Edit & Insert External Txt File  (Read 4317 times)

0 Members and 1 Guest are viewing this topic.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Edit & Insert External Txt File
« on: September 21, 2011, 11:57:32 AM »
I just finished the attached lisp routine to edit and insert *.txt files, if you execute the function with the text file also attached as an example you will see the "-" at the end of line 11.  Any ideas on how to get rid if this in this example?

Bruce

edit added code (sorry forgot)

Code: [Select]

(defun c:ednotes (/ fileloc ext ftitle filenm pt1 filen linetext cnt nmb FileE edit insert dclfile allngth ollngth)

  (setq dclfile "c:\\program files\\septic assistant\\note files\\temp.dcl")
  (setq fileloc "c:\\program files\\septic assistant\\note files\\General Notes")
  (setq ext "txt") 

 (defun createdcl (/ )
    (setq FileE(open dclfile "w"))
    (write-line "ednotes: dialog {label = \"Edit / Insert Std Notes ?\";: boxed_row {: row  {: button {label= \"Edit\";key = \"edit\";is_cancel
                 = true;width = 10;fixed_width = true;}: button {label= \"Insert\";key = \"insert\";is_cancel = true;width = 10;fixed_width = true
                 ;}: button {label = \"Cancel\";is_cancel = true;key = \"cancel\";width = 4;fixed_width = true;}}}: text {label =
                 \"Septic Assistant - 2011\";alignment = centered; }}" FileE)
    (close FileE)
    );end of function

  (defun calldcl (/ dcl_id)
    (setq dcl_id(load_dialog dclfile))
    (new_dialog "ednotes" dcl_id)
    (set_tile    "edit" "0")
    (action_tile "edit" "(setq edit $value)")
    (mode_tile "insert" 2)
    (set_tile    "insert" "0")
    (action_tile "insert" "(setq insert $value)")   
    (action_tile "cancel" "(deldcl)(end)")
    (start_dialog )
    (unload_dialog dcl_id)
    );end of function

  (defun end (/ )
    (princ  "\n- Function Cancelled. -  ")
    (exit)
    );defun

  (defun deldcl (/ )
    (vl-file-delete dclfile)
    )

  (defun mltline (/ #lns lcnt mlinetext stline)   
    (setq #lns (/ allngth ollngth))
    (if (/= #lns (fix #lns))
      (setq #lns (+ (fix #lns) 1))
      );if
    (setq lcnt 0)
    (while (/= lcnt #lns)
      (setq stline (+(* lcnt (fix ollngth))1))
      (if (= lcnt 0)
(setq mlinetext (strcat (itoa nmb)".- " (substr linetext stline (fix ollngth))"-"))
(if (/= (- #lns 1) lcnt)
  (setq mlinetext (strcat "    " (substr linetext stline (fix ollngth))"-"))
  (setq mlinetext (strcat "    " (substr linetext stline (fix ollngth))))
  );if
);if
      (command "text" "" mlinetext )
      (setq lcnt (+ 1 lcnt))
      );while end of function
    );end of function


  (defun insertt (/ )
    (setq pt1 (getpoint "Starting Point of Text;"))
    (setq FileN(open filenm "r"))
    (setq ollngth(float(atoi (read-line FileN))))
    (setq linetext(read-line FileN))
    (command "text" pt1 "0" linetext )
    (setq nmb 0)
    (setq cnt 1)
    (while (= cnt 1)
      (setq nmb(+ nmb 1))
      (setq linetext (read-line FileN))
      (if (= linetext nil)
(progn
  (setq cnt 2)
  (Close FileN)
  );progn
(progn
  (if (< (setq allngth(strlen linetext)) ollngth)
    (progn
      (setq linetext(strcat (itoa nmb)".- " linetext))
      (command "text" "" linetext )
      );progn
    (mltline)
    );if
  );progn
);if
      );while
    );end of function

  (setq ftitle "Note Files Available for Editing and Inserting")
  (setq filenm (getfiled ftitle fileloc ext 0))
  (createdcl)
  (calldcl)
  (if (= edit "1")
    (progn
      (command "start" (strcat "notepad " filenm))
      (calldcl)
      (if (= insert "1")
(insertt)
);if
      );progn
    (insertt)
    );if
  (deldcl) 
  (princ          "\n        -  Function Successfully Completed -")
  (princ)
  );end of function



« Last Edit: September 21, 2011, 02:17:35 PM by snownut2 »

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Edit & Insert External Txt File
« Reply #1 on: September 21, 2011, 05:03:31 PM »
Hi Bruce,

Please study my modifications in the attached LISP file.

You might also be interested in this function.

Lee
« Last Edit: September 21, 2011, 05:09:25 PM by Lee Mac »

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Edit & Insert External Txt File
« Reply #2 on: September 22, 2011, 07:53:06 AM »
Thanks Lee for your response.

You probably got a good chuckle after looking at my very novice code writing techniques.


Bruce

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Edit & Insert External Txt File
« Reply #3 on: September 22, 2011, 07:55:09 AM »
You probably got a good chuckle after looking at my very novice code writing techniques.

Your code wasn't too bad Bruce, maybe needing a little more error trapping and better DCL handling, but other than that, not too bad.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Edit & Insert External Txt File
« Reply #4 on: September 22, 2011, 02:30:11 PM »
Bruce you may find this of interest.  8-)
http://www.theswamp.org/index.php?topic=1392.0
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.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Edit & Insert External Txt File
« Reply #5 on: September 22, 2011, 07:07:26 PM »
Bruce you may find this of interest.  8-)
http://www.theswamp.org/index.php?topic=1392.0

Now that's what you call a Dialog  :lol:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Edit & Insert External Txt File
« Reply #6 on: September 22, 2011, 09:11:42 PM »
Yea it keeps growing  :-o

I uploaded a picture of 9.8
You need a wide screen for that one.  :evil:
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Edit & Insert External Txt File
« Reply #7 on: September 22, 2011, 11:21:19 PM »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7531

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC