Lisproutine for spot levels

Lisproutine for spot levels

Anonymous
Not applicable
1,539 Views
3 Replies
Message 1 of 4

Lisproutine for spot levels

Anonymous
Not applicable

Hello, 

 

Could someone help me with the following Lisp routine please?

I use it to extract levels from point clouds in AutoCAD.

I was wondering if there is a way for the text to have the correct z value (client's requirement) 

 

At the moment, the cross has the correct z value but the text has a z value of 0. 

 

;------------------------------------------------------------------
; PICKLEV.lsp
;
; Desc:
; Macro to insert an cross & level and automatically add level value,
; from z value of 3d entity selected.
;
; by B.Frost 07/11/02 ver1.0
;------------------------------------------------------------------
; NOTE:
;
;------------------------------------------------------------------
(prompt "\nLoading PICKLEV Please wait...")

(defun MODES (a)
(setq MLST '())
(repeat (length a)
(setq MLST (append MLST (list (list (car a) (getvar (car a))))))
(setq a (cdr a)))
)

(defun MODER ()
(repeat (length MLST)
(setvar (caar MLST) (cadar MLST))
(setq MLST (cdr MLST))
)
)

(defun err (msg)
(moder) ; restore system varaibles.

(if (/= msg "Function cancelled")
(alert (strcat "\nError: " msg))
)
(setq *error* olderr) ;Restore old *error* handler
(princ)
)

;************************************************************************
; main program
;-------------
(defun C:bfAutoSP ()

(setq olderr *error*
*error* err)

(modes '("cmdecho" "Highlight" "Dimzin" "Osmode"))
(setvar "CMDECHO" 0)

(setvar "HIGHLIGHT" 0)
(setvar "DIMZIN" 1)

; Print copyright notice to screen
(princ "PickLev v1.0 ©2002 B.Frost")

(while T
; Start undo group
(command "UNDO" "G")

(setq lpos (getpoint "\nPick Level position: "))
(if (= nil lpos) (exit))

; Test if valid Level value picked, i.e. > 0.000
; **** COULD have option to prompt for text *****
;(print (caddr lpos))
(if (> (caddr lpos) 0.0)
(progn

(setq oldsnap (getvar "OSMODE")) ; save old snap mode
(setvar "OSMODE" 0)

(if (= nil lori)
(setq defori 0.0)
(setq defori lori)
)
(setq lori (getangle lpos (strcat "\nPick orientation <" (rtos (* defori (/ 180 pi)) 2 2) ">: ")))
(if (= nil lori) (setq lori defori) )

; is current text style variable height?
(setq sty (tblsearch "STYLE" (getvar "TEXTSTYLE")))
(setq txtht (cdr (assoc 40 sty)))
(setq vartxt (= (rtos txtht) (rtos 0))) ; is current text height zero
(if vartxt
(setq txtht (* 0.0015 (* 50 (getvar "LTSCALE")))) ; if so set a sensible text height
)

; Compute text position
(setq txtpos (Polar lpos lori (/ txtht 2)))

(setq txtori (* lori (/ 180 Pi) )) ; convert orientation from rads to degs
; get level value i.e. Z coord of selected point
(setq levtxt (rtos (caddr lpos) 2 2) )
;(print levtxt)
;(setq lpos (list (car lpos) (cadr lpos) 0)) ; take out z value from lpos

; Add Level Symbol
(command "_INSERT" "Cross" lpos txtht "" txtori)

; Add level text.
(command "_TEXT" "ML" txtpos)
(if vartxt (command txtht))
(command txtori levtxt)

(princ "\nMove text (ESC to keep position)")
(command "_Move" "L" "" txtpos pause)
;; (setq mvpt (getpoint "\nMove text:"))
;; (if (= nil mvpt) (setq mvpt txtpos))
;; (command mvpt)

(setq d1 (distance txtpos (cdr (assoc 10 (entget (entlast))))))
(setq d2 (distance '(0 0 0) txtpos))
(print d1)
(print d2)
(if (eq d1 d2)
(print"OOPS!")(print "OK")
)

(setvar "OSMODE" oldsnap)

) ; end progn
(print "Invalid point selection!")
) ; end if

; End undo group
(command "UNDO" "E")

) ; end while


(moder)

(setq *error* olderr)
(princ)

) ; end defun

 

 

0 Likes
Accepted solutions (1)
1,540 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this

 

;------------------------------------------------------------------
; PICKLEV.lsp
;
; Desc:
; Macro to insert an cross & level and automatically add level value,
; from z value of 3d entity selected.
;
; by B.Frost 07/11/02 ver1.0
;------------------------------------------------------------------
; NOTE:
;
;------------------------------------------------------------------
(prompt "\nLoading PICKLEV Please wait...")

(defun MODES (a)
  (setq MLST '())
  (repeat (length a)
    (setq MLST (append MLST (list (list (car a) (getvar (car a))))))
    (setq a (cdr a)))
  )

(defun MODER ()
  (repeat (length MLST)
    (setvar (caar MLST) (cadar MLST))
    (setq MLST (cdr MLST))
    )
  )

(defun err (msg)
  (moder) ; restore system varaibles.
  
  (if (/= msg "Function cancelled")
    (alert (strcat "\nError: " msg))
    )
  (setq *error* olderr) ;Restore old *error* handler
  (princ)
  )

;************************************************************************
; main program
;-------------
(defun C:bfAutoSP ()
  
  (setq olderr *error*
	*error* err)
  
  (modes '("cmdecho" "Highlight" "Dimzin" "Osmode" "OSNAPZ"))
  (setvar "CMDECHO" 0)
  
  (setvar "HIGHLIGHT" 0)
  (setvar "DIMZIN" 1)
  
  ; Print copyright notice to screen
  (princ "PickLev v1.0 ©2002 B.Frost")
  
  (while T
    ; Start undo group
    (command "UNDO" "G")
    
    (setq lpos (getpoint "\nPick Level position: "))
    (if (= nil lpos) (exit))
    
    ; Test if valid Level value picked, i.e. > 0.000
    ; **** COULD have option to prompt for text *****
    ;(print (caddr lpos))
    (if (> (caddr lpos) 0.0)
      (progn
	
	(setq oldsnap (getvar "OSMODE")) ; save old snap mode
	(setq oldosnapz (getvar 'osnapz))
	
	(setvar "OSMODE" 0)
	
	(if (= nil lori)
	  (setq defori 0.0)
	  (setq defori lori)
	  )
	(setq lori (getangle lpos (strcat "\nPick orientation <" (rtos (* defori (/ 180 pi)) 2 2) ">: ")))
	(if (= nil lori) (setq lori defori) )
	
	; is current text style variable height?
	(setq sty (tblsearch "STYLE" (getvar "TEXTSTYLE")))
	(setq txtht (cdr (assoc 40 sty)))
	(setq vartxt (= (rtos txtht) (rtos 0))) ; is current text height zero
	(if vartxt
	  (setq txtht (* 0.0015 (* 50 (getvar "LTSCALE")))) ; if so set a sensible text height
	  )
	
	; Compute text position
	(setq txtpos (Polar lpos lori (/ txtht 2)))
	
	(setq txtori (* lori (/ 180 Pi) )) ; convert orientation from rads to degs
	; get level value i.e. Z coord of selected point
	(setq levtxt (rtos (caddr lpos) 2 2) )
	;(print levtxt)
	;(setq lpos (list (car lpos) (cadr lpos) 0)) ; take out z value from lpos
	
	; Add Level Symbol
	(command "_INSERT" "Cross" lpos txtht "" txtori)
	
	; Add level text.
	(command "_TEXT" "ML" txtpos)
	(if vartxt (command txtht))
	(command txtori levtxt)
	
	(princ "\nMove text (ESC to keep position)")
	(setvar 'osnapz 0)
	(command "_Move" "L" "" (reverse (cdr (reverse txtpos))) pause)
	(setvar 'osnapz oldosnapz)
	
	;; (setq mvpt (getpoint "\nMove text:"))
	;; (if (= nil mvpt) (setq mvpt txtpos))
	;; (command mvpt)
	
	(setq d1 (distance txtpos (cdr (assoc 10 (entget (entlast))))))
	(setq d2 (distance '(0 0 0) txtpos))
	(print d1)
	(print d2)
	(if (eq d1 d2)
	  (print"OOPS!")(print "OK")
	  )
	
	(setvar "OSMODE" oldsnap)
	
	) ; end progn
      (print "Invalid point selection!")
      ) ; end if
    
    ; End undo group
    (command "UNDO" "E")
    
    ) ; end while
  
  
  (moder)
  
  (setq *error* olderr)
  (princ)
  
  ) ; end defun
0 Likes
Message 3 of 4

Anonymous
Not applicable

Thank you!

 

That works exactly how I want it. 

0 Likes
Message 4 of 4

msutorWRTDE
Observer
Observer

Hi guys,

thank you for sharing, it works great!!!

Can you tell me how can I edit it so it scales the text and the Cross to the correct size? Right now my cross is 1x1 size and when it brings it in, it is scaled to 0.25. Also it changes the text size to 0.25. It would be great if it was getting both from TEXTSIZE. I'd need it because I work with different scales all the time.

Also would it be possible to get rid of the orientation option? It would be a little faster if it was set to 0.

Kind regards

Mateusz Sutor

0 Likes