Please help me with lisp routine to select polylines with elevation divisible by 5 and move to a specific layer

Please help me with lisp routine to select polylines with elevation divisible by 5 and move to a specific layer

jakepV2M3V
Observer Observer
491 Views
4 Replies
Message 1 of 5

Please help me with lisp routine to select polylines with elevation divisible by 5 and move to a specific layer

jakepV2M3V
Observer
Observer

I have imported state lidar contours as polylines with elevations and I need a lisp that can help me move "major" elevation contours (polylines with elevations divisible by 5) to my "C-X-Major Topo" layer.  

I have attached a lisp I think should work, but it doesn't and I am NOT capable of trouble shooting it.

 

thanks for any and all help!

0 Likes
Accepted solutions (1)
492 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

Good, two minor errors. setq vs set and func name is 1-, not 1 -

 

(defun c:MAJOR ()
  
  (setq ss (ssget '((0 . "LWPOLYLINE")))) ; Select LWPOLYLINE entities
  (setq conint (getdist "Enter Major Contour Interval:"))
  (setq major "C-X-Topo-Major")
  (setq minor "C-X-Topo-Minor")
  (command "._pedit" "_M" ss "" "_L" "ON" "")
  (command "._chprop" ss "" "_layer" minor "")
  
  (if ss ; Check if entities are selected
    (progn
      (repeat (setq i (sslength ss))
	(setq e (ssname ss (setq i (1- i))))
	(setq el (abs (cdr (assoc 38 (entget e)))))
	
	(if (equal (rem el conint) 0.0 1e-6)
	  (command "_.chprop" e "" "_layer" major "")
	  )
	)
      )
    (princ "No LWPOLYLINE entities selected.")
    )
  )

 

Message 3 of 5

jakepV2M3V
Observer
Observer

This worked perfectly!  Thank you for your help.

0 Likes
Message 4 of 5

ronjonp
Advisor
Advisor

@jakepV2M3V Also remember to localize your variables, (defun c:MAJOR ( / CONINT E EL I MAJOR MINOR SS)

0 Likes
Message 5 of 5

hak_vz
Advisor
Advisor

@jakepV2M3V 

Here you have another lisp that you can use when your terrain isohypses are all placed in drawing with

elevations set to 0. This is a problem that I encounter way too often in my daily practice.

 

(defun c:repelev ( / *error* base step eo ss i) 
	(defun *error* ()
		(princ)
	)	

	(setq base (getreal"\n New starting elevation: >")
		  step (getreal "\n Isohypse step (+ or - value) >:")
	)
	(entmakex 
			(list (cons 0 "LAYER")
			   (cons 100 "AcDbSymbolTableRecord")
			   (cons 100 "AcDbLayerTableRecord")
			   (cons 2 "C-X-Topo-Major")
			   (cons 62 1)
			   (cons 70 0)
			   (cons 370 30)
			)
		)
	(entmakex 
			(list (cons 0 "LAYER")
			   (cons 100 "AcDbSymbolTableRecord")
			   (cons 100 "AcDbLayerTableRecord")
			   (cons 2 "C-X-Topo-Minor")
			   (cons 62 5)
			   (cons 70 0)
			   (cons 370 18)
			)
		)
	(princ (strcat "\nSelect isohypse(s) at " (rtos base 2 1) " Press 'Enter' when done): >"))
	(while (and (setq ss (ssget '((0 . "*POLYLINE")))) (> (sslength ss) 0))

				(setq i -1)
				(while (< (setq i (1+ i)) (sslength ss))
					(setq eo (vlax-ename->vla-object (ssname ss i)))
					(vlax-put eo 'Elevation base)
					(if (= (rem base 5) 0.0)
						(vlax-put eo 'Layer  "C-X-Topo-Major")
						(vlax-put eo 'Layer  "C-X-Topo-Minor")
					)
				)
				(setq base (+ base step))
				(princ (strcat "\nSelect isohypse(s) at " (rtos base 2 1) " Press 'Enter' when done): >"))
	)
	(princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes