Author Topic: Change Layer Property .. test  (Read 2608 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Change Layer Property .. test
« on: July 29, 2008, 08:04:01 PM »
I've been trying to snip a couple of milliseconds from a reasonably sized app ....

Here are some interesting speed comparative figures.

Code: [Select]
(BenchMark
  '((vla-put-layer (vlax-ename->vla-object (entlast)) pf:layer)
    ;;
    (vl-cmdf "CHANGE" "L" "" "Properties" "LA" pf:Layer "")
    ;;
    (command "CHANGE" "L" "" "Properties" "LA" pf:Layer "")
    ;;
    (progn (setq ed (entget (entlast))) (entmod (subst (cons 8 pf:layer) (assoc 8 ed) ed)))
    ;;
    (entmod (subst (cons 8 pf:layer) (assoc 8 (entget (entlast))) (entget (entlast))))
   )
)

Quote


Benchmarking [M.P. 2005] ..............Elapsed milliseconds for 2048 iteration(s)/ relative Timing :

    (COMMAND "CHANGE" "L" "" "Properties...).....15109 / 23.571 <slowest>
    (VL-CMDF "CHANGE" "L" "" "Properties...)......9093 / 14.1856
    (ENTMOD (SUBST (CONS 8 PF:LAYER) (AS...)......1235 / 1.9267
    (PROGN (SETQ ED (ENTGET (ENTLAST))) ...)......1188 / 1.8534
    (vla-put-Layer (vlax-ename->vla-obje...).......641 / 1 <fastest>

 


Hope this is a little insightfull and usefull.
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change Layer Property .. test
« Reply #1 on: July 29, 2008, 09:02:53 PM »
Even with selectionSets (up to a size :) ), the VLisp version holds its own ..


Code: [Select]
(BenchMark
  '(
    ;;
    (progn
     (setq index -1)
     (while
      (setq ent (ssname ss-test (setq index (1+ index))))
      (entmod (subst (cons 8 pf:layer) (assoc 8 (entget ent)) (entget ent)))
     )
    )
   ;;
    (progn (setq eindex -1)
           (repeat (sslength ss-test)
             (setq edata (entget (ssname ss-test (setq eindex (1+ eindex)))))
             (entmod (subst (cons 8 pf:layer) (assoc 8 edata) edata))
           )
    )   
    ;;
    (progn
     (setq aindex -1)
     (repeat
      (sslength ss-test)
      (vla-put-layer (vlax-ename->vla-object (ssname ss-test (setq aindex (1+ aindex)))) pf:layer)
     )
    )
    ;;
    (command "CHANGE" ss-test "" "Properties" "LA" pf:Layer "")
   )
)
Quote


Command: (setq ss-test (ssget))
Select objects: Specify opposite corner: 10 found

Benchmarking [M.P. 2005] .............Elapsed milliseconds for 1024 iteration(s)/ relative Timing :

    (COMMAND "CHANGE" SS-TEST "" "Proper...).....3437 / 3.7278 <slowest>
    (PROGN (SETQ INDEX -1) (WHILE (SETQ ...).....1203 / 1.3048
    (PROGN (SETQ EINDEX -1) (REPEAT (SSL...).....1094 / 1.1866
    (PROGN (SETQ AINDEX -1) (REPEAT (SSLE...)......922 / 1 <fastest>
 

Quote


Command: (setq ss-test (ssget))
Select objects: Specify opposite corner: 40 found

Benchmarking [M.P. 2005] ...........Elapsed milliseconds for 256 iteration(s)/ relative Timing :

    (COMMAND "CHANGE" SS-TEST "" "Proper...).....922 / 1.5522 <slowest>
    (PROGN (SETQ INDEX -1) (WHILE (SETQ ...).....781 / 1.3148
    (PROGN (SETQ EINDEX -1) (REPEAT (SSL...).....688 / 1.1582
    (PROGN (SETQ AINDEX -1) (REPEAT (SSLE...).....594 / 1 <fastest>

 


Quote


Command: (setq ss-test (ssget))
Select objects: Specify opposite corner: 100 found

Benchmarking [M.P. 2005] ..........Elapsed milliseconds for 128 iteration(s)/ relative Timing :

    (PROGN (SETQ INDEX -1) (WHILE (SETQ ...).....1313 / 1.4013 <slowest>
    (PROGN (SETQ EINDEX -1) (REPEAT (SSL...).....1141 / 1.2177
    (COMMAND "CHANGE" SS-TEST "" "Proper...).....1000 / 1.0672
    (PROGN (SETQ AINDEX -1) (REPEAT (SSL...)......937 / 1 <fastest>

   
« Last Edit: July 30, 2008, 08:30:17 AM by Kerry Brown »
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Change Layer Property .. test
« Reply #2 on: July 29, 2008, 09:31:15 PM »
Interesting, Thanks Kerry. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change Layer Property .. test
« Reply #3 on: July 29, 2008, 09:33:08 PM »
SO ....
this is (part of ) what I ended up with ..

Code: [Select]

    ;;-------------------------------------------------------
    ;;
    ;; Draw Bolt Hole Markers
    ;;
    (kdub:mark)
    (setq obj (vlax-invoke KGLOBAL:MODELSPACE
                           'addline
                           (setq tmpPt (list (* -0.5 p:thickness) p:pcd-rad 0.0))
                           (list (* 1.5 p:thickness) p:pcd-rad 0.0)
              )
    )
    (vla-put-layer obj pf:layer)
    (vla-put-color obj pf:holecolor)

    (setq obj (vla-copy obj))
    (vla-move obj
              (vlax-3d-point tmpPt)
              (vlax-3d-point (list (* -0.5 p:thickness) (- p:pcd-rad) 0.0))
    )

    ;;-------------------------------------------------------
    ;;
    ;; Draw Bore Hole section
    ;;
    (if NotBlind
      (progn (setq obj (vlax-invoke KGLOBAL:MODELSPACE
                                    'addline
                                    (setq tmpPt (list 0.0 p:centerhole-rad 0.0))
                                    (list (* 1.0 p:thickness) p:centerhole-rad 0.0)
                       )
             )
             (vla-put-layer obj pf:layer)
             (vla-put-color obj pf:HiddenColor)
             (vla-put-linetype obj pf:HiddenLType)
             (setq obj (vla-copy obj))
             (vla-move obj
                       (vlax-3d-point tmpPt)
                       (vlax-3d-point (list (* -0.5 p:thickness) (- p:centerhole-rad) 0.0))
             )
      )
    )
    (vl-cmdf "_.SELECT" ssOutline "_ADD" (kdub:catch) "")
    ;;
    ;;-------------------------------------------------------

« Last Edit: July 29, 2008, 09:54:27 PM by Kerry Brown »
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change Layer Property .. test
« Reply #4 on: July 29, 2008, 09:36:43 PM »

AND ..
just a note about this : (list (* 1.0 p:thickness) p:centerhole-rad 0.0)

The ActiveX Method won't accept an integer .. it wants a double
SO we need to use either (* 1.0 p:thickness) OR (float p:thickness) for the X ordinate
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change Layer Property .. test
« Reply #5 on: July 29, 2008, 09:38:28 PM »
Interesting, Thanks Kerry. 8-)

My pleasure Alan.
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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10666
Re: Change Layer Property .. test
« Reply #6 on: July 29, 2008, 09:48:07 PM »
*hmm* According to that VL is fastest.

Speaking of layer changing; I think i too have discovered something that might flip things around a bit. I havent had a chance to look into what I thought i noticed, but i plan to do some research when i get some free time. If I saw what i think i saw, it shoulnt really matter that much (not as much as my orig `tests') between VL and AL versions (`command' and `vl-cmdf' is out in my opinion).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change Layer Property .. test
« Reply #7 on: July 29, 2008, 09:52:02 PM »

I'd be interested in seeing your results John
.. but my testing shows the ActiveX VLisp blowing the  AutoLisp (entmod(Subst etc .. ) out of the water.
.... though I may have missed something :)
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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10666
Re: Change Layer Property .. test
« Reply #8 on: July 29, 2008, 09:59:32 PM »
Yeah your test is quite the read. VL is smoking.

When i said `flip things around' i should have expanded that out a bit more to explain that i think i might have to flip my thoughts a bit (my initial thoughts of entmod being a faster solution could be wrong).

Your test: only a 100 layer though right?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change Layer Property .. test
« Reply #9 on: July 29, 2008, 10:31:25 PM »
< snip >
Your test: only a 100 layer though right?

John,

I was really only interested in single ents and small selection sets [ say 25 ents]

for BIG selection sets the CHANGE command which accepts selection sets may be fastest.
« Last Edit: July 30, 2008, 08:29:57 AM by Kerry Brown »
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.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Change Layer Property .. test
« Reply #10 on: July 30, 2008, 01:23:04 PM »
maybe vla-put-Layer is faster, but trying it as a whole yields totally different results:
Code: [Select]
(setq KGLOBAL:MODELSPACE
       (vla-get-ModelSpace
(vla-get-ActiveDocument (vlax-get-acad-object))
       )
      p:thickness 1.0
      p:pcd-rad 1.0
      pf:layer "test"
      pf:holecolor 5
)
(defun test1 (/ obj)
  (setq obj (vlax-invoke
      KGLOBAL:MODELSPACE
      'addline
      (setq tmpPt (list (* -0.5 p:thickness) p:pcd-rad 0.0))
      (list (* 1.5 p:thickness) p:pcd-rad 0.0)
    )
  )
  (vla-put-layer obj pf:layer)
  (vla-put-color obj pf:holecolor)
)
(defun test2 (/)
  (entmake (list (cons 0 "LINE")
(list 10 (* -0.5 p:thickness) p:pcd-rad 0.0)
(list 11 (* 1.5 p:thickness) p:pcd-rad 0.0)
(cons 8 pf:layer)
(cons 62 pf:holecolor)
   )
  )
)
(benchmark '((test1) (test2)))
and keep in mind that we have to check whether layer "test" is present and create it if needed before issuing vla-put-Layer

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Change Layer Property .. test
« Reply #11 on: July 30, 2008, 01:46:03 PM »
I've been trying to snip a couple of milliseconds from a reasonably sized app ....

A few years ago we were complaining about how many minutes it took to open a drawing, or do this or do that.  Now we're talking about shaving milliseconds off a program.  It's funny how times have changed.   :-)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

JohnK

  • Administrator
  • Seagull
  • Posts: 10666
Re: Change Layer Property .. test
« Reply #12 on: July 30, 2008, 03:05:02 PM »
maybe vla-put-Layer is faster, but trying it as a whole yields totally different results:
<snip>
and keep in mind that we have to check whether layer "test" is present and create it if needed before issuing vla-put-Layer

Nothing ive done in VL could approach the speed of entmake, but im starting to think that VL can be faster then entmod.

Checking the layers existance; that is where you can use the speed of entmake.

Lets work out an agreed upon test senerio (or several) and code each method (a VL and a AL version).

For example:

Criteria:
        1. 100 layers
            -e.g.       
            ((0 . "LAYER") (2 . "1") (70 . 0) (62 . 1) (6 . "Continuous"))
            ((0 . "LAYER") (2 . "2") (70 . 0) (62 . 2) (6 . "Continuous"))
            ((0 . "LAYER") (2 . "3") (70 . 0) (62 . 3) (6 . "Continuous"))
            ((0 . "LAYER") (2 . "4") (70 . 0) (62 . 4) (6 . "Continuous"))
            ...
        2. No user interaction so timing can be done right away.

Synopsis:
        1. Create a 100 lines (they can be ontop of eachother, that
           part inst important).each line is to be on its own layer.

Senerios:
        1. Create the layers then create the lines then change line
           props to be on proper layer.
        2. Create layers then create lines with the proper layer
           props.
        3. create the lines, then create the layers and itterate thru
           the lines to modify each ones props to be on the proper
           layer.

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org