Author Topic: Block select Lisp needed...  (Read 17388 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #15 on: August 26, 2004, 10:56:48 AM »
Man I have a LOT of tweaking to do. I'm not even close to matching that Stig.
TheSwamp.org  (serving the CAD community since 2003)

hudster

  • Gator
  • Posts: 2848
Block select Lisp needed...
« Reply #16 on: August 26, 2004, 11:07:21 AM »
Many thanks, I owe you one.

Works great.  I changed the end to pre-assign a layer for the blocks to be moved to. :)
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

SMadsen

  • Guest
Block select Lisp needed...
« Reply #17 on: August 26, 2004, 11:10:25 AM »
Quote from: Mark Thomas
Man I have a LOT of tweaking to do. I'm not even close to matching that Stig.

Well, you know my opinion on the VLA stuff .. don't use it if it doesn't serve a purpose :)

Glad you could use it, Hudster

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Block select Lisp needed...
« Reply #18 on: August 26, 2004, 05:57:34 PM »
Quote from: Mark Thomas
Man I have a LOT of tweaking to do. I'm not even close to matching that Stig.

Seems to me your biggest tweak will be creating a selection set of attributed blocks so you don't step through every entity.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #19 on: August 27, 2004, 07:27:02 AM »
Quote from: Jeff_M
Seems to me your biggest tweak will be creating a selection set of attributed blocks so you don't step through every entity.

I agree Jeff.

Changing mine to use the ss method like Mr. Madsen appears to be a bit faster. than his. :D
Code: [Select]


(defun timer (stime)
  (setq time (getvar "MILLISECS"))
  (setq time (/ (- (getvar "MILLISECS") stime) 1000.0))
  (princ (strcat "Elapsed time: " (rtos time) " seconds"))
  )

(defun get-attribs (obj)
  (vlax-safearray->list
    (vlax-variant-value
      (vla-GetAttributes obj)
      )
    )
  )


(defun check-for-char (obj char / attribs ans_lst)

  (setq attribs (get-attribs obj))

  (mapcar
    '(lambda (x / ts)
       (setq ts (vla-get-textstring x))
       (cond ((= (substr ts (strlen ts)) char)
              (setq ans_lst (cons "yes" ans)))
             )
       )
    attribs
    ); mapcar

  (if (vl-position "yes" ans_lst)
    T nil
    )
  )

