Jump to content

Select object by insertion point


DGRL

Recommended Posts

Hi Coders

 

 

Was wondering if it is possible using visual lisp to select multiple objects from a list containing insertion points only

 

So list contains multiple insertion points of different objects that needs to be selected one by one and if implemented in my routines do something with it

Link to comment
Share on other sites

Yes - if the objects are blocks/texts, then iterate thru all and check their insertionpoint property.

Else if the objects do not support such property, use the 'expanding circle' approach to select the nearest objects on the given fuzz value.

Link to comment
Share on other sites

just a quicky before bedtime

 

attachment.php?attachmentid=63592&cid=1&stc=1

 

; near point - written for DGRL - rlx 25-3-2018
; pl is point list '((x y)(x y)...) , fz is fuzz factor
(defun c:tst ( / pl fz ss)
 (setq pl '((10 50)(20 50)(30 50)(40 50)(50 50)) fz 1 ss (ssget '((0 . "INSERT"))))
 (if ss (mapcar '(lambda (x) (princ "\n")(princ (getip x))) (chk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))))
 (princ)
)

(defun chk (%ss / l) (mapcar '(lambda (x) (if (near-member (getip x) pl fz) (setq l (cons x l)))) %ss) l)

(defun near-member (l1 l2 tol) (vl-some (function (lambda (l3) (vl-every '(lambda (n1 n2)(equal n1 n2 tol)) l1 l3))) l2))
(defun getip (e) (list (cadr (assoc 10 (entget e)))(caddr (assoc 10 (entget e)))))

(vl-load-com)

;(near-member '(20 50) '((10 50) (20 50) (30 50) (40 50)(50 50)) 0.1) -> T
;(near-member '(20 51) '((10 50) (20 50) (30 50) (40 50)(50 50)) 0.1) -> nil

gr.Rlx

drgl-near-point-test.jpg

Edited by rlx
Link to comment
Share on other sites

Note that such groups can be filtered directly from the ssget filter list ;)

 

FWIW, i prefer relational test

pro: simple, reliable & efficient

cons: no fuzz

 

(setq [b] pl [/b]'((10. 50.)(20. 50.)(30. 50.)(40. 50.)(50. 50.))[color="green"]; point list[/color]
ss 
(ssget
 (append (vl-list* '(0 . "CIRCLE,TEXT,INSERT"); filter
	    '(-4 . "<OR")
	    (apply 'append (mapcar ''((x) (list '(-4 . "=,=,*") (cons 10 x))) [b]pl [/b]))
	    ) 
  '((-4 . "OR>"))
  ) 
   ) 
)
)

Link to comment
Share on other sites

Note that such groups can be filtered directly from the ssget filter list ;)

 

Last night my near-member function came to me saying he wanted a job because he was bored ... so I gave him one...

Link to comment
Share on other sites

FWIW, i prefer relational test

pro: simple, reliable & efficient

cons: no fuzz

 

Reason I used fuzz was cause of a function I use to copy an entire array or 'table' of strings , rows and colums , from one set to another and had problems with mixed alignments. So one column used middle left , another just middle etc. and 'quickly' found out neither group 10 or 11 could always be trusted. So decided to use a fuzze factor and most or all my problems were gone. If coordinates are truly reliable then you're right and a 'simple' ssget filter is adequate.

 

gr. Rlx

Link to comment
Share on other sites

FWIW, i prefer relational test

pro: simple, reliable & efficient

cons: no fuzz

 

A fuzz factor is still possible in this scenario, for example:

(defun ssget-by-pointlist ( lst fuz )
   (ssget "_X"
       (append
          '(
               (0 . "ARC,CIRCLE,ELLIPSE,INSERT,TEXT,MTEXT,POINT") ;; Objects for which DXF 10 is meaningful
               (-4 . "<OR")
           )
           (apply 'append
               (mapcar
                  '(lambda ( x )
                       (list
                          '(-4 . "<AND")
                          '(-4 . ">=,>=,>=")
                           (cons 10 (mapcar '- x (list fuz fuz fuz)))
                          '(-4 . "<=,<=,<=")
                           (cons 10 (mapcar '+ x (list fuz fuz fuz)))
                          '(-4 . "AND>")
                       )
                   )
                   lst
               )
           )
          '(
               (-4 . "OR>")
           )
       )
   )
)

 

Last night my near-member function came to me saying he wanted a job because he was bored ... so I gave him one...

 

Haha! :lol:

Link to comment
Share on other sites

A fuzz factor is still possible in this scenario, for example:

 

Nice!

Lee deserves a beer! :beer:

 

Rlx just a 2c for near-member (equal works on nested lists):

 

(defun near-member (l1 l2 tol) (vl-some (function (lambda (l3) (equal l1 l3 tol))) l2))

 

I'm guessing its another old function of yours. :)

Link to comment
Share on other sites

A fuzz factor is still possible in this scenario, for example:

(defun ssget-by-pointlist ( lst fuz )...

 

Thanks Lee Nice! Great Tips of the day :)

 

..If coordinates are truly reliable then you're right and a 'simple' ssget filter is adequate.

gr. Rlx

 

fuzz is the key, Lee is the unlocker :P

 

Nice!

Lee deserves a beer! :beer:

agree :beer:

Link to comment
Share on other sites

well ok then... waiter , beers for everyone and 2 cents for Grrr!

 

 

new project , probably thousands of loops so time to dust off the old loop-generator...

 

 

:beer:

 

 

gr.Rlx

Link to comment
Share on other sites

GOT IT ALREADY

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-AutoLISP/files/GUID-7E85CB8F-B4DA-42F3-ABD3-89342A11EF9B-htm.html

 

Thanks to all of you

Though the answers raised a question

 

What is a fuz factor?

 

 

fuzz or fuzzy is just another word for tolerance , just look at lisp helpfile for difference between = , eq and equal

 

 

gr. Rlx

Edited by rlx
Link to comment
Share on other sites

Nice!

Lee deserves a beer! :beer:

 

Rlx just a 2c for near-member (equal works on nested lists):

 

(defun near-member (l1 l2 tol) (vl-some (function (lambda (l3) (equal l1 l3 tol))) l2))

I'm guessing its another old function of yours. :)

 

 

Depends , what is old haha ... but , after I posted , I did have a little nagging voice asking me if I really needed the extra vl-every , but then the lights went out , bedtime... Anyways , I liked this function before and now I like it even more , thanks Grrr!

 

 

gr. Rlx

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