Jump to content

Lisp Routine to Bring in Z Value (Lee Mac Lisps)


Recommended Posts

Hi Everyone,

We have browsed the forum looking for a Lisp Routine for creating Z values from point clouds. Lee Mac has came up with something which works well (great work Lee).


Though we are looking to modify this to suit our workflow:


  • Basically we want to pick a point and bring through the z value as text. (which the lisp below works fine) though not having the option to choose between x,y,z and only picking the z value every time would be beneficial.
  • Having a fixed offset and text size too rather than having the option to choose
  • Next we need the lisp to bring in some text for the selected level i.e creating text with the remark DL. Once we have one code for this lisp we can then alter this to bring in other remarks such as CL WHL CHL USB etc etc. Then we can customise each lisp with a button in CAD.
  • One Last thing is the lisp below creates a Cross from two drawn lines. Does anyone know how to make this a separate entity like a Symbol/Block and change it so its square to the model space unlike the current cross


If anyone can help with this it would be fantastic and heavily aid our workflow.

The code below is as Lee Mac has posted


(defun c:ptlab (/ Text _PromptWithDefault _Cross Pt pos)
 ;; Lee Mac  ~  30.03.10

 (defun Text (pt hgt str)
   (entmakex (list (cons 0 "TEXT") (cons 10  pt)
                   (cons 40 hgt)   (cons 7 (getvar 'TEXTSTYLE))
                   (cons 1  str))))

 (defun _PromptWithDefault (f arg d)
   (cond ((apply f arg)) (d)))

 (defun _Cross (p h / l)
   (setq l (sqrt (* 0.5 h h)))
       (lambda (p1 p2)
         (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2)))))

     (list (polar p (/      pi  4.) l)
           (polar p (/ (* 3 pi) 4.) l))

     (list (polar p (/ (* 5 pi) 4.) l)
           (polar p (/ (* 7 pi) 4.) l))))
 (setq *Coord* (cond (*Coord*) ("Y"))
       *tHgt*  (cond (*tHgt* ) ((getvar 'TEXTSIZE)))
       *thOff* (cond (*thOff*) (0.15))
       *tvOff* (cond (*tvOff*) (0.15))
       *cSze*  (cond (*cSze* ) ((getvar 'TEXTSIZE))))

 (setq pos '(("X" . 0) ("Y" . 0) ("Z" . 2)))

 (initget "X Y Z")
 (mapcar (function set) '(*Coord* *tHgt* *thOff* *tvOff* *cSze*)
         (mapcar (function _PromptWithDefault) '(getkword getdist getdist getdist getdist )
                 (list (list (strcat "\nSpecify Coord to Label [X/Y/Z] <" *Coord* "> : "))
                       (list (strcat "\nSpecify Text Height <" (rtos *tHgt*) "> : "))
                       (list (strcat "\nSpecify Horizontal Text Offset <" (rtos *thOff*) "> : "))
                       (list (strcat "\nSpecify Vertical Text Offset <" (rtos *tvOff*) "> : "))
                       (list (strcat "\nSpecify Cross Height <" (rtos *cSze*) "> : ")))
                 (list *Coord* *tHgt* *thOff* *tvOff* *cSze*)))

 (while (setq pt (getpoint "\nPick Point to Label <Exit> : "))
   (_Cross (setq pt (trans pt 1 0)) *cSze*)

   (Text (polar  (polar pt 0. *thOff*) (/ pi 2.) *tvOff*) *tHgt*
         (rtos (nth (cdr (assoc *Coord* pos)) pt))))



Thanks in Advance



Link to comment
Share on other sites

The code by Lee has all the answers, plus you could reduce the code regarding the text placement by presetting the questions, the square rather than 2 lines could be a block.


A couple of rules does square block in current dwg exist, else need a few more lines of code to make it, does the text style to be used exist also, else needs to be added does it have a preset height ?


Here is a start it needs question above answered and extra code can be added.

(while (setq pt (getpoint "\nPick Point to Label <Exit> : "))
(setq pt (trans pt 1 0)) ; real world
(setq x (rtos (car pt) 2 3)) ; for example only as z is all required
(setq y (rtos (cadr pt) 2 3))
(setq z (rtos (caddr pt) 2 3))
(command "text" pt "2.5" 0.0 (strcat "Z=" z) "") ; note text style has height as zero
(command "insert" "sqbox" pt 1 1 0)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...