(defun gbwa (/ time sset a obj)
  (setq time (getvar "MILLISECS"))
  (cond ((setq sset (ssget "X" '((0 . "INSERT") (66 . 1))))
         (setq a 0)
         (repeat (sslength sset)
                 (setq obj (vlax-ename->vla-object (ssname sset a)))
                 (if (check-for-char obj "E")
                   (vla-put-layer obj "0"); change layer name here
                   )
                 (vlax-release-object obj)
                 (setq a (1+ a))
                 )
         )
        (T (princ "No attributed blocks found"))
        )
  (timer time)
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
Block select Lisp needed...
« Reply #20 on: August 27, 2004, 08:23:31 AM »
Hey Mark? Remember that recursive ss->vla-object function you built? I was wondering if you made that work in here somehow, what the speed difference would be?  At the same time, I've given some thought on Jeff's comment. The differences appear to be that your initial routine scans the entire modelspace (every entity in it), whereas the 66 . 1 still has to scan every block in the drawing paper and modelspace. I was wondering if you went back to your first version and set it up to look for blocks in modelspace only, would that also increase the speed?


BTW, can you post your results between routines?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #21 on: August 27, 2004, 08:29:19 AM »
Quote from: Daron
Hey Mark? Remember that recursive ss->vla-object function you built? I was wondering if you made that work in here somehow, what the speed difference would be?

I kinda doubt it.
Quote
At the same time, I've given some thought on Jeff's comment. The differences appear to be that your initial routine scans the entire modelspace (every entity in it), whereas the 66 . 1 still has to scan every block in the drawing paper and modelspace. I was wondering if you went back to your first version and set it up to look for blocks in modelspace only, would that also increase the speed?

It was modelspace only, I think!


Quote
BTW, can you post your results between routines?

sure will.
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
Block select Lisp needed...
« Reply #22 on: August 27, 2004, 08:35:58 AM »
The first routine was just modelspace, but every entity in that space i.e. lines arcs. The (ssget "x" 66 . 1) scans every BLOCK object in the database. That includes paperspace. I think you could bring the numbers down by searching blocks in modelspace. I'm not sure how complicated that would be since the spaces (model/paper) are considered a block object, too. Would be neat to see.

SMadsen

  • Guest
Block select Lisp needed...
« Reply #23 on: August 27, 2004, 08:43:58 AM »
Excellent, Mark.
Here are times for 20 runs on 100 blocks, each containing 7 attributes:

;; GBWA
(/ (+ 0.2500 0.2340 0.2350 0.2190 0.2190 0.2190 0.2180 0.2180 0.2180 0.2190
      0.2190 0.2340 0.2810 0.2190 0.2180 0.2190 0.2190 0.2190 0.2190 0.2180) 20.0)
;; average time = 0.2257

;; C:ATTLAY
(/ (+ 0.2190 0.2190 0.2350 0.2190 0.2190 0.2810 0.2180 0.2190 0.2180 0.2190
      0.2960 0.2190 0.2340 0.2340 0.2190 0.2810 0.2190 0.2180 0.2190 0.2190) 20.0)
;; average time = 0.2312

Bypassing COMMAND and moving the blocks directly from the SSNAME loop - same method as you are using - gives these times:

;; ATTLAY
(/ (+ 0.2030 0.2190 0.2030 0.2190 0.2030 0.2810 0.2030 0.2190 0.2340 0.2190
      0.2660 0.2190 0.2030 0.2190 0.2180 0.2810 0.2190 0.2190 0.2030 0.2190) 20.0)
;; average time = 0.22345

All in all a draw, I would say.

Code used for changing blocks directly:
Code: [Select]
(defun attlay (/ a ent entl sset)
  (setq time (getvar "MILLISECS"))
  (cond ((setq sset (ssget "X" '((0 . "INSERT") (66 . 1))))
         (setq a 0)
         (repeat (sslength sset)
           (setq ent (ssname sset a)
                 a   (1+ a)
           )
           (and (getAttrib ent "*E")
                (setq entl (entget ent))
                (entmod (subst (cons 8 "0")(assoc 8 entl) entl))
           )
         )
        )
  )
  (timer time)
  (princ)
)

daron

  • Guest
Block select Lisp needed...
« Reply #24 on: August 27, 2004, 08:50:40 AM »
Cool, Stig. Mark, I just looked into what I was saying and it doesn't appear that you can separate the blocks through their space and search them out. At least not without some back door maneuvering, which would most likely take longer. Bummer.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #25 on: August 27, 2004, 08:54:27 AM »
Here's what I get. (although remember I *AM* using the SS method as presented by Mr. Madsen)

Code: [Select]

Details;
1 block (block1) 3 attributes
10,000 insertions of block1.
2,500 contain the string ("E") in one on the attributes we are looking for.

SMadsen
Elapsed time: 3.1100 seconds

MThomas
Elapsed time: 2.1410 seconds
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Block select Lisp needed...
« Reply #26 on: August 27, 2004, 08:59:43 AM »
Quote from: Mark Thomas

Code: [Select]

SMadsen
Elapsed time: 3.1100 seconds

MThomas
Elapsed time: 2.1410 seconds

Is that mine with the COMMAND method or SUBST method?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #27 on: August 27, 2004, 09:09:34 AM »
>Is that mine with the COMMAND method or SUBST method?
command
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Block select Lisp needed...
« Reply #28 on: August 27, 2004, 09:11:17 AM »
Okie
Do you have a chance of running the latter method also?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Block select Lisp needed...
« Reply #29 on: August 27, 2004, 09:14:00 AM »
Yep, I'll be done in a sec.............
TheSwamp.org  (serving the CAD community since 2003)