subodh_gis Posted May 27, 2014 Posted May 27, 2014 ;; If the selection set (txt) can be obtained and it holds more than one item ;;then we will use (if (< 1 (sslength txt)) (do this) ) ;;what if selection set (txt) don't have any entity. (if (= nil (sslength txt)) ;;but it is not working plz suggest right way (do this) ) Quote
BIGAL Posted May 27, 2014 Posted May 27, 2014 (edited) Try this (if (/= txt nil) (Progn ; if more than 1 line of code (do this) ) ) Edited May 27, 2014 by BIGAL Quote
BIGAL Posted May 27, 2014 Posted May 27, 2014 Have a look at this post by LEE-Mac it has error checking for text in the post by him http://www.cadtutor.net/forum/showthread.php?86575-Draw-near-points-of-text-entities Quote
Tharwat Posted May 27, 2014 Posted May 27, 2014 What are you trying to do ? and post your complete example cause to have a condition with the sslength function is not the proper way in general . Quote
subodh_gis Posted May 27, 2014 Author Posted May 27, 2014 This code is selecting the closed polylines if they have more than one Text,Mtext inside. But if i like to select the closed polylines which have no Text,Mtext inside. (defun c:mtpl ( / app ent grp idx lst mni mxa out sel tmp txt ) (if (setq sel (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1)))) (progn (repeat (setq idx (sslength sel)) (setq ent (ssname sel (setq idx (1- idx))) lst (cons (cons ent (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent)))) lst) ) ) (setq tmp (apply 'append (mapcar 'cdr lst)) mni (car tmp) mxa (car tmp) ) (foreach pnt (cdr tmp) (setq mni (mapcar 'min mni pnt) mxa (mapcar 'max mxa pnt) ) ) (setq app (vlax-get-acad-object) out (ssadd) ) (vla-zoomwindow app (vlax-3D-point mni) (vlax-3D-point mxa)) (foreach grp lst (if (and (setq txt (ssget "_wp" (mapcar '(lambda ( p ) (trans p (car grp) 1)) (cdr grp)) '((0 . "TEXT,MTEXT")))) (< 1 (sslength txt)) ) (ssadd (car grp) out) ) (setq txt nil) (gc) ) (sssetfirst nil out) ) ) (princ) ) (vl-load-com) (princ) Quote
Tharwat Posted May 27, 2014 Posted May 27, 2014 This code is selecting the closed polylines if they have more than one Text,Mtext inside.But if i like to select the closed polylines which have no Text,Mtext inside. Replace this part . (foreach grp lst (if (not (setq txt (ssget "_wp" (mapcar '(lambda ( p ) (trans p (car grp) 1)) (cdr grp)) '((0 . "TEXT,MTEXT")))) ) (ssadd (car grp) out) ) (setq txt nil) (gc) ) Quote
subodh_gis Posted May 27, 2014 Author Posted May 27, 2014 Now it is selecting all the polylines (defun c:mtpl ( / app ent grp idx lst mni mxa out sel tmp txt ) (if (setq sel (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1)))) (progn (repeat (setq idx (sslength sel)) (setq ent (ssname sel (setq idx (1- idx))) lst (cons (cons ent (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent)))) lst) ) ) (setq tmp (apply 'append (mapcar 'cdr lst)) mni (car tmp) mxa (car tmp) ) (foreach pnt (cdr tmp) (setq mni (mapcar 'min mni pnt) mxa (mapcar 'max mxa pnt) ) ) (setq app (vlax-get-acad-object) out (ssadd) ) (vla-zoomwindow app (vlax-3D-point mni) (vlax-3D-point mxa)) (foreach grp lst (if (not (setq txt (ssget "_wp" (mapcar '(lambda ( p ) (trans p (car grp) 1)) (cdr grp)) '((0 . "TEXT,MTEXT")))) ) (ssadd (car grp) out) ) (setq txt nil) (gc) ) (sssetfirst nil out) ) ) (princ) ) (vl-load-com) (princ) Quote
Tharwat Posted May 27, 2014 Posted May 27, 2014 But if i like to select the closed polylines which have no Text,Mtext inside. Now it is selecting all the polylines Settle your goal first and after that post your question Quote
subodh_gis Posted May 27, 2014 Author Posted May 27, 2014 i only like to select polyline which don't have text inside. that's it. Quote
Tharwat Posted May 27, 2014 Posted May 27, 2014 i only like to select polyline which don't have text inside. that's it. So my modification and your rearrangement on the routine should do the trick in posts # 6 & 7 , otherwise upload the drawing you are testing the codes on . Quote
subodh_gis Posted May 27, 2014 Author Posted May 27, 2014 Thanks Tharwat! Its working fine now. but why (/= txt nil) was not working. Quote
Tharwat Posted May 27, 2014 Posted May 27, 2014 Thanks Tharwat! Its working fine now. It was but why (/= txt nil) was not working. That means does not equal to nil , so it has a value which is not nil Quote
Tharwat Posted May 27, 2014 Posted May 27, 2014 Thanks It is working fine now. Happy to hear that . You're welcome . Quote
subodh_gis Posted May 27, 2014 Author Posted May 27, 2014 I was thinking that instead of selecting, can we change the property of polyline like color and LW. Quote
Tharwat Posted May 27, 2014 Posted May 27, 2014 I was thinking that instead of selecting, can we change the property of polyline like color and LW. Yes you can , by iterating through each entity in the selection set and update any property you want by adding / appending it to the DXF codes . Quote
MSasu Posted May 27, 2014 Posted May 27, 2014 Or may do the same for entire selection set by calling CHPROP command: (if (setq selSet (ssget)) (command "_CHPROP" selSet "" "_C" 2 "") ;change color to yellow ) Quote
subodh_gis Posted May 27, 2014 Author Posted May 27, 2014 Thanks MSasu this way i know but in my below code if i like to change the color of polylines which have no text inside. (defun c:mtpl ( / app ent grp idx lst mni mxa out sel tmp txt ) (if (setq sel (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1)))) (progn (repeat (setq idx (sslength sel)) (setq ent (ssname sel (setq idx (1- idx))) lst (cons (cons ent (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent)))) lst) ) ) (setq tmp (apply 'append (mapcar 'cdr lst)) mni (car tmp) mxa (car tmp) ) (foreach pnt (cdr tmp) (setq mni (mapcar 'min mni pnt) mxa (mapcar 'max mxa pnt) ) ) (setq app (vlax-get-acad-object) out (ssadd) ) (vla-zoomwindow app (vlax-3D-point mni) (vlax-3D-point mxa)) (foreach grp lst (if (not (setq txt (ssget "_wp" (mapcar '(lambda ( p ) (trans p (car grp) 1)) (cdr grp)) '((0 . "TEXT,MTEXT")))) ) (ssadd (car grp) out) ) (setq txt nil) (gc) ) (sssetfirst nil out) ) ) (princ) ) (vl-load-com) (princ) Quote
Lee Mac Posted May 27, 2014 Posted May 27, 2014 This code is selecting the closed polylines if they have more than one Text,Mtext inside.But if i like to select the closed polylines which have no Text,Mtext inside. A tip for future posts: when posting code that is not your own, it is common etiquette to indicate the original author/source, otherwise the posted code is assumed to be your own. Please familiarise yourself with the Code Posting Guidlines applicable to all code posted on this forum. Quote
BIGAL Posted May 28, 2014 Posted May 28, 2014 A 3rd way seeing your using VL why not use gets & puts for color and linetype etc (vla-put-color ent 0) (vla-put-linetype ent "Bylayer") (vla-put-lineweight ent aclnwtbyblock) 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.