Jump to content

LISP to change the colour of points depending on height


Adam R

Recommended Posts

Hi,

 

I'm trying to write a LISP that will automatically take a level survey, ask the user for a height and a tolerance and then highlight points that fall outside this tolerance. It would be even better if I could differentiate between points that are too high and points that are too low. 

 

For context, I want to use this for surveys of concrete slabs that are supposed to be at a given level. I understand qselect does most of what I'm saying but would like to be able to do the whole process as one command. If it could also change the text that accompanies these points, that would be EVEN better!!

 

Thanks in advance!

Link to comment
Share on other sites

;;;
;;;
;;;
(defun c:ztol (/ z f ss i en ed p e c)

  (initget 1)
  (setq z (getdist "\nElevation:   "))

  (initget 7)
  (setq f (getdist "\nTolerence:   "))

  (and (princ "\nSelect Points...")
       (setq ss (ssget '((0 . "POINT"))))
       (setq i 0)
       (while (setq en (ssname ss i))
              (setq ed (entget en))
              (setq p (cdr (assoc 10 ed)))
              (setq e (caddr p))
              (cond ((equal e z f) (setq c 2))
                    ((< e (- z f)) (setq c 1))
                    ((> e (+ z f)) (setq c 3)))
              (entmod (append ed (list (cons 62 c))))
              (setq i (1+ i))))

  (command "_.REGENALL")

  (princ"\nRed Below : Green Above : Yellow Within Tolerance")
  (prin1))

The routine could look like this

 

Dealing with the text could be a whole different ball game.

 

-David

 

  • Like 1
Link to comment
Share on other sites

Hi David, 

Thanks for your reply! I've tried to run this code but changed a couple value names. When I try to run it, it fails on the selecting points part. 

 

Select Points : ; error: bad SSGET list

 

Here is my version. Hopefully I haven't changed something vital! Only just started learning LISP today so I don't fully understand its workings

       
 

(defun c:levelsurvey (/ height tolerance ss i en ed p e c)
;******************************************************* Start

(initget 1)
(setq height (getdist "\nSlab Height : ")) 

(initget 7)
(setq tolerance (getdist "\nTolerance : ")) 

(and (princ "\nSelect Points : ")
    (setq ss (ssget '((0. "POINT"))))
    (set i 0)
    (while (setq en (ssname ss i))
    (setq ed (entget en))
    (setq p (cdr (assoc 10 ed)))
    (setq e (caddr p))
    (cond ((equal e height tolerance) (setq c 2))
        ((< e (- height tolerance)) (setq c 1))
        ((> e (+ height tolerance)) (setq c 3)))
    (entmod (append ed (list (cons 62 c))))
    (setq i (1 + i))))

(command "_.REGENALL")

(princ"\nRed Below : Green Above : Yellow Within Tolerance")
(prin1))
       
;******************************************************* End

(princ)
)
(princ)

 

P.S. I have no idea how to format my posts so the code is in the pretty blue box.

Link to comment
Share on other sites

Thank you!

 

Ended up just copying the code again and editing to prevent typos (as there were quite a few!) and that part works now.  Rookie error on my behalf!

 

Now all I need is the text half of the code which after some research, seems to be even trickier.

 

Any thoughts on how to do this?

 

Thanks for all the help I've received so far, I really appreciate it.

Link to comment
Share on other sites

34 minutes ago, Adam R said:

Thank you!

 

Ended up just copying the code again and editing to prevent typos (as there were quite a few!) and that part works now.  Rookie error on my behalf!

 

Now all I need is the text half of the code which after some research, seems to be even trickier.

 

Any thoughts on how to do this?

 

Thanks for all the help I've received so far, I really appreciate it.

Would the level text be on a specific layer to differentiate it from other text?

Link to comment
Share on other sites

Just realised that the text object for each point is created at the same z value as the point so using TEXT in place of POINT will carry out the same operation and change the colours of the height labels. Not sure how to do both in the same chunk of code though?

 

Link to comment
Share on other sites

2 minutes ago, Adam R said:

Just realised that the text object for each point is created at the same z value as the point so using TEXT in place of POINT will carry out the same operation and change the colours of the height labels. Not sure how to do both in the same chunk of code though?

 

 

Starter for 10

 

(setq ss (ssget '((0. "POINT,TEXT"))))

 

  • Like 1
Link to comment
Share on other sites

I was hoping it would be something that simple but didn't know how to do it 😅

 

Thank you all for all the help! Should save me hours of sifting through data!

 

Here's the finished code for anyone who looks for it in the future. I'm using it for a .dxf export from a Leica CS20

 

(defun c:levelsurvey (/ height tolerance ss i en ed p e c)
        
;******************************************************* Hide Unused Layers

(command "_.layer" "_off" "Coordinates,Point_ID" "_thaw" "Callout,Text" "_on" "Callout,Text" "" "_regen")

;******************************************************* User Inputs

(initget 1)
(setq height (getdist "\nSlab Height : ")) 

(initget 7)
(setq tolerance (getdist "\nTolerance : ")) 

;****************************************************** Point Edit

(and (princ "\nSelect Points : ")
     (setq ss (ssget '((0 . "POINT,TEXT"))))
       (setq i 0)
       (while (setq en (ssname ss i))
              (setq ed (entget en))
              (setq p (cdr (assoc 10 ed)))
              (setq e (caddr p))
              (cond ((equal e height tolerance) (setq c 2))
                    ((< e (- height tolerance)) (setq c 1))
                    ((> e (+ height tolerance)) (setq c 3)))
              (entmod (append ed (list (cons 62 c))))
              (setq i (1+ i))))

  (command "_.REGENALL")

  (princ"\nRed Below : Green Above : Yellow Within Tolerance")
  (prin1)

 

;******************************************************* End

(princ)
)
(princ)

Edited by Adam R
remove unnecessary line
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.

Guest
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...