Select block with higher string number

Select block with higher string number

msarqui
Collaborator Collaborator
498 Views
5 Replies
Message 1 of 6

Select block with higher string number

msarqui
Collaborator
Collaborator

Hi guys,

 

May I have you help please?

 

In the attached file I have a block called "REVISION" with some tags.

I am looking for a routine that will put in a selection set (ssget) only the instance of this block with the higher string number in the REVB tag.

So, for exemple, In the case of the attached file, it will be the instance with the "3".

 

Thanks

Marcelo

0 Likes
Accepted solutions (2)
499 Views
5 Replies
Replies (5)
Message 2 of 6

hmsilva
Mentor
Mentor
Accepted solution

Hi Marcelo,

as a starting point...

 

(vl-load-com)
(defun c:demo (/ atts big hnd i obj ss val)
   (if (setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "REVISION") (cons 410 (getvar 'ctab)) '(66 . 1))))
      (progn
         (repeat (setq i (sslength ss))
            (setq hnd  (ssname ss (setq i (1- i)))
                  obj  (vlax-ename->vla-object hnd)
                  atts (vlax-invoke obj 'GetAttributes)
            )
            (foreach att atts
               (if (and (= (vla-get-TagString att) "REVB")
                        (setq val (vla-get-TextString att))
                        (wcmatch val "#*")
                        (setq val (read val))
                   )
                  (cond ((null big)
                         (setq big (cons val hnd))
                        )
                        ((and big
                              (> val (car big))
                         )
                         (setq big (cons val hnd))
                        )
                  )
               )
            )
         )
         (if big
            (princ big)
            (princ "\nREVB don't have valid values... ")
         )
      )
      (princ "\nNo REVISION blk was found in the current tab... ")
   )
   (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 3 of 6

marko_ribar
Advisor
Advisor
Accepted solution
(defun c:selhighestattvaluereference ( / assoclst b )

  (vl-load-com)

  (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for a b
      (if (and
            (= (vla-get-objectname a) "AcDbBlockReference")
            (= (vla-get-hasattributes a) :vlax-true)
          )
        (foreach c (safearray-value (variant-value (vla-getattributes a)))
          (if (= (vla-get-tagstring c) "REVB")
            (setq assoclst (cons (cons (vla-get-textstring c) (vlax-vla-object->ename a)) assoclst))
          )
        )
      )
    )
  )
  (if assoclst
    (progn
      (setq b (cdar (vl-sort assoclst '(lambda ( a b ) (> (atoi (car a)) (atoi (car b)))))))
      (sssetfirst nil (ssadd b))
    )
  )
  (princ)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 4 of 6

devitg
Advisor
Advisor

Hi HMSILVA , as the OP ask to put the inser in a selections set .

 

I suggest it 

 

 

(if big
           (progn 
            (princ (cdr big))
            (setq insert-ss (ssadd (cdr big)))
            
            );progn  
           (princ "\nREVB don't have valid values... ")
         )

Could it be so?

Message 5 of 6

msarqui
Collaborator
Collaborator

Many thanks guys!

I can handle from here.

Marcelo

0 Likes
Message 6 of 6

hmsilva
Mentor
Mentor

@devitg wrote:

Hi HMSILVA , as the OP ask to put the inser in a selections set .

 

I suggest it 

 

 

(if big
           (progn 
            (princ (cdr big))
            (setq insert-ss (ssadd (cdr big)))
            
            );progn  
           (princ "\nREVB don't have valid values... ")
         )

Could it be so?


Hi Gabriel,

Marcelo (the OP), already have a pretty good level in programming, so I would prefer to just offering him a start to his code, and leave the finalization ti him...

 

@msarqui

You're welcome, Marcelo
Glad I could help

Henrique

 

Cheers

Henrique

EESignature

0 Likes