GregGleason Posted March 19, 2018 Posted March 19, 2018 I have an SSGET for a block, and the selection works. I then want to do a wildcard search for each block description. Then I want to keep blocks with descriptions with "AAA", "BBB", and "CCC" and exclude other blocks from the selection. Once I have the selection I want to change that selection to another layer. Here is what I have so far: (defun c:Test ( / in ss en de myco) (setq myco 0) (if (setq in -1 ss (ssget "_C" '(7.244 2.071) '(16.665 10.003) '((0 . "INSERT") (8 . "FTG-Iso")))) (while (setq en (ssname ss (setq in (1+ in)))) (progn (setq myco (+1 myco)) (princ (strcat "\n " (rtos myco 2 0) ". Hey!")) (setq de (entget en description)) ; (princ (strcat "\n " de)) [color=blue]{Exclude entities that do not have valid strings in description}[/color] ) ) ) (sssetfirst nil ss) (princ) ) Greg Quote
Lee Mac Posted March 19, 2018 Posted March 19, 2018 Here's a nudge in the right direction - (defun c:test ( / i s ) (if (setq s (ssget "_C" '(7.244 2.071) '(16.665 10.003) '((0 . "INSERT") (8 . "FTG-Iso")))) (repeat (setq i (sslength s)) (print (cdr (assoc 4 (entget (tblobjname "block" (cdr (assoc 2 (entget (ssname s (setq i (1- i))))))))))) ) ) (princ) ) Quote
GregGleason Posted March 19, 2018 Author Posted March 19, 2018 Here's a nudge in the right direction - (defun c:test ( / i s ) (if (setq s (ssget "_C" '(7.244 2.071) '(16.665 10.003) '((0 . "INSERT") (8 . "FTG-Iso")))) (repeat (setq i (sslength s)) (print (cdr (assoc 4 (entget (tblobjname "block" (cdr (assoc 2 (entget (ssname s (setq i (1- i))))))))))) ) ) (princ) ) Lee, I ran this and all I got was a string of "nil" in the Text window. Is that what was supposed to happen? Greg Quote
BIGAL Posted March 20, 2018 Posted March 20, 2018 Greg Gleason I am confused descriptions ? Do you mean block name ? lee ? (entget (tblobjname "block" (cdr (assoc 2 (entget (car (entsel))))))) is ok returns nil no (assoc 4 (setq s (ssget "_C" '(7.244 2.071) '(16.665 10.003) '((0 . "INSERT") (8 . "FTG-Iso")))) (repeat (setq x (sslength s)) (setq obj (vlax-ename->vla-object (ssname s (setq x (- x 1))))) (princ "\n") (princ (vla-get-name obj)) ; put a cond here check for aaa bb ccc and change obj layer ; (vla-put-layer obj newlay) ) Quote
ronjonp Posted March 20, 2018 Posted March 20, 2018 Block description is part of the block definition. Try creating a new block and look at the lower right corner of the options. Quote
BIGAL Posted March 20, 2018 Posted March 20, 2018 Works fine Lee now that I have added some comments. Learn something new every day. Not sure what an equivalent in VL is it may be a property rather than a get. Quote
ronjonp Posted March 20, 2018 Posted March 20, 2018 ... Not sure what an equivalent in VL is it may be a property rather than a get. Here's a VL example: Quote
GregGleason Posted March 20, 2018 Author Posted March 20, 2018 Greg Gleason I am confused descriptions ? Do you mean block name ? lee ? (entget (tblobjname "block" (cdr (assoc 2 (entget (car (entsel))))))) is ok returns nil no (assoc 4 (setq s (ssget "_C" '(7.244 2.071) '(16.665 10.003) '((0 . "INSERT") (8 . "FTG-Iso")))) (repeat (setq x (sslength s)) (setq obj (vlax-ename->vla-object (ssname s (setq x (- x 1))))) (princ "\n") (princ (vla-get-name obj)) ; put a cond here check for aaa bb ccc and change obj layer ; (vla-put-layer obj newlay) ) This is what I mean by description. I want to be able to pull the description value out and examine it to decide whether or not to include it in the selection or not. Hope that makes sense. Greg Quote
ronjonp Posted March 20, 2018 Posted March 20, 2018 .. Hope that makes sense. Greg It does now ... Quote
GregGleason Posted March 20, 2018 Author Posted March 20, 2018 Well, I must admit I'm lost with the comments so far, as I do not have enough depth (at this point) to follow the code. It looks like the way I was doing it was not the right way, or at least not efficient. Can someone recommend a place to look to begin to understand what I want to accomplish? I want to move forward in my understanding while solving the problem. Greg Quote
ronjonp Posted March 20, 2018 Posted March 20, 2018 (edited) Try this quick untested example. (defun c:test (/ _getattvalue en in ss val) ;; RJP - Simple get attribute value sub .. no error checking (defun _getattvalue (block tag) (vl-some '(lambda (att) (cond ((= (strcase tag) (vla-get-tagstring att)) (vla-get-textstring att)))) (vlax-invoke block 'getattributes) ) ) ;; RJP - added (66 . 1) to filter ( attributed blocks ) (if (setq ss (ssget "_C" '(7.244 2.071) '(16.665 10.003) '((0 . "INSERT") (8 . "FTG-Iso") (66 . 1))) ) (foreach en (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (if (and ;; If we have a value, and it does not match the filter then remove item from selection (setq val (_getattvalue (vlax-ename->vla-object en) "Description")) (wcmatch val "AAA,BBB,CCC") ) (ssdel en ss) ) ) ) ;; Highlight selection (sssetfirst nil ss) (princ) ) Edited March 20, 2018 by ronjonp Quote
Tharwat Posted March 20, 2018 Posted March 20, 2018 Try this quick untested example. @ronjonp, Have a look HERE Quote
Lee Mac Posted March 20, 2018 Posted March 20, 2018 This is what I mean by description. I want to be able to pull the description value out and examine it to decide whether or not to include it in the selection or not. There was no mention of attributes in your first post... A block description typically refers to this: Quote
ronjonp Posted March 21, 2018 Posted March 21, 2018 There was no mention of attributes in your first post... A block description typically refers to this: [ATTACH]63539[/ATTACH] I thought the same thing too. Sometimes I wish there was a requirement to post a sample dwg.... Quote
BIGAL Posted March 21, 2018 Posted March 21, 2018 3rd agree what confused me, I do admit probably have never added a description to a block, just named it appropriately. Re VL like others looking for wrong word thanks ronjonp. Also no need to delete from list as the request was to change layer, if match aaa,bbb,ccc then change. Quote
GregGleason Posted March 21, 2018 Author Posted March 21, 2018 There was no mention of attributes in your first post... A block description typically refers to this: [ATTACH]63539[/ATTACH] Ugh! Sorry guys for making things so confusing. It was seen in the QPROP window so I assumed (wrongly, of course) that it was the natural description. I should have investigated further and have made it clear that it was a attribute called "Description". On the bright side, I'm still learning and I will not give up. You guys are the best. Greg Quote
GregGleason Posted March 21, 2018 Author Posted March 21, 2018 Try this quick untested example. (defun c:test (/ _getattvalue en in ss val) ;; RJP - Simple get attribute value sub .. no error checking (defun _getattvalue (block tag) (vl-some '(lambda (att) (cond ((= (strcase tag) (vla-get-tagstring att)) (vla-get-textstring att)))) (vlax-invoke block 'getattributes) ) ) ;; RJP - added (66 . 1) to filter ( attributed blocks ) (if (setq ss (ssget "_C" '(7.244 2.071) '(16.665 10.003) '((0 . "INSERT") (8 . "FTG-Iso") (66 . 1))) ) (foreach en (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (if (and ;; If we have a value, and it does not match the filter then remove item from selection (setq val (_getattvalue (vlax-ename->vla-object en) "Description")) (wcmatch val "AAA,BBB,CCC") ) (ssdel en ss) ) ) ) ;; Highlight selection (sssetfirst nil ss) (princ) ) ronjonp, thanks for the code. I ran it and it ran to completion, but all of the items remained selected regardless of the description contents. I put this code in after the "setq val" statement to see what it was set to ... (princ (strcat "\n -> (" val ")")) And I get this error which stops the execution: ; error: bad argument type: stringp nil I would think that the "val" variable would return a character string. Is that correct? Greg Quote
ronjonp Posted March 21, 2018 Posted March 21, 2018 Change (wcmatch val "AAA,BBB,CCC") to (not (wcmatch val "AAA,BBB,CCC")). Quote
GregGleason Posted March 21, 2018 Author Posted March 21, 2018 Change (wcmatch val "AAA,BBB,CCC") to (not (wcmatch val "AAA,BBB,CCC")). I changed that and the results are the same, with everyone of the blocks with that layer being selected (in this file there are 27). I even tried it with one item (like "AAA") but there was no difference in the results. I wonder why the block reference attribute is being ignored? Greg 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.