Radu Iordache Posted April 18, 2023 Posted April 18, 2023 This small lisp that I found on this forum and adapted a little (it was meant for groups), selects an image by clicking anywhere inside it. After clicking one image, it highlights it and exits the command. It would be helpful to modify it so that I can click more images one by one and continue to add them to the selection set until I press enter. In other words, I want it to repeat the selection procedure till I selected all wanted images. Can anybody help with that? Thanks in advance. (defun c:CIMG (/ ops enl pts sel) (and (setq enl (entlast)) (setvar 'cmdecho 0) (princ "\nClick inside the image: ") (vl-cmdf "_.BOUNDARY" pause "") (not (equal enl (setq enl (entlast)))) (setq pts (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget enl)))) (vl-cmdf "_.ERASE" enl "") (setvar 'cmdecho 1) (setq sel (ssget "_CP" pts '((0 . "IMAGE")))) (sssetfirst nil sel)) (if (= sel nil) (princ " You did not click an image!")) (princ)) CIMG.lsp Quote
Tsuky Posted April 18, 2023 Posted April 18, 2023 Perhaps this? (defun c:CIMG ( / e_last ss pt_in pts sel) (setq e_last (entlast) ss (ssadd)) (while (setq pt_in (getpoint "\nClick inside the image <Right click or Enter to exit>: ")) (bpoly pt_in nil '(0 0 1)) (cond ((and (entlast) (not (eq e_last (entlast)))) (setq pts (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget (entlast))))) (entdel (entlast)) (setq sel (ssget "_CP" pts '((0 . "IMAGE")))) (if sel (ssadd (ssname sel 0) ss) (princ "\nYou did not click an image!") ) ) ) ) (if ss (sssetfirst nil ss)) (prin1) ) Quote
Radu Iordache Posted April 18, 2023 Author Posted April 18, 2023 (edited) 56 minutes ago, Tsuky said: Perhaps this? (defun c:CIMG ( / e_last ss pt_in pts sel) (setq e_last (entlast) ss (ssadd)) (while (setq pt_in (getpoint "\nClick inside the image <Right click or Enter to exit>: ")) (bpoly pt_in nil '(0 0 1)) (cond ((and (entlast) (not (eq e_last (entlast)))) (setq pts (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget (entlast))))) (entdel (entlast)) (setq sel (ssget "_CP" pts '((0 . "IMAGE")))) (if sel (ssadd (ssname sel 0) ss) (princ "\nYou did not click an image!") ) ) ) ) (if ss (sssetfirst nil ss)) (prin1) ) It's not working, see below: Command: cimg Click inside the image <Right click or Enter to exit>: error: null function: BPOLY LATER EDIT: But it works like this: (command "_bpoly" pt_in "") instead of (bpoly pt_in nil '(0 0 1)) Forgot to say that I am using Progecad so maybe that is the reason. Thank you so much! Edited April 18, 2023 by Radu Iordache Quote
BIGAL Posted April 19, 2023 Posted April 19, 2023 Select images ??? (setq sel (ssget '((0 . "IMAGE")))) Quote
Tsuky Posted April 20, 2023 Posted April 20, 2023 (edited) @Radu Iordache You have problems with adjacent images, so try like this... (defun c:CIMG ( / e_last ss pt_in pts dlt p1 p2 sel) (setq e_last (entlast) ss (ssadd)) (while (setq pt_in (getpoint "\nClick inside the image <Right click or Enter to exit>: ")) ;(bpoly pt_in nil '(0 0 1)) (command "_bpoly" "_none" pt_in "") (cond ((and (entlast) (not (eq e_last (entlast)))) (setq pts (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget (entlast)))) dlt (/ (- (caar pts) (caadr pts)) 1000.0) p1 (list (- (apply 'min (mapcar 'car pts)) dlt) (- (apply 'min (mapcar 'cadr pts)) dlt)) p2 (list (+ (apply 'max (mapcar 'car pts)) dlt) (+ (apply 'max (mapcar 'cadr pts)) dlt)) ) (entdel (entlast)) (setq sel (ssget "_W" p1 p2 '((0 . "IMAGE")))) (if sel (progn (ssadd (ssname sel 0) ss) (sssetfirst nil ss)) (princ "\nYou did not click an image!") ) ) ) ) (prin1) ) Edited April 20, 2023 by Tsuky Quote
Radu Iordache Posted April 21, 2023 Author Posted April 21, 2023 16 hours ago, Tsuky said: @Radu Iordache You have problems with adjacent images, so try like this... (defun c:CIMG ( / e_last ss pt_in pts dlt p1 p2 sel) (setq e_last (entlast) ss (ssadd)) (while (setq pt_in (getpoint "\nClick inside the image <Right click or Enter to exit>: ")) ;(bpoly pt_in nil '(0 0 1)) (command "_bpoly" "_none" pt_in "") (cond ((and (entlast) (not (eq e_last (entlast)))) (setq pts (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget (entlast)))) dlt (/ (- (caar pts) (caadr pts)) 1000.0) p1 (list (- (apply 'min (mapcar 'car pts)) dlt) (- (apply 'min (mapcar 'cadr pts)) dlt)) p2 (list (+ (apply 'max (mapcar 'car pts)) dlt) (+ (apply 'max (mapcar 'cadr pts)) dlt)) ) (entdel (entlast)) (setq sel (ssget "_W" p1 p2 '((0 . "IMAGE")))) (if sel (progn (ssadd (ssname sel 0) ss) (sssetfirst nil ss)) (princ "\nYou did not click an image!") ) ) ) ) (prin1) ) It works! Thank you very much for your time! I also made this version involving some offset to the original boundary and using that with WP method but it may not work in some cases. (defun c:CIMG ( / e_last ss pt_in pts sel) (setq snap (getvar "osmode")) (setvar "osmode" 0) (setq e_last (entlast) ss (ssadd)) (setq imag (ssget "X" '((0 . "IMAGE")))) (while (setq pt_in (getpoint "\nClick in imagine <Sau click dreapta/enter pentru a termina selectia>: ")) (vl-cmdf "_.BPOLY" "a" "b" "n" imag "" "x" pt_in "") (command "-offset" "100" "(entlast)" "0,0" "") (cond ((and (entlast) (not (eq e_last (entlast)))) (setq pts (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget (entlast))))) (entdel (entlast)) (entdel (entlast)) (setq sel (ssget "WP" pts '((0 . "IMAGE")))) (if sel (progn (setq nents (sslength sel)) (repeat nents (setq ent (ssname sel (setq nents (1- nents)))) (ssadd ent ss) ) ) ) (setvar "grips" 0) (sssetfirst nil ss) ) ) ) (setvar "grips" 1) (setvar "osmode" snap) (if ss (sssetfirst nil ss)) (if (not sel) (princ "\nNu s-a selectat nicio imagine.")) (prin1) ) Quote
Radu Iordache Posted April 21, 2023 Author Posted April 21, 2023 On 4/19/2023 at 8:44 AM, BIGAL said: Select images ??? (setq sel (ssget '((0 . "IMAGE")))) I wanted to be able to select images (one or more but not all ) by clicking inside them (and not their frame). Quote
Recommended Posts
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.