cg-Cad

Lisp »Tips 'n Tricks »CXYZ »1 »2 »3

CXYZ v1,2

Questo lisp è un'estensione (semplificata, nel senso che non richiede layer e file-dati txt) del lisp CXY della libreria PicK:

;|
	CXYZ.LSP (versione 1)

	Copyright (C) 2005 Claudio Piccini.
	All rights reserved

	www.cg-cad.com

|;

(defun myerror (s)                  
  (if (/= s "Function cancelled")
    (princ (strcat "\nError: " s))
  )
 (ripVar)
 (princ)
)

(defun salVar ()
 (setq orto (getvar "orthomode"))
 (setq snapp (getvar "osmode"))
 (setq snm (getvar "snapmode"))
 (setq piano (getvar "clayer"))  
)

(defun ripVar ()
 (command "_redraw")
 (setvar "cmdecho" 1)
 (setvar "osmode" snapp)
 (setvar "snapmode" snm)
 (setvar "orthomode" orto)
 (setvar "clayer" piano)
 (setvar "cecolor" "BYLAYER")
 (setq *error* olderr)
 (princ)
)

(defun CooXYZ (/ k hTesto pQ
                 pQT p1 p2 p3 p4 p5 p6
                 spazio distXY
                 nCooX nCooY nCooZ
                 cCooX cCooY cCooZ strX strY
 )
 (setq hTesto (getreal "\n Dimensione testo: "))
 (command "osnap" "_non")
 (setq k 1)
 (while k
  (command "osnap" "_int")
  (setq pQ (getpoint "\n Seleziona il punto da quotare : "))
  (if (= pQ nil)
   (setq k nil)
   (progn
    (command "osnap" "_non")
    (setq nCooX (car pQ))
    (setq nCooY (cadr pQ))
    (setq nCooZ (caddr pQ))
    (initget 1)
    (setq pQT (getpoint "\n Punto di inserimento coordinate: "))
    ;;                                       
    ;;  p5---p6
    ;;    | øx = numero       (ø p3)
    ;;    |
    ;;    | *y = numero       (* p2)
    ;;    |  
    ;;    | #z = numero       (# p1)
    ;;  p4---pQT
    ;;
    (setq spazio (/ hTesto 2))
    (setq distXY (+ hTesto (/ hTesto 2)))
    (setq p1 (list (car pQT)(+ (cadr pQT) spazio)))
    (setq p2 (list (car pQT)(+ (cadr p1) distXY)))
    (setq p3 (list (car pQT)(+ (cadr p2) distXY)))
    (setq p4 (list (- (car p2) spazio)(cadr pQT)))
    (setq p5 (list (car p4) (+ (cadr p3) spazio spazio)))
    (setq p6 (list (car pQT)(cadr p5)))
    ; disegna una parentesi quadra aperta
    (command "_pline" pQT "_w" 0.0 0.0 p4 p5 p6 "")
    ; trasforma le coordinate x,y,z in stringhe
    (setq cCooX (rtos nCooX 2 2))
    (setq cCooY (rtos nCooY 2 2))
    (setq cCooZ (rtos nCooZ 2 2))
    (setq strX (strcat "x = " cCooX))
    (setq strY (strcat "y = " cCooY))
    (setq strZ (strcat "z = " cCooZ))
    (command "_text" p3 hTesto 0.0 strX)
    (command "_text" p2 hTesto 0.0 strY)
    (command "_text" p1 hTesto 0.0 strZ)
   )
  )
 )
)

(defun C:CXYZ (/ olderr snapp snm orto piano)
 (setq olderr *error* *error* myerror)
 (setvar "cmdecho" 0)
 (salVar)
 (CooXYZ)
 (ripVar)
)
;;;eof

CXYZ

Ma scrivere la coordinata Z dei punti che appartengono al piano X, Y, Z=0 è superfluo: parte del codice di CXY torna utile come caso particolare di CXYZ.
Come al solito sono in blu le istruzioni nuove (anche se in questo caso antiche):

;|
	CXYZ.LSP (versione 2)

	Copyright (C) 2005 Claudio Piccini.
	All rights reserved

	www.cg-cad.com

|;

(defun myerror (s)                  
  (if (/= s "Function cancelled")
    (princ (strcat "\nError: " s))
  )
 (ripVar)
 (princ)
)

(defun salVar ()
 (setq orto (getvar "orthomode"))
 (setq snapp (getvar "osmode"))
 (setq snm (getvar "snapmode"))
 (setq piano (getvar "clayer"))  
)

