Вы находитесь на странице: 1из 14

;;; RasDraw.lsp Version 1.1.7 ;;; Created Mar.01, 2005 ;;; By: D.

Guindon ;;; ;;;This program utilizes Rasterdesign and AutoCAD commands to aid in the ;;;drawing and editing of raster images (commands will also edit AutoCAD ;;;vector entities if picked). ;;; ;;;All commands are available at the command line. ;;;To invoke a command, press only the related Accelerator Key. ;;;(Pressing Return is not required). ;;;Once a command has been invoked, press [return] to complete the command seque nce. ;;;For example to draw a line: ;;; Press [L] ;;; Pick Start point ;;; Pick End point ;;; Press [return] to complete command sequence. ;;; ;;;Available commands are (press capitalized character to invoke command): ;;; ;;; 1 - Saves active image ;;; 2 - Toggles image frame on/off ;;; 3 - Pan ;;; 4 - Zoom ;;; 5 - Savetime Sets Savetime variable (in minutes) for Autosave function. ;;; A - Arc (draws arc) ;;; B - Box (draws rectangle) ;;; C - Circle (draws circle) ;;; D - Dot (draws solid donut) ;;; E - Erase (erases raster area or Acad Entities selected) ;;; Erase Options: ;;; C - Erase Circular Region ;;; D - Erase Diagonal Region ;;; L - Erase raster under Pline ;;; M - Multiple Erase Mode (loop) ;;; N - Issues Standard Acad Erase command (erases Acad entities onl y) ;;; P - Erase Region defined by closed Pline ;;; S - Erase Smart Pick ;;; V - Erase raster under Vector ;;; F - Flip (mirrors raster area or Acad Entities selected) ;;; G - polyGon (draws polygon) ;;; I - sketch_Inc (sets sketch resolution) ;;; K - despecKle (invokes Raster Design Despeckle command) ;;; L - Line (draws line) ;;; M - Move (moves raster area or Acad Entities selected) ;;; N - aligN (invokes Raster Design Deskew command to align drawing) ;;; O - cOpy (creates copies of raster area or Acad Entities selected) ;;; P - Pline (draws pline) ;;; R - Rotate (rotates raster area or Acad Entities selected) ;;; S - Sketch (draws freehand sketch) ;;; T - Text (draws text) HINT - use Fit justification to fit text in allowab le space or ;;; enter other options [Align/Fit/Center/Middle/Right/TL/TC/TR/ML/M C/MR/BL/BC/BR] ;;; ;;; U - Undo (undoes last step) See note 1. below. ;;; V - oVal (draws ellipse) ;;; W - lineWidth (sets raster pen width)

