arri
Guest
nel caso non si avesse a disposizione il file .pat
http://www.turvill.com/t2/free_stuff/getpat.lsp
;|
getpat.lsp (c) 2001 tee square graphics
version 1.01b - 1/22/2002
this routine may be used to extract hatch pattern data
from existing drawings when the .pat file containing
the original information is not available.
after loading the file in the usual manner, type the
command getpat at the autocad command: prompt, select
any (non-solid) hatch object, and the pattern information
will be written to a .pat file having the same name as
the pattern (e.g., pattern information for the hatch
pattern woods will be written to woods.pat.
ver. 1.01b includes two small fixex to eliminate "bad
argument" lisp errors when run with certain installations
of autocad 2000+.
|;
(defun c:getpat (/ cmde hat elst rotn hnam temp xofs yofs what
temp outf flin angl tmp1 tmp2 xvec yvec)
(setq cmde (getvar "cmdecho"))
(setvar "cmdecho" 0)
(while (not (setq hat (entsel "\nselect hatch: "))))
(setq elst (entget (car hat)))
(if (= (cdr (assoc 0 elst)) "hatch")
(progn
(setq rotn (* 180 (/ (cdr (assoc 52 elst)) pi))
hnam (cdr (assoc 2 elst))
hscl (cdr (assoc 41 elst))
)
;; the following nine lines may optionally be omitted.
;; their purpose is to create a temporary "clone" of the
;; selected hatch with a 0 deg. rotation angle, in case
;; the hatch object specified a rotation angle. if these
;; lines are omitted, the current rotation of the selected
;; hatch will become the "0" deg. rotation for the extracted
;; pattern definition.
(if (not (zerop rotn))
(progn
(setq temp elst)
(entmake temp)
(command "_.rotate" (entlast) "" (cdr (assoc 10 temp))(- rotn))
(setq elst (entget (entlast)))
(entdel (entlast))
)
)
;; end of optional code.
(setq xofs (cdr (assoc 43 elst))
yofs (cdr (assoc 44 elst))
elst (member (assoc 53 elst) elst)
)
(setq outf (strcat hnam ".pat"))
(if (findfile outf)
(progn
(initget "overwrite append")
(setq what (getkword (strcat "\n" outf " already exists; overwrite/append? ")))
)
)
(setq outf (open outf (if (= what "append") "a" "w"))
flin (strcat "*" hnam)
)
(foreach x elst
(cond
((= (car x) 53)
(write-line flin outf)
(setq angl (cdr x)
flin (trim (angtos angl 0 7))
)
)
((= (car x) 43)
(setq flin (strcat flin ", " (trim (rtos (/ (- (cdr x) xofs) hscl) 2 7))))
)
((= (car x) 44)
(setq flin (strcat flin "," (trim (rtos (/ (- (cdr x) yofs) hscl) 2 7))))
)
((= (car x) 45)
(setq tmp1 (cdr x))
)
((= (car x) 46)
(setq tmp2 (cdr x)
xvec (/ (+ (* tmp1 (cos angl))(* tmp2 (sin angl))) hscl)
yvec (/ (- (* tmp2 (cos angl))(* tmp1 (sin angl))) hscl)
flin (strcat flin ", " (trim (rtos xvec 2 7)) "," (trim (rtos yvec 2 7)))
)
)
((= (car x) 49)
(setq flin (strcat flin ", " (trim (rtos (/ (cdr x) hscl) 2 7))))
)
((= (car x) 98)
(write-line flin outf)
)
(t nil)
)
)
(write-line "" outf)
(close outf)
(alert (strcat hnam " pattern definition written to " hnam ".pat"))
)
(alert "selected object not a hatch.")
)
(setvar "cmdecho" cmde)
(princ)
)
(defun trim (x / n)
(setq n (strlen x))
(while (= (substr x n 1) "0")
(setq n (1- n)
x (substr x 1 n)
)
)
(if (= (substr x n 1) ".")
(setq x (substr x 1 (1- n)))
)
x
)
(alert
(strcat "getpat.lsp (c) 2003 tee square graphics\n"
" type getpat to start"
)
)
(princ)
http://www.turvill.com/t2/free_stuff/getpat.lsp
;|
getpat.lsp (c) 2001 tee square graphics
version 1.01b - 1/22/2002
this routine may be used to extract hatch pattern data
from existing drawings when the .pat file containing
the original information is not available.
after loading the file in the usual manner, type the
command getpat at the autocad command: prompt, select
any (non-solid) hatch object, and the pattern information
will be written to a .pat file having the same name as
the pattern (e.g., pattern information for the hatch
pattern woods will be written to woods.pat.
ver. 1.01b includes two small fixex to eliminate "bad
argument" lisp errors when run with certain installations
of autocad 2000+.
|;
(defun c:getpat (/ cmde hat elst rotn hnam temp xofs yofs what
temp outf flin angl tmp1 tmp2 xvec yvec)
(setq cmde (getvar "cmdecho"))
(setvar "cmdecho" 0)
(while (not (setq hat (entsel "\nselect hatch: "))))
(setq elst (entget (car hat)))
(if (= (cdr (assoc 0 elst)) "hatch")
(progn
(setq rotn (* 180 (/ (cdr (assoc 52 elst)) pi))
hnam (cdr (assoc 2 elst))
hscl (cdr (assoc 41 elst))
)
;; the following nine lines may optionally be omitted.
;; their purpose is to create a temporary "clone" of the
;; selected hatch with a 0 deg. rotation angle, in case
;; the hatch object specified a rotation angle. if these
;; lines are omitted, the current rotation of the selected
;; hatch will become the "0" deg. rotation for the extracted
;; pattern definition.
(if (not (zerop rotn))
(progn
(setq temp elst)
(entmake temp)
(command "_.rotate" (entlast) "" (cdr (assoc 10 temp))(- rotn))
(setq elst (entget (entlast)))
(entdel (entlast))
)
)
;; end of optional code.
(setq xofs (cdr (assoc 43 elst))
yofs (cdr (assoc 44 elst))
elst (member (assoc 53 elst) elst)
)
(setq outf (strcat hnam ".pat"))
(if (findfile outf)
(progn
(initget "overwrite append")
(setq what (getkword (strcat "\n" outf " already exists; overwrite/append? ")))
)
)
(setq outf (open outf (if (= what "append") "a" "w"))
flin (strcat "*" hnam)
)
(foreach x elst
(cond
((= (car x) 53)
(write-line flin outf)
(setq angl (cdr x)
flin (trim (angtos angl 0 7))
)
)
((= (car x) 43)
(setq flin (strcat flin ", " (trim (rtos (/ (- (cdr x) xofs) hscl) 2 7))))
)
((= (car x) 44)
(setq flin (strcat flin "," (trim (rtos (/ (- (cdr x) yofs) hscl) 2 7))))
)
((= (car x) 45)
(setq tmp1 (cdr x))
)
((= (car x) 46)
(setq tmp2 (cdr x)
xvec (/ (+ (* tmp1 (cos angl))(* tmp2 (sin angl))) hscl)
yvec (/ (- (* tmp2 (cos angl))(* tmp1 (sin angl))) hscl)
flin (strcat flin ", " (trim (rtos xvec 2 7)) "," (trim (rtos yvec 2 7)))
)
)
((= (car x) 49)
(setq flin (strcat flin ", " (trim (rtos (/ (cdr x) hscl) 2 7))))
)
((= (car x) 98)
(write-line flin outf)
)
(t nil)
)
)
(write-line "" outf)
(close outf)
(alert (strcat hnam " pattern definition written to " hnam ".pat"))
)
(alert "selected object not a hatch.")
)
(setvar "cmdecho" cmde)
(princ)
)
(defun trim (x / n)
(setq n (strlen x))
(while (= (substr x n 1) "0")
(setq n (1- n)
x (substr x 1 n)
)
)
(if (= (substr x n 1) ".")
(setq x (substr x 1 (1- n)))
)
x
)
(alert
(strcat "getpat.lsp (c) 2003 tee square graphics\n"
" type getpat to start"
)
)
(princ)