Author Topic: Finding block in Block collection w/ it's name  (Read 4267 times)

0 Members and 1 Guest are viewing this topic.

ArgV

  • Guest
Finding block in Block collection w/ it's name
« on: August 14, 2009, 10:00:13 PM »
Hey all. Good weekend. :)

Is there a way to, rather than iterating through the block collection for each block I have in a blockNameList, just find it using the blocks name to go strait to it?

I think it can be done, but I can't remember how it's done or what the syntax is.

thanks!

-ArgV

taner

  • Guest
Re: Finding block in Block collection w/ it's name
« Reply #1 on: August 14, 2009, 11:09:01 PM »
Quote
(vl-catch-all-apply '(lambda ()
             (vlax-ename->vla-object (tblobjname "block" name))
           )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Finding block in Block collection w/ it's name
« Reply #2 on: August 14, 2009, 11:59:38 PM »
I do it using Library functions

Library stuff
Code: [Select]
(defun kdub:safeitem (collection item / returnvalue)
  (if (not (vl-catch-all-error-p
             (setq returnvalue (vl-catch-all-apply 'vla-item
                                                   (list collection item)
                               )
             )
           )
      )
    returnvalue
  )
)

(defun kdub:block-p (name)
(kdub:safeitem (vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
  name
)
)

The Code :
Code: [Select]
(setq BlockObject (kdub:block-p "TheBlockNameIWantToFind"))

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ArgV

  • Guest
Re: Finding block in Block collection w/ it's name
« Reply #3 on: August 15, 2009, 05:27:41 AM »
I do it using Library functions

Library stuff
Code: [Select]
(defun kdub:safeitem (collection item / returnvalue)
  (if (not (vl-catch-all-error-p
             (setq returnvalue (vl-catch-all-apply 'vla-item
                                                   (list collection item)
                               )
             )
           )
      )
    returnvalue
  )
)

(defun kdub:block-p (name)
(kdub:safeitem (vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
  name
)
)

The Code :
Code: [Select]
(setq BlockObject (kdub:block-p "TheBlockNameIWantToFind"))


Ok, cool. Thank you. :)

ArgV

  • Guest
Re: Finding block in Block collection w/ it's name
« Reply #4 on: August 15, 2009, 05:28:35 AM »
Quote
(vl-catch-all-apply '(lambda ()
             (vlax-ename->vla-object (tblobjname "block" name))
           )
)

Thank you for replying. I was more looking for the object collection. Sorry I wasn't very clear on that.  :|

Joe Burke

  • Guest
Re: Finding block in Block collection w/ it's name
« Reply #5 on: August 15, 2009, 09:35:38 AM »
Object collection? There's no such thing.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Finding block in Block collection w/ it's name
« Reply #6 on: August 15, 2009, 10:01:24 AM »
I think it depends upon what you are trying to achieve ArgV - could you explain a bit more.

ArgV

  • Guest
Re: Finding block in Block collection w/ it's name
« Reply #7 on: September 07, 2009, 11:28:18 AM »
Object collection? There's no such thing.

Sorry, was in a hurry. BLOCK collection.  :-o

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Finding block in Block collection w/ it's name
« Reply #8 on: September 07, 2009, 11:29:38 AM »
Is this matter resolved now ArgV?

ArgV

  • Guest
Re: Finding block in Block collection w/ it's name
« Reply #9 on: September 07, 2009, 11:31:01 AM »
I think it depends upon what you are trying to achieve ArgV - could you explain a bit more.

I got it. I was looking for:

Code: [Select]
(if (not (vl-catch-all-error-p
             (setq returnvalue [color=red](vl-catch-all-apply 'vla-item
                                                   (list collection item)[/color]
                               )
             )
           )
      )
 returnvalue
  )


Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Finding block in Block collection w/ it's name
« Reply #10 on: September 07, 2009, 11:43:29 AM »
Cool  :-)