Author Topic: vla-get-activeselectionset -> collection  (Read 4870 times)

0 Members and 1 Guest are viewing this topic.

ArgV

  • Guest
vla-get-activeselectionset -> collection
« on: February 25, 2010, 03:05:43 PM »


So, I'm trying to change (if a selection set exists) all items in the current selection set to a new layer created using VLISP and the vla-add.

However, a selection set is apparently NOT a collection, and to use vlax-map-collection, it obviously must be a collection.

how would I convert or create a 'collection' with my active selection set?


here is the part of the code I'm working with (that doesn't work)  :-P
Code: [Select]
(if
  (vla-get-activeselectionset (vla-get-activedocument *ACAD*))
  (vlax-map-collection '(lambda (x)
     (vla-put-layer x newLayer))
  (vla-get-activeselectionset)) ;<-- cannot use a selection set (gets "too few arguments" error)
  )



thanks!

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: vla-get-activeselectionset -> collection
« Reply #1 on: February 25, 2010, 03:07:32 PM »
You are not supplying vla-get-activeselectionset with enough arguments (i.e. the Document object),  :wink:

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: vla-get-activeselectionset -> collection
« Reply #2 on: February 25, 2010, 03:11:32 PM »
Oh, and the function and object are the wrong way around...

Better:

Code: [Select]
(defun c:test (/ doc ss)
  (vl-load-com)

  (setq doc (vla-get-ActiveDocument
              (vlax-get-acad-object)))

  (or (tblsearch "LAYER" "Lee Mac")
      (vla-Add (vla-get-layers doc) "Lee Mac"))

  (if (ssget "_:L")
    (progn
      (vlax-map-collection
        (setq ss (vla-get-ActiveSelectionset doc))
          (function
            (lambda (object)
              (vla-put-layer object "Lee Mac"))))

      (vla-delete ss)))
 
  (princ))
                 

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: vla-get-activeselectionset -> collection
« Reply #3 on: February 25, 2010, 03:27:26 PM »
Oh, and 1 more thing:

Code: [Select]
(vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))

Will always return true even if the SelectionSet is empty - better to check:

Code: [Select]
(not (zerop (vla-get-Count (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))))

 :-)

ArgV

  • Guest
Re: vla-get-activeselectionset -> collection
« Reply #4 on: February 26, 2010, 08:14:54 PM »
Oh, and 1 more thing:

Code: [Select]
(vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))

Will always return true even if the SelectionSet is empty - better to check:

Code: [Select]
(not (zerop (vla-get-Count (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))))


Hey, thanks Lee. :) So, I've not yet tried all this yet, but is a selection set considered a collection then? I just thought it was that, and didn't realize I had all sorts of other stuff screwed up. I was in a hurry, so of course I was just stuck on one thing. ;)


 :-)


Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: vla-get-activeselectionset -> collection
« Reply #5 on: February 27, 2010, 05:27:07 AM »
Yes, a SelectionSet is a Collection Object  :-)

nivuahc

  • Guest
Re: vla-get-activeselectionset -> collection
« Reply #6 on: February 27, 2010, 09:52:29 AM »
Wouldn't it be easier to create a group of the selection set and parse through the objects in the group?

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: vla-get-activeselectionset -> collection
« Reply #7 on: February 27, 2010, 10:09:15 AM »
Wouldn't it be easier to create a group of the selection set and parse through the objects in the group?

Not sure what you are hinting at (a list?) but, the alternative is to use vlax-for on the collection object  :-)

nivuahc

  • Guest
Re: vla-get-activeselectionset -> collection
« Reply #8 on: February 27, 2010, 10:51:38 AM »
Wouldn't it be easier to create a group of the selection set and parse through the objects in the group?

Not sure what you are hinting at (a list?) but, the alternative is to use vlax-for on the collection object  :-)

Ignore me, I was confusing this thread with another one and mixing that up with something I was working on yesterday, and thought that the problem was with multiple selection sets. I blame old age.  :ugly:

But my idea was that, if multiple selections sets were the problem then temporary groups (which are just saved selection sets, really) would be a solution.

But that's not at issue here so pretend I didn't say anything.  :-D

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: vla-get-activeselectionset -> collection
« Reply #9 on: February 27, 2010, 10:54:16 AM »
No worries  :-)