;;; X - Xmerge (merges selected Vectors, Images or REM objects to raster image) ;;; Y - arraY (creates an array of raster area or Acad Entities selected) ;;; Z - siZe (scales raster area or Acad Entities selected) ;;; ;;; Note 1. For each consecutive Undo issued, the undo command undoes a single ;;; operation, giving the option to issue a Redo after each step. ;;; This is necessary as RasterDesign has limited Undo support and will Undo all ;;; Image Edits automatically once 10 edits or 2 erase edits have been u ndone. ;;; ;;; *** RasDraw *** ;;; Main Command-Line User-Interface/Loop ;;; Accepts: Nothing ;;; Returns: Nothing (vl-load-com) (defun rasdraw ( / imagentt tsz oldwid loop ntt inc gr gr0 gr1 xcnt xnt xlst xty p undolst a cmd) (setq olderr *error*) (setq *error* dwgerr) (setvar "limcheck" 0) (setq oldecho (getvar "cmdecho")) (setvar "cmdecho" 0) (setq oldos (getvar "osmode")) (setq cecolor (getvar "cecolor")) (setvar "cecolor" "red") (setq oldplinewid (getvar "plinewid")) (setvar "plinewid" 0.0) (setq oldinc (getvar "sketchinc")) (setq tsz (getvar "textsize")) (setvar "sketchinc" (/ tsz 20.0)) (setq oldpoly (getvar "skpoly")) (setvar "skpoly" 1) (if (setq imagentt (getimage)) (progn (cond ((findfile "AeciUi42.arx") (arxload (findfile "AeciUi42.arx")) ) (t nil) ) (command ".undo" "control" "all") (if rpenwid (command "-rpens" "modify" "all" "acad" (setq oldwid rpenwid)) (command "-rpens" "modify" "all" "acad" (setq rpenwid (/ tsz 6.6667) old wid (/ tsz 6.6667))) ) (setq loop 1) (while (= loop 1) (autosave) (if mv (m 2)) (redraw imagentt 3) (setq ntt (lastent)) (setq inc (getvar "sketchinc")) (setvar "cmdecho" 1) (prompt "\nEnter [Arc/Box/Circle/Dot/Line/oVal/Pline/polyGon/Text/Sketch /sketch_Inc/lineWidth/aligN/arraY/cOpy/despecKle/Erase/Flip/Move/siZe/Rotate/Xme rge/Undo]: ") (setq gr (grread) gr0 (nth 0 gr) gr1 (nth 1 gr))

(if (= gr0 2) (setq gr1 (strcase (chr gr1)))) (cond ((or (= gr1 "_") (= gr1 "'")) (setq cmd gr1) (while (/= " " (setq a (chr (nth 1 (grread))))) (setq cmd (strcat cmd a)) ) (command cmd) (cmdloop) ) ((= gr0 3) (if (and (= 'LIST (type gr1)) (= 3 (length gr1))) (if (nentselp gr1) (command "._pselect" gr1 "" "._properties") ) (alert "Invalid Input.") ) ) ((= gr0 11) nil) ((= gr0 25) (setq loop nil)) ((= gr1 "A") (m 0) (draw ".arc" ntt imagentt)) ((= gr1 "B") (m 0) (draw ".rectangle" ntt imagentt)) ((= gr1 "C") (m 0) (draw ".circle" ntt imagentt)) ((= gr1 "D") (m 0) (draw ".donut" ntt imagentt)) ((= gr1 "E") (erase)) ((= gr1 "F") (m 0) (edit ".mirror")) ((= gr1 "G") (m 0) (draw ".polygon" ntt imagentt)) ((= gr1 "I") (command ".Sketchinc" (getdist (strcat "\nEnter new value for SKETCHINC <" (rtos (getvar "sketc hinc")) ">: ") ) ) ) ((= gr1 "K") (m 1) (command "idespeckle") (cmdloop) ) ((= gr1 "L") (m 0) (draw ".line" ntt imagentt)) ((= gr1 "M") (m 0) (edit ".move")) ((= gr1 "N") (m 1) (command "ideskew") (cmdloop) ) ((= gr1 "O") (edit ".copy")) ((= gr1 "P") (m 0) (draw ".pline" ntt imagentt)) ((= gr1 "R") (m 0) (edit ".rotate")) ((= gr1 "S") (m 0) (setvar "orthomode" 0) (draw ".sketch" ntt imagentt) ) ((= gr1 "T") (m 0) (command ".style" "" "" 0.0) (while (> (getvar "cmdactive") 0) (command "")

) (draw ".dtext" ntt imagentt) ) ((= gr1 "U") (comminp gr1 "")) ((= gr1 "V") (m 0) (draw ".ellipse" ntt imagentt)) ((= gr1 "W") (m 1) (setvar "cmdecho" 0) (setq oldwid rpenwid) (initget 6) (if (setq rpenwid (getdist (strcat "\nEnter new value for LineWidth <" (rtos rpenwid) ">: "))) (command "-rpens" "modify" "all" "acad" (setq oldwid rpenwid)) (command "-rpens" "modify" "all" "acad" (setq rpenwid oldwid)) ) ) ((= gr1 "X") (m 1) (if (/= rpenwid oldwid) (command "-rpens" "modify" "all" "acad" (setq rpenwid oldwid)) ) (setq xcnt 0) (while (setq xnt (entsel "\nSelect object to merge: ")) (setq xlst (entget (setq xnt (car xnt)))) (setq xtyp (cdr (assoc 0 xlst))) (cond ((= "IMAGE" xtyp) (if (eq xnt imagentt) (prompt "\nCan't merge an image to itself. ") (command ".iimerge" xnt "" imagentt "yes") ) ) ((= "AECIDBREMCIRCREG" xtyp) (command ".move" xnt imagentt "" "@" "@" ".imergetoimg" xnt "" ) ) ((= "AECIDBREMPOLYREG" xtyp) (command ".move" xnt imagentt "" "@" "@" ".imergetoimg" xnt "" ) ) ((or (= "TEXT" xtyp) (= "MTEXT" xtyp)) (command "-rpens" "modify" "all" "acad" (setq rpenwid (/ (cdr (assoc 40 xlst)) 8.0))) (command ".ivmerge" xnt imagentt "" "") ) (t (command ".ivmerge" xnt imagentt "" "")) ) (cmdloop) (setq xcnt (+ xcnt 1)) ) ) ((= gr1 "Y") (m 0) (edit ".array")) ((= gr1 "Z") (m 0) (edit ".scale")) (t (comminp gr1 "Invalid RasDraw Option <")) ) ) (dwgerr "") ) (dwgerr " ") )

) ;;;*** GetImage *** ;;; Image Selection Routine ;;; Accepts: Nothing ;;; Returns: ename of selected image (defun getimage ( / cnt imglst sset ename gr gr1 gr2 chk n) (setq cnt 0 imglst nil) (setq ss1 (ssget "x" '((0 . "IMAGE"))) ss2 (ssget "x" '((0 . "AECIDBEMBEDDEDRASTERIMAGE"))) ) (if ss1 (while (setq ename (ssname ss1 cnt)) (setq imglst (append imglst (list ename))) (setq cnt (+ cnt 1)) ) ) (setq cnt 0) (if ss2 (while (setq ename (ssname ss2 cnt)) (setq imglst (append imglst (list ename))) (setq cnt (+ cnt 1)) ) ) (cond ((null imglst) (prompt "\nNo editable images found in drawing. ")) ((= (length imglst) 1) (setq chk (nth 0 imglst)) (command ".imageframe" 1 ".transparency" chk "" "on") ) ((> (length imglst) 1) (command ".imageframe" 1) (foreach n imglst (command ".transparency" n "" "on") ) (if **imagentt** (prompt "\nSelect Image to edit or [Previous] <p>: ") (prompt "\nSelect Image to edit: ") ) (setq gr (grread nil 2 2) gr1 (nth 0 gr) gr2 (nth 1 gr)) (cond ((= gr1 2) (if (or (= gr2 13) (= (strcase (chr gr2)) "P")) (setq chk **imagentt**) ) ) ((= gr1 3) (if (= 'LIST (type gr2)) (if (setq chk (nentselp gr2)) (if (null (member (setq chk (car chk)) imglst)) (setq chk (prompt "\nInvalid selection. Please select a Named Im age. ")) ) (setq chk (prompt "\nNothing selected. ")) ) ) ) ((= gr1 25) (setq chk **imagentt**))

) ) ) (if chk (if (setq g340 (assoc 340 (entget chk))) (if (findfile (setq imagepath (cdr (assoc 1 (entget (cdr g340)))))) (setq **imagentt** chk) (setq **imagentt** (alert (strcat "\nInvalid path: " imagepath "\n\nPlease use 'Image Command' to Browse for Image file and 'Save PATH'.") ) ) ) (setq **imagentt** chk) ) ) ) ;;;*** Draw *** ;;; Draw Routine ;;; Accepts: cmd as String ; ntt as ename ; imagentt as ename ;;; Returns: Nothing ;;; cmd = AutoCAD drawing command name, e.g. "Line" ;;; ntt = ename of Last entity in drawing database ;;; imagentt = ename of image being edited (defun draw (cmd ntt imagentt) (prompt "\n") (command cmd) (cond ((equal ".sketch" cmd) (command "")) ((equal ".donut" cmd) (command "0.0")) (t nil) ) (cmdloop) (setvar "cmdecho" 0) (cond ((equal ".dtext" cmd) (command "-rpens" "modify" "all" "acad" (setq rpenwid (/ (getvar "textsize ") 8.0))) ) ((/= rpenwid oldwid) (command "-rpens" "modify" "all" "acad" (setq rpenwid oldwid)) ) ) (rasadd ntt imagentt) ) ;;;*** Edit *** ;;; Edit Routine ;;; Accepts: cmd as String ;;; Returns: Nothing ;;; cmd = AutoCAD edit command name, e.g. "Copy" (defun edit (cmd / sset n clear) (setq retval (select)) (setq sset (nth 0 retval) remset (nth 1 retval)) (setq ntt (lastent)) (if (> (sslength sset) 0)

(progn (command cmd sset "") (cmdloop) (if (> (sslength remset) 0) (progn (setq cnt 0) (while (setq n (ssname remset cnt)) (if (entget n) (command ".IMERGETOIMG" n "") ) (if (entget n) (command ".Iclear" n "") ) (setq cnt (+ cnt 1)) ) (while (setq ntt (entnext ntt)) (setq elist (entget ntt)) (if (= "AECIDBREM" (strcase (substr (cdr (assoc 0 elist)) 1 9))) (command ".IMERGETOIMG" ntt "") ) ) ) ) ) ) (cmdloop) ) ;;;*** Rasadd *** ;;; Merges Vector entities to Image ;;; Accepts: ntt as ename ; imagentt as ename ;;; Returns: Nothing ;;; ntt = ename of Last entity in drawing database ;;; imagentt = ename of image being edited (defun rasadd (ntt imagentt / sset) (setq sset (ssadd)) (while (setq ntt (entnext ntt)) (ssadd ntt sset) ) (if (> (sslength sset) 0) (command ".ivmerge" sset imagentt "" "") ) ) ;;;*** Lastent *** ;;; Gets last entity in database ;;; Accepts: Nothing ;;; Returns: ename of last entity in database (defun lastent ( / a b) (if (setq b (setq a (entlast))) (if (equal "INSERT" (cdr (assoc 0 (entget a)))) (while (setq a (entnext a)) (setq b a) ) (setq b a) ) ) b

) ;;;*** Select *** ;;; Raster Region Selection ;;; Accepts: Nothing ;;; Returns: Nothing (defun select ( / done sset_1 sset_2 sset_3 newntt gr gr1 gr2 chk mode cnt) (setq done nil sset_1 (ssadd) sset_2 (ssadd) sset_3 (ssadd)) (setq newntt ntt) (while (not done) (prompt "\nSelect Region option [Circular/Diagonal/Polygonal/Remove] or firs t point: ") (setq gr (grread) gr1 (nth 0 gr) gr2 (nth 1 gr)) (cond ((or (equal gr '(2 13)) (equal gr1 25)) (setq done t) ) ((= gr1 3) (if (= (type gr2) 'LIST) (if (setq chk (nentselp gr2)) (progn (if (= (length chk) 2) (setq chk (car chk)) (setq chk (car (reverse (car (reverse chk))))) ) (redraw chk 3) (if (setq sset_2 (ssget)) (ssadd chk sset_2) (setq sset_2 (ssadd chk)) ) ) (progn (command ".isrectreg" gr2) (cmdloop) ) ) ) ) ((= gr1 2) (prompt (chr gr2)) (setq mode (strcase (chr gr2))) (cond ((= "C" mode) (prompt "\n") (progn (command ".iscircreg") (cmdloop))) ((= "D" mode) (prompt "\n") (progn (command ".isdiagreg") (cmdloop))) ((= "P" mode) (prompt "\n") (progn (command ".ispolyreg") (cmdloop))) ((= "R" mode) (prompt "\nRemove objects: ") (command ".iclear") (cmdlo op)) (t (alert "Invalid selection.")) ) ) (t (setq sset_2 (prompt "Select: Invalid Option"))) ) (if (not (equal newntt (setq newntt (lastent)))) (progn (ssadd newntt sset_1) (ssadd newntt sset_3) ) ) (setq cnt 0)

(if sset_2 (progn (while (setq chk (ssname sset_2 cnt)) (redraw chk 3) (ssadd chk sset_1) (setq cnt (+ cnt 1)) ) ) ) ) (setvar "cmdecho" 0) (setvar "cmdecho" 1) (if sset_1 (list sset_1 sset_3) (cmdloop) ) ) ;;;*** Erase *** ;;; Raster Erase Routine ;;; Accepts: Nothing ;;; Returns: Nothing (defun erase ( / gr gr0 gr1 loop cnt chk sset z zz n) (setq loop 1) (setvar "cmdecho" 1) (setq undolst '(0)) (while loop (setq ntt (entlast) cnt 0) (prompt "\nErase option [Circular Diagonal Polygonal Line Smartpick Vector M ultiple Undo] or first point: ") (setq gr (grread) gr0 (nth 0 gr) gr1 (nth 1 gr)) (if (= gr0 2) (setq gr1 (strcase (chr gr1)))) (cond ((or (= gr1 "_") (= gr1 "'")) (setq cmd gr1) (while (/= " " (setq a (chr (nth 1 (grread))))) (setq cmd (strcat cmd a)) ) (command cmd) (cmdloop) ) ((= gr0 3) (prompt "\n") (m 1) (if (= (type gr1) 'LIST) (if (setq chk (nentselp gr1)) (progn (if (= (length chk) 2) (setq chk (car chk)) (setq chk (car (reverse (car (reverse chk))))) ) (redraw chk 3) (if (setq sset (ssget)) (ssadd chk sset) (setq sset (ssadd chk)) ) (while (setq n (ssname sset cnt)) (if (not (eq n **imagentt**)) (entdel n)

(alert "\nCannot erase Active Image.\nImage removed from selec tion set.") ) (setq cnt (+ cnt 1)) ) ) (command ".irubrect" gr1) ) ) ) ((= gr0 11) (m 0) nil) ((= gr0 25) (m 0) (setq loop nil)) ((= "C" gr1) (prompt "\n") (m 1) (command ".irubcirc")) ((= "D" gr1) (prompt "\n") (m 1) (command ".irubdiag")) ((= "E" gr1) (m 0) (prompt "\n")) ((= "M" gr1) (m 0) (prompt "\n") (setq loop 2)) ((= "L" gr1) (prompt "\n") (m 1) (command ".irubpline")) ((= "N" gr1) (prompt "\n") (m 1) (command ".erase")) ((= "P" gr1) (prompt "\n") (m 1) (command ".irubpoly")) ((= "S" gr1) (prompt "\n") (m 1) (command ".idelsmart")) ((= "V" gr1) (prompt "\n") (m 1) (command ".vfpline")) ((= "U" gr1) (m 0) (comminp gr1 "")) (t (m 0) (comminp gr1 "Invalid Erase option <")) ) (cmdloop) (cond ((= "V" gr1) (while (setq ntt (entnext ntt)) (entdel ntt) ) ) ) (if (= loop 1) (if (/= "E" gr1) (setq loop nil) ) ) (if (and (= loop 2) mv) (command ".undo" "end")) ) ) ;;;*** ZOOM *** (defun zoom ( / gr gr0 gr1) (command "'_.zoom") (cmdloop) ) ;;;*** CommInp *** ;;;Common User Input Options for both Main-Command-Loop and Erase-Command-Loop ;;;Accepts: gr1 as string (keyboard character pressed) ;;;Returns: Nothing (defun comminp (gr1 msg / uloop gr gr1 gr2) (cond ((= gr1 "1") (sri) ) ((= gr1 "2") (command ".iframe") )

((= gr1 "3") (command "'_.pan") (cmdloop) ) ((= gr1 "4") (zoom) ) ((= gr1 "5") (setsavetime) ) ((= "U" gr1) (command ".Undo" "1") (setq uloop t) (while uloop (prompt "\nSelect [Undo/Redo] or Enter to exit: ") (setq gr (grread)) (setq gr1 (nth 0 gr) gr2 (nth 1 gr)) (if (= gr1 2) (setq gr2 (strcase (chr gr2)))) (cond ((= gr1 25) (setq uloop nil)) ((= gr2 "\r") (setq uloop nil)) ((= gr2 "U") (command ".undo" "1")) ((= gr2 "R") (command ".redo")) (t (alert "Invalid Option. \nChoose Undo, Redo or Enter to exit.") (if (and (/= 'LIST (type gr2)) (member gr2 '("_" "'"))) (while (/= " " (chr (nth 1 (grread)))) (grread)) ) ) ) ) ) ((= "\r" gr1) (setq loop nil)) ((= gr1 "\002") (if (= (getvar "snapmode") 0) (setvar "snapmode" 1) (setvar "snapmode" 0) ) ) ((= gr1 "\004") (setq gr1 (getvar "coords")) (cond ((= gr1 0) (setvar "coords" 1)) ((= gr1 1) (setvar "coords" 2)) ((= gr1 2) (setvar "coords" 0)) ) ) ((= gr1 "\005") (setq gr1 (getvar "snapisopair")) (cond ((= gr1 0) (setvar "snapisopair" 1) (prompt "\n<Isoplane Top>")) ((= gr1 1) (setvar "snapisopair" 2) (prompt "\n<Isoplane Right>")) ((= gr1 2) (setvar "snapisopair" 0) (prompt "\n<Isoplane Left>")) ) ) ((= gr1 "\006") (if (/= (getvar "osmode") oldos) (setvar "osmode" oldos) (setvar "osmode" 0) )

) ((= gr1 "\007") (if (= (getvar "gridmode") 0) (progn (setvar "gridmode" 1) (prompt " <Gidmode On> ") ) (progn (setvar "gridmode" 0) (prompt " <Gridmode Off> ") ) ) ) ((= gr1 "\017") (if (= (getvar "orthomode") 0) (progn (setvar "orthomode" 1) (prompt " <Ortho On> ") ) (progn (setvar "orthomode" 0) (prompt " <Ortho Off> ") ) ) ) ((= gr1 "\024") (setq gr1 (getvar "tabmode")) (cond ((= gr1 1) (setvar "tabmode" 0) (alert " <Tablet Off> ")) ((= gr1 0) (setvar "tabmode" 1) (if (= (getvar "tabmode") 0) (alert "CALibrate the TABLET before turning it ON <Tablet off>") (alert " <Tabmode On> ") ) ) ) ) ((= gr1 " ") nil) (t (alert (strcat msg gr1 ">." ))) ; "Invalid RasDraw Option <" gr1 ">."))) ) ) ;;;*** MarkUndo *** ;;;This function marks beginning and end of command groups. ;;;Accepts: n as integer ;;; n = 1, mark beginning of group ;;; n = 2, mark end of group ;;;Returns: Nothing (defun m (n / n) (setq mv (cond ((= n 1) (command ".undo" "begin") t) ((= n 2) (command ".undo" "end") nil) (t nil) ) ) )

