Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

filter polyline with elevation of 0.5M

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
marlance
4385 Views, 12 Replies

filter polyline with elevation of 0.5M

Is there any away to filter all polylines with an elevation of 1.5, 2.5, 3.5, etc.

I want to delete them but I want to retain those who have an elevation of 1.0 , 2.0, 3.0 etc

 

12 REPLIES 12
Message 2 of 13
Ajilal.Vijayan
in reply to: marlance

Try with this

This code should change the unwanted lines color to 11.

(defun c:filterpoly ()
(setq a (ssget "_X" '((0 . "LWPOLYLINE"))))
 (setq n (sslength a))
 (setq index 0)
  (repeat n
   (setq b1 (vlax-ename->vla-object(ssname a index)))
   (setq index (1+ index))
   (if (wcmatch (rtos(vla-get-elevation b1)) "*.5")
   (vlax-put-property b1 'Color 11);change the color to 11
   );if
   );repeat
   );defun

 

Message 3 of 13
pbejse
in reply to: marlance


@rulep21 wrote:

Is there any away to filter all polylines with an elevation of 1.5, 2.5, 3.5, etc.

I want to delete them but I want to retain those who have an elevation of 1.0 , 2.0, 3.0 etc

 


Demo to delete:

 

(defun c:DemoD (/ ss el)
  (if (setq ss	(ssget "_X" '((0 . "LWPOLYLINE")))
      )
    (repeat (setq i (sslength ss))
      (setq el
	     (abs
	       (cdr
		 (assoc 38 (entget (setq e (ssname ss (setq i (1- i))))))
	       )
	     )
      )
      (if (not (zerop (- el (fix el))))
	(entdel e)
      )
    )
  )
  (princ)
)

    	

 

Demo to select non conforming elevation value

 

(defun c:DemoS (/ ssd ss el)
  (if (setq ssd	(ssadd)
	    ss	(ssget "_X" '((0 . "LWPOLYLINE")))
      )
    (repeat (setq i (sslength ss))
      (setq el
	     (abs
	       (cdr
		 (assoc 38 (entget (setq e (ssname ss (setq i (1- i))))))
	       )
	     )
      )
      (if (not (zerop (- el (fix el))))
	(ssadd e ssd)
      )
    )
  )
  (sssetfirst nil ssd)
)
    	

 

HTH

 

 

Message 4 of 13
Kent1Cooper
in reply to: pbejse


@pbejse wrote:
....
,,,,
(if (not (zerop (- el (fix el)))) ....

....


Depending on how their elevations were determined, you might have some that are close enough for something like the Properties box to display as being at a whole-number elevation value, but that are not precisely there, e.g. at 1.99999999999943 or 4.00000000000061.  The above would find those to be "wrong" and therefore flag or delete them.  If that's a possibility, but you want to keep such Polylines, a test like this:

 

  (if (not (equal (rem el 1) 0 1e-6))

 

would let them stay.  Change the 6 to some precision/fuzz-factor that works for you.

Kent Cooper, AIA
Message 5 of 13
pbejse
in reply to: Kent1Cooper


@Kent1Cooper wrote:

Depending on how their elevations were determined,....

..... whole-number elevation value, but that are notprecisely there...

  (if (not (equal (rem el 1) 0 1e-6)) 

 


Good point Kent. Thank you for the info kind sir. Smiley Happy

 

Message 6 of 13
marlance
in reply to: marlance

how if i want to change the layers of all polylines with an elevation of 5,10,15 and so on to a certain layer (major contour) and the rest to (minor contour)?
Message 7 of 13
Kent1Cooper
in reply to: marlance


@rulep21 wrote:
how if i want to change the layers of all polylines with an elevation of 5,10,15 and so on to a certain layer (major contour) and the rest to (minor contour)?

Borrowing some elements from pbejse's suggestions, and adding Layer filtering to the selection in case you might have Polylines at such elevations representing some kind of surface features that you don't want moved to the major contours Layer:

 

(vl-load-com)

(defun c:Major5 (/ ss el)
  (if (setq ss (ssget "_X" '((0 . "LWPOLYLINE") (8 . "YourContourLayerName")))
    (repeat (setq i (sslength ss))
      (setq el (cdr (assoc 38 (entget (setq e (ssname ss (setq i (1- i)))))))); elevation
      (if (equal (rem el 5.0) 0.0 1e-6); at elevation that is a multiple of 5?

        (vla-put-Layer (vlax-ename->vla-object e) "YourMajorContourLayerName")
      ); if

    ); repeat

  ); if
  (princ)
😞 defun

You could also do it using

        (command "_.chprop" e "" "_layer" "YourMajorContourLayerName" "")

in place of the (vla-put...) function, which would eliminate the need for the (vl-load-com) at the top, but would also affect only those contours in the current space [which may be all you need].  The (vla-put...) approach will change the Layer of qualifying LWPolylines in Model space and any Paper space layout(s).

 

Consider also whether you need to account for the possibility of a locked Layer, which can be done easily enough if needed.  And if you might have any Polylines drawn in other than the World Coordinate System, but assuming your contours are in the WCS, you can get it to ignore those in other UCS's if you want.

Kent Cooper, AIA
Message 8 of 13
marlance
in reply to: Kent1Cooper

You could also do it using

        (command "_.chprop" e "" "_layer" "YourMajorContourLayerName" "")

 

Hi kent

I modified the code and here's what I've got

(defun c:p5 ()
(setq eval (getdist "Enter Contour Interval:"))
(setq layer (strcat "Contour_" (rtos eval 2 2)))

(if (setq ss	(ssget "_X" '((0 . "LWPOLYLINE")))
      )
    (repeat (setq i (sslength ss))
      (setq el
	     (abs
	       (cdr
		 (assoc 38 (entget (setq e (ssname ss (setq i (1- i))))))
	       )
	     )
      )

(command "-layer" "m" layer "")

(if (equal (rem el eval) 0.0 1e-6);


(command "_.chprop" e "" "_layer" layer "")
      )
    )
  )
  (princ)
)

   

It works well now with me.

But I have one request again.

How can I filter all text in the drawing that is divisible by 5?

 

Thanks in advance

Message 9 of 13
marlance
in reply to: marlance

(defun c:div ()
(setq divi (getdist "Enter divisibility:"))
(setq layer (strcat "div_"(rtos divi 2 2)))
(if (setq ss (ssget "_X" '((0 . "TEXT"))))
(repeat (setq i (sslength ss))
(setq num (getreal (assoc 1 (entget (setq e (ssname ss (setq i (1- i))))))))
)
)
(command "-layer" "m" layer "")
(if
(= (rem num divi ) 0)
(command "_.chprop" e "" "_layer" layer "")
)
(princ)
)

 i've written this code based on filtering polyline elevation but it's not working

I hope someone could help me again for this one

 

 

Message 10 of 13
Kent1Cooper
in reply to: marlance


@rulep21 wrote:
(defun c:div ()
(setq divi (getdist "Enter divisibility:"))
(setq layer (strcat "div_"(rtos divi 2 2)))
(if (setq ss (ssget "_X" '((0 . "TEXT"))))
(repeat (setq i (sslength ss))
(setq num (getreal (assoc 1 (entget (setq e (ssname ss (setq i (1- i))))))))
)
)
(command "-layer" "m" layer "")
(if
(= (rem num divi ) 0)
(command "_.chprop" e "" "_layer" layer "")
)
(princ)
)

 i've written this code based on filtering polyline elevation but it's not working

I hope someone could help me again for this one

 

 


The (get...) functions ask the User for input.  And (assoc) will return a dotted pair with the 1 and the content, so you need to separate the content.  Try:

....

(setq num (cdr (assoc 1 (entget (setq e (ssname ss (setq i (1- i))))))))

....

Kent Cooper, AIA
Message 11 of 13
Kent1Cooper
in reply to: marlance


@rulep21 wrote:

...

(defun c:p5 ()
(setq eval (getdist "Enter Contour Interval:")
...

...


I would recommend using a different variable name.  There is a Lisp function called (eval), and using that as a variable name, if you don't localize the variable, could make any routines that use (eval) not work correctly.

Kent Cooper, AIA
Message 12 of 13
bretttwarwick
in reply to: marlance

Marlance, I like your code but it changes all polylines at the interval elevations instead of the selection set polylines only.  How do I modify it to only change the layer of the selection set polylines?

 

 


@marlance wrote:

You could also do it using

        (command "_.chprop" e "" "_layer" "YourMajorContourLayerName" "")

 

Hi kent

I modified the code and here's what I've got

(defun c:p5 ()
(setq eval (getdist "Enter Contour Interval:"))
(setq layer (strcat "Contour_" (rtos eval 2 2)))

(if (setq ss	(ssget "_X" '((0 . "LWPOLYLINE")))
      )
    (repeat (setq i (sslength ss))
      (setq el
	     (abs
	       (cdr
		 (assoc 38 (entget (setq e (ssname ss (setq i (1- i))))))
	       )
	     )
      )

(command "-layer" "m" layer "")

(if (equal (rem el eval) 0.0 1e-6);


(command "_.chprop" e "" "_layer" layer "")
      )
    )
  )
  (princ)
)

   

It works well now with me.

But I have one request again.

How can I filter all text in the drawing that is divisible by 5?

 

Thanks in advance


 

Message 13 of 13
Kent1Cooper
in reply to: bretttwarwick


@bretttwarwick wrote:

....it changes all polylines at the interval elevations instead of the selection set polylines only.  How do I modify it to only change the layer of the selection set polylines?

 


@marlance wrote:

....

....
(if (setq ss (ssget "_X" '((0 . "LWPOLYLINE"))) ....


Remove the "_X" from that line.  It is telling the routine to find all  LWPolylines in the drawing.  Without that, it will ask the User to select.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost