TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ArgV on August 14, 2009, 10:00:13 PM

Title: Finding block in Block collection w/ it's name
Post by: ArgV 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
Title: Re: Finding block in Block collection w/ it's name
Post by: taner on August 14, 2009, 11:09:01 PM
Quote
(vl-catch-all-apply '(lambda ()
             (vlax-ename->vla-object (tblobjname "block" name))
           )
)
Title: Re: Finding block in Block collection w/ it's name
Post by: Kerry 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"))

Title: Re: Finding block in Block collection w/ it's name
Post by: ArgV 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. :)
Title: Re: Finding block in Block collection w/ it's name
Post by: ArgV 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.  :|
Title: Re: Finding block in Block collection w/ it's name
Post by: Joe Burke on August 15, 2009, 09:35:38 AM
Object collection? There's no such thing.
Title: Re: Finding block in Block collection w/ it's name
Post by: Lee Mac 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.
Title: Re: Finding block in Block collection w/ it's name
Post by: ArgV on September 07, 2009, 11:28:18 AM
Object collection? There's no such thing.

Sorry, was in a hurry. BLOCK collection.  :-o
Title: Re: Finding block in Block collection w/ it's name
Post by: Lee Mac on September 07, 2009, 11:29:38 AM
Is this matter resolved now ArgV?
Title: Re: Finding block in Block collection w/ it's name
Post by: ArgV 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
  )

Title: Re: Finding block in Block collection w/ it's name
Post by: Lee Mac on September 07, 2009, 11:43:29 AM
Cool  :-)