Author Topic: (ssget "_X" ...) Vs. (vlax-for ... (vla-get-block ...))  (Read 10329 times)

0 Members and 1 Guest are viewing this topic.

Patrick_35

  • Guest
Re: (ssget "_X" ...) Vs. (vlax-for ... (vla-get-block ...))
« Reply #15 on: February 23, 2015, 03:50:24 AM »
Yes, ssget with activeselectionset is the best

I've had some trouble with the activeselectionset method in the past (an intermittent and inconsistent error: Automation Error. Calling method Clear of interface IAcadSelectionSet failed) and have now abandoned this method entirely.
Precisely why I abandoned its use as well.
I had the same problem that I solved using systematically erasing the selection. Since then, no problems. Now all my lisps use this method.
Look at the two lisps I posted

I would also delete the selection set [ (vla-delete sel) ] after processing, but this did not seem to resolve the issue; or are you referring to something else when you say 'solved using systematically erasing the selection'?
Sorry if my English is not great.
What I mean is that you make a selection with ssget and then your treatment with activeselectionset.
Then you make a vla-delete on activeselectionset
From what I could deduce is that a stacking selections causes this error and that systematically erasing the selection set, I do not have this problem.
I use it for years, post lisps with this method on other forums.

kruuger

  • Swamp Rat
  • Posts: 633
Re: (ssget "_X" ...) Vs. (vlax-for ... (vla-get-block ...))
« Reply #16 on: February 24, 2015, 05:31:40 AM »

draw few objects.
start XXX

Code: [Select]
(defun c:XXX (/ doc)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (ssget)
  (vlax-for %
    (vla-get-activeselectionset
      (vla-get-activedocument
        (vlax-get-acad-object)
      )
    )
    (princ %) (princ "\n")
  )
  (princ)
)

make few undo CTRL+Z.
try to run XXX and -> error: Automation Error. Calling method Clear of interface IAcadSelectionSet

as Patrick said. we add vla-delete and so far no more error.

Code: [Select]
(defun c:XXX (/ doc ss)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (ssget)
  (vlax-for %
    (setq ss
      (vla-get-activeselectionset
        (vla-get-activedocument
          (vlax-get-acad-object)
        )
      )
    )
    (princ %) (princ "\n")
  )
  (vla-delete ss)
  (princ)
)
i noticed that errors occurs very often after undo (when no vle-delete)
k.
« Last Edit: February 24, 2015, 05:37:11 AM by kruuger »

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: (ssget "_X" ...) Vs. (vlax-for ... (vla-get-block ...))
« Reply #17 on: February 24, 2015, 10:12:39 AM »
You may directly select inserts using filters
Code - Auto/Visual Lisp: [Select]
  1.   (setq ss  ( (lambda ( sname sss )
  2.                       ( (if (vl-catch-all-error-p
  3.                               (vl-catch-all-apply 'vla-item
  4.                                                   (list sss sname)
  5.                               )
  6.                             )
  7.                             vla-add
  8.                             vla-item
  9.                         )
  10.                         sss
  11.                         sname
  12.                       )
  13.                     )
  14.                     "SomeSet"
  15.                     (vla-get-selectionsets
  16.                       (vla-get-activedocument (vlax-get-acad-object)))
  17.             )
  18.   )
  19.   (vla-clear ss)
  20.   (setq
  21.     ssflt0 (vlax-make-safearray vlax-vbinteger '(0 . 0))
  22.     ssflt1 (vlax-make-safearray vlax-vbvariant '(0 . 0))
  23.   )
  24.  
  25.     ss
  26.     acselectionsetall
  27.     nil
  28.     nil
  29.     (vlax-safearray-fill ssflt0 '(0))
  30.     (vlax-safearray-fill ssflt1 '("INSERT"))
  31.   )
  32.   ss
  33. )

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (ssget "_X" ...) Vs. (vlax-for ... (vla-get-block ...))
« Reply #18 on: February 24, 2015, 12:17:32 PM »
If my test is valid I do not see the convenience:
Code: [Select]
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
    (ALE_SSGETINSERTS).....1388 / 2.4 <fastest>
    (ALE_SSGETINSERTS).....1450 / 2.3
    (P35_SSGETINSERTS).....1482 / 2.25
    (P35_SSGETINSERTS).....1529 / 2.18
    (NAZ_SSGETINSERTS).....2745 / 1.22
    (NAZ_SSGETINSERTS).....3338 / 1 <slowest>
Code: [Select]
(defun ALE_SSGetInserts ( /  sel idx lst )
    (if (setq sel (ssget "_X" '((0 . "INSERT"))))
        (repeat (setq idx (sslength sel))
            (setq lst (cons (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) lst))
        )
    )
)
(defun naz_SSGetInserts ( /  ss lst)
     (setq ss  ( (lambda ( sname sss )
                         ( (if (vl-catch-all-error-p
                                 (vl-catch-all-apply 'vla-item
                                                     (list sss sname)
                                 )
                               )
                               vla-add
                               vla-item
                           )
                           sss
                           sname
                         )
                       )
                       "SomeSet"
                       (vla-get-selectionsets
                         (vla-get-activedocument (vlax-get-acad-object)))
               )
     )
     (vla-clear ss)
     (setq
       ssflt0 (vlax-make-safearray vlax-vbinteger '(0 . 0))
       ssflt1 (vlax-make-safearray vlax-vbvariant '(0 . 0))
     )
     (vla-select
       ss
       acselectionsetall
       nil
       nil
       (vlax-safearray-fill ssflt0 '(0))
       (vlax-safearray-fill ssflt1 '("INSERT"))
     )
     (if ss (vlax-for blo ss (setq lst (cons blo lst))))
)
(defun P35_SSGetInserts ( /  doc sel lst)
     (setq
       doc (vla-get-activedocument (vlax-get-acad-object))
     )
     (and (ssget "_X" '((0 . "INSERT")))
       (progn
         (vlax-for blo (setq sel (vla-get-activeselectionset doc))
           (setq lst (cons blo lst))
         )
         (vla-delete sel)
       )
     )
     lst
)

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: (ssget "_X" ...) Vs. (vlax-for ... (vla-get-block ...))
« Reply #19 on: February 25, 2015, 01:46:55 AM »
:-( wow, my way is slowest. so, if i have to delete some garbage entities such as points, small lines, blank texts or wipeouts, what is the fastest way to do it?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (ssget "_X" ...) Vs. (vlax-for ... (vla-get-block ...))
« Reply #20 on: February 26, 2015, 01:13:35 PM »
I do not understand the question, it seems to me that there is the solution...