(defun cmdloop () (while (> (getvar "cmdactive") 0) (command pause) ) ) ;;;*** SRI *** ;;; Save Raster Image Routine ;;; Accepts: Nothing ;;; Returns: Nothing ;;; Saves Image file currently being edited. (defun sri () (command ".qsave") (cmdloop) ) ;;;*** SetSaveTime *** ;;;Gets user input to set savetime system variable. ;;;Accepts: Nothing ;;;Returns: Nothing (defun setsavetime ( / a b) (setq a (getvar "savetime")) (while (null b) (if (setq b (getint (strcat "\nEnter new value for SAVETIME <" (itoa a) ">: "))) (if (and (>= b 0) (<= b 600)) (setvar "savetime" b) (setq b (prompt "\nRequires an integer between 0 and 600. ")) ) (setq b t) ) ) ) ;;;*** AutoSave *** ;;;Automatically saves Image and drawing based on SaveTime system variable. ;;;Accepts: Nothing ;;;Returns: Nothing (defun autosave ( / a) (setq a (getvar "savetime")) (if (> a 0) (if (> (* 1440 (- (getvar "date") (getvar "tdupdate"))) a) (progn (prompt "\nAuto-Saving Image. ") (sri) ) ) ) ) ;;;*** DwgErr *** ;;; Error Handler ;;; Accepts: msg as string ;;; Returns: Nothing ;;; msg is Error message ;;; Resets system vars and saves image files after editing. (defun dwgerr (msg) (setq *error* olderr)

(if **imagentt** (redraw **imagentt** 4)) (if mv (command ".undo" "end")) (setvar "plinewid" oldplinewid) (setvar "osmode" oldos) (setvar "cecolor" cecolor) (setvar "cmdecho" oldecho) (setvar "sketchinc" oldinc) (setvar "skpoly" oldpoly) (if (equal msg "") (COMMAND ".QSAVE") (prompt (strcat "\n" msg)) ) (if oldwid (setq rpenwid oldwid) ) (setq oldplinewid nil oldos nil cecolor nil oldecho nil oldinc nil oldpoly nil rasdraw nil getimage nil draw nil edit nil rasadd nil mark nil lastent nil select nil erase nil zoom nil sri nil comminp nil ) (if (> (getvar "cmdactive") 0) (progn (command) (command))) (prin1) )