Select All Triangles using LSP

Select All Triangles using LSP

Anonymous
Not applicable
1,209 Views
4 Replies
Message 1 of 5

Select All Triangles using LSP

Anonymous
Not applicable

Hello All, 

 

I am looking for a LSP file that will help me in selecting only Triangles of a particular Area in a drawing file. 

 

Using QSelect I can select entities with particular areas but that selects other polylines as well which are not required. 

 

Method 2 is uising Qselect again, I can filter out closed entities and then select the triangles by using the same command again. However I am looking for one single command that could help me selecting triangles with a particular area. 


This can then be extended to, selecting polygons (side input to be obtained from the user) and then selecting by an property (area, perimeter etc .)

 

Any help is appreciated. Thank you.

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

ВeekeeCZ
Consultant
Consultant
Accepted solution
(vl-load-com)

(defun c:SelTriArea ( / fuzz ss ar i en f)

  (setq fuzz 0.01)

  (setq f (ssget "I"))
  (if (and (setq ss (ssget '((0 . "LWPOLYLINE") (90 . 3) (-4 . "&=") (70 . 1))))
	   (setq ar (getreal "\nArea: "))
	   )
    (repeat (setq i (sslength ss))
      (setq en (ssname ss (setq i (1- i))))
      (if (not (equal ar (vlax-curve-getarea en) fuzz))
	(ssdel en ss))))
  
  (if f (command "_.regen"))
  (sssetfirst nil ss)
  (princ)
  )
 
Message 3 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....

I am looking for a LSP file that will help me in selecting only Triangles of a particular Area in a drawing file. 

Using QSelect I can ....


Given the QSELECT approach, may I assume you want it to find all  of them in the drawing [or in the current space, at least], without User-selection involvement, but only the specifying of the area?  If so, try this modification of @ВeekeeCZ 's suggestion:

(defun C:SelTriArea (/ ss ar i en)
  (if
    (and
      (setq ss (ssget "_X" (list '(0 . "LWPOLYLINE") '(90 . 3) (cons 410 (getvar 'ctab)) '(-4 . "&") '(70 . 1))))
      (setq ar (getreal "\nArea: "))
    ); and
    (repeat (setq i (sslength ss))
      (setq en (ssname ss (setq i (1- i))))
      (if (not (equal ar (vlax-curve-getarea en) 0.01)); <-- EDIT fuzz factor as desired
        (ssdel en ss); then
      ); if
    ); repeat
  ); if
  (sssetfirst nil ss)
  (princ)
); defun
(vl-load-com)

I added the  "_X"  to find all without User selection, accordingly also eliminating the  "I" pre-selection aspect, and added the  (cons 410 (getvar 'ctab))  to look in only the current space.  I also incorporated the fuzz factor directly, without the use of a variable if it's always going to be the same value, but that could be done with a variable if you want to ask the User how close the area needs to be to what they ask for.

 

A small other thing:  I changed the  (-4 . "&=")  to  (-4 . "&")  which is all that's needed in this case.  And another:  If the f variable and the REGEN were there to "clear" highlighting of pre-selected objects that don't fit the criteria, I find it's not necessary -- (sssetfirst nil ss) clears highlighting from anything not in the ss selection set.

 

It can be enhanced easily to ask for a number of sides for different shaped polygons, and/or for the property to filter by.

Kent Cooper, AIA
Message 4 of 5

Anonymous
Not applicable

Thanks guys. Both the logics work fantastically well. @ВeekeeCZ 's logic can be used if the selection has to be done only for a specified area. For an entire drawing sheet we can use @Kent1Cooper 's logic. 

 

As mentioned, can we ask the user to mention the number of sides the polygon needs to have ? 

Also, can the selected objects be numbered sequentially ? 

 

Thanks once again 🙂

 

Regards

0 Likes
Message 5 of 5

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

... Also, can the selected objects be numbered sequentially ? ...

Regards


What do you mean?

 

The first part:

(vl-load-com)

(defun c:SelPolArea ( / fuzz ss ar i en f)

  (setq fuzz 	0.01)

  (or *sa-vtc*
      (setq *sa-vtc* 3))

  (setq f (ssget "I"))
  
  (if (and (setq *sa-vtc* (cond ((getint (strcat "\nNumber or vertices <" (itoa *sa-vtc*) ">: ")))
				(*sa-vtc*)))
	   (setq ss (ssget (list '(0 . "LWPOLYLINE") (cons 90 *sa-vtc*) '(-4 . "&=") '(70 . 1))))
	   (setq ar (getreal "\nArea: "))
	   )
    (repeat (setq i (sslength ss))
      (setq en (ssname ss (setq i (1- i))))
      (if (not (equal ar (vlax-curve-getarea en) fuzz))
	(ssdel en ss))))
  
  (if f (command "_.regen"))
  (sssetfirst nil ss)
  (princ)
  )
0 Likes