(defun ripVar ()
 (command "_redraw")
 (setvar "cmdecho" 1)
 (setvar "osmode" snapp)
 (setvar "snapmode" snm)
 (setvar "orthomode" orto)
 (setvar "clayer" piano)
 (setvar "cecolor" "BYLAYER")
 (setq *error* olderr)
 (princ)
)

(defun CooXYZ (/ k hTesto pQ
                 pQT p1 p2 p3 p4 p5 p6
                 spazio distXY
                 nCooX nCooY nCooZ
                 cCooX cCooY cCooZ strX strY
 )
 (setq hTesto (getreal "\n Dimensione testo: "))
 (command "osnap" "_non")
 (setq k 1)
 (while k
  (command "osnap" "_int")
  (setq pQ (getpoint "\n Seleziona il punto da quotare : "))
  (if (= pQ nil)
   (setq k nil)
   (progn
    (command "osnap" "_non")
    (setq nCooX (car pQ))
    (setq nCooY (cadr pQ))
    (setq nCooZ (caddr pQ))
    (initget 1)
    (setq pQT (getpoint "\n Punto di inserimento coordinate: "))
    (if (/= nCooZ 0)
     (progn
      ;;                                       
      ;;  p5---p6
      ;;    | øx = numero       (ø p3)
      ;;    |
      ;;    | *y = numero       (* p2)
      ;;    |  
      ;;    | #z = numero       (# p1)
      ;;  p4---pQT
      ;;
      (setq spazio (/ hTesto 2))
      (setq distXY (+ hTesto (/ hTesto 2)))
      (setq p1 (list (car pQT)(+ (cadr pQT) spazio)))
      (setq p2 (list (car pQT)(+ (cadr p1) distXY)))
      (setq p3 (list (car pQT)(+ (cadr p2) distXY)))
      (setq p4 (list (- (car p2) spazio)(cadr pQT)))
      (setq p5 (list (car p4) (+ (cadr p3) spazio spazio)))
      (setq p6 (list (car pQT)(cadr p5)))
      ; disegna una parentesi quadra aperta
      (command "_pline" pQT "_w" 0.0 0.0 p4 p5 p6 "")
      ; trasforma le coordinate x,y,z in stringhe
      (setq cCooX (rtos nCooX 2 2))
      (setq cCooY (rtos nCooY 2 2))
      (setq cCooZ (rtos nCooZ 2 2))
      (setq strX (strcat "x = " cCooX))
      (setq strY (strcat "y = " cCooY))
      (setq strZ (strcat "z = " cCooZ))
      (command "_text" p3 hTesto 0.0 strX)
      (command "_text" p2 hTesto 0.0 strY)
      (command "_text" p1 hTesto 0.0 strZ)
     )
     (progn
      ;;
      ;;  p4---p5
      ;;    | øx = numero       (ø p2)
      ;;    |
      ;;    | *y = numero       (* p1)
      ;;    |  
      ;;  p3---pQT
      ;;
      (setq spazio (/ hTesto 2))
      (setq distXY (+ hTesto (/ hTesto 2)))
      (setq p1 (list (car pQT) (+ (cadr pQT) spazio)))
      (setq p2 (list (car pQT) (+ (cadr p1) distXY)))
      (setq p3 (list (- (car p2) spazio) (cadr pQT)))
      (setq p4 (list (car p3) (+ (cadr p2) spazio spazio)))
      (setq p5 (list (+ (car p4) spazio) (cadr p4)))
      ; disegna una parentesi quadra aperta
      (command "_pline" pQT "_w" 0.0 0.0 p3 p4 p5 "")
      ; trasforma le coordinate x,y in stringhe
      (setq cCooX (rtos nCooX 2 2))
      (setq cCooY (rtos nCooY 2 2))
      (setq strX (strcat "x = " cCooX))
      (setq strY (strcat "y = " cCooY))
      (command "_text" p2 hTesto 0.0 strX)
      (command "_text" p1 hTesto 0.0 strY)
     )
    ) 
   )
  )
 )
)

(defun C:CXYZ (/ olderr snapp snm orto piano)
 (setq olderr *error* *error* myerror)
 (setvar "cmdecho" 0)
 (salVar)
 (CooXYZ)
 (ripVar)
)
;;;eof

Lisp »Tips 'n Tricks

Ultimo Aggiornamento_Last Update: 24 Marzo 2005