Jump to content

SSGET - BLOCK, then Search Descriptions


Recommended Posts

Posted

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

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

  • GregGleason

    13

  • ronjonp

    12

  • BIGAL

    3

  • Lee Mac

    3

Top Posters In This Topic

Posted Images

Posted

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

Posted
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

Posted

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

Posted

Block description is part of the block definition. Try creating a new block and look at the lower right corner of the options.

Posted

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.

Posted

...

Not sure what an equivalent in VL is it may be a property rather than a get.

 

Here's a VL example:

2018-03-20_8-13-09.png

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

 

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

 

Hope that makes sense.

 

Greg

EAE_1.jpg

Posted

..

Hope that makes sense.

 

Greg

 

It does now :P ...

Posted

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

Posted (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 by ronjonp
Posted
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.

 

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

 

:facepalm: There was no mention of attributes in your first post...

 

A block description typically refers to this:

 

blockdesc.png

Posted
:facepalm: 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. :facepalm: Sometimes I wish there was a requirement to post a sample dwg....

Posted

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.

Posted
:facepalm: 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

Posted
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

Posted

Change (wcmatch val "AAA,BBB,CCC") to (not (wcmatch val "AAA,BBB,CCC")).

Posted
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

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