Comando: (length (ALE_GetTableNames "LAYER")) >>> 407
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 128 iteration(s):
(CMDF_LAYERON)......1763 / 8.57 <fastest>
(ALE_LAYERON)......15101 / 1 <slowest>
Elapsed milliseconds / relative speed for 64 iteration(s):
(CMDF_LAYERON).....1685 / 3.08 <fastest>
(ALE_LAYERON)......5195 / 1 <slowest>
Elapsed milliseconds / relative speed for 64 iteration(s):
(CMDF_LAYERON).....1653 / 4.62 <fastest>
(ALE_LAYERON)......7629 / 1 <slowest>
lapsed milliseconds / relative speed for 128 iteration(s):
(CMDF_LAYERON)......1981 / 6.51 <fastest>
(CMDF_LAYERON)......2637 / 4.89
(CMDF_LAYERON)......3073 / 4.2
(ALE_LAYERON).......9375 / 1.38
(ALE_LAYERON)......11793 / 1.09
(ALE_LAYERON)......12902 / 1 <slowest>
(defun cmdf_LayerON ( )
(vl-cmdf "_.layer" "_Off" "*$???_*" "_Y" "")
(vl-cmdf "_.layer" "_ON" "*$???_*" "")
)
(defun ALE_LayerON ( )
(ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_ON" . "*$???_*")))
(ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_Off" . "*$???_*")))
)
; Function: ALE_Layer_PutOnAll
;
; Version 1.00 - 16/11/2006
; Description:
; Put Layers On or Off
;
; Arguments:
; VlaDoc: IAcadDocument: An AutoCAD drawing or IAxDbDocument: Interface
; LrsCol: Layer Collection
; ChgLst: list of dotted pairs Layers commands and names in reverse order
; (used reverse order because I use cons to build the list rather than append), example:
; (("_OFF" . "*_Abc*") ("_ON" . "*Com_*") ("_ON" . "~*$*") ("_ON" . "*Xyz_*") ("_OFF" . "*|$*,$*"))
; first element = command > "_ON" or "_OFF" case insensitive
; second element = layers names > see WcMatch case insensitive
;
; Examples:
; (or *AcadApp* (setq *AcadApp* (vlax-get-Acad-Object) ))
; (or *AcAcDwg* (setq *AcAcDwg* (vla-get-ActiveDocument *AcadApp*)))
; (or *AcLayrs* (setq *AcLayrs* (vla-get-Layers *AcAcDwg*)))
;
; (ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_OFF" . "*_Abc*") ("_ON" . "*Com_*")))
; ==> On Layers "*COM_*" than Off Layers "*_ABC*"
;
; (ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_ON" . "*")))
; ==> On all layers
;
; Return Values: VLA-OBJECT IAcadLayers
;
(defun ALE_Layer_PutOnAll (VlaDoc LrsCol ChgLst / LyrNam BitVal)
(setq ChgLst (reverse (read (strcase (vl-prin1-to-string ChgLst)))))
(vlax-map-Collection
LrsCol
'(lambda (LmbDat)
(setq
BitVal nil
LyrNam (strcase (vla-get-Name LmbDat))
)
(foreach ForElm ChgLst
(if (wcmatch LyrNam (cdr ForElm))
(if (= (car ForElm) "_ON") (setq BitVal 1) (setq BitVal 0))
)
)
(and
BitVal
(if (zerop BitVal)
(vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-false))
(vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-true ))
)
)
)
)
)
Hello Kerry! :-)
Publish here an example of your file for testing.
I have a lot of different codes for solving the problem,
but never did serious research.
I'm curious!
:-D
.. and the bonus is the command does not require a regen of the viewport.
Has anyone come across a code solution that is faster than vl-cmdf or command-s for handling complex wildcard nominations.
The command method is actually reasonably fast, but I want to satisfy due diligence.
@ Marc'Antonio Alessi:It is to avoid problems when I process many files, I think the difference is very small:
Maybe the vl-catch-all-apply stucture is slowing things down? I am not sure why you use it.
Elapsed milliseconds / relative speed for 256 iteration(s):
(CMDF_LAYERON)......2122 / 5.77 <fastest>
(ALE_LAYERON2).....11606 / 1.06
(ALE_LAYERON)......12246 / 1 <slowest>
Elapsed milliseconds / relative speed for 256 iteration(s):
(CMDF_LAYERON)......2012 / 7.75 <fastest>
(ALE_LAYERON)......12855 / 1.21
(ALE_LAYERON2).....15600 / 1 <slowest>
(defun ALE_Layer_PutOnAll2 (VlaDoc LrsCol ChgLst / LyrNam BitVal)
(setq ChgLst (reverse (read (strcase (vl-prin1-to-string ChgLst)))))
(vlax-map-Collection
LrsCol
'(lambda (LmbDat)
(setq
BitVal nil
LyrNam (strcase (vla-get-Name LmbDat))
)
(foreach ForElm ChgLst
(if (wcmatch LyrNam (cdr ForElm))
(if (= (car ForElm) "_ON") (setq BitVal 1) (setq BitVal 0))
)
)
(and
BitVal
(if (zerop BitVal)
(vla-put-LayerOn LmbDat :vlax-false)
(vla-put-LayerOn LmbDat :vlax-true)
)
)
)
)
)
Here is my sample.
(defun _ThawLayers ( filter invert_filter / @Match @Main )
;; Thaw and turn on layers that match the filter,
;; otherwise freeze and turn off, with special
;; treatment of layer "0" and "Defpoints".
;;
;; Syntax:
;;
;; Thaw layers matching the filter:
;;
;; (_ThawLayers "*support*,*e" nil)
;;
;; Thaw layers NOT matching the filter (read another
;; way -- freeze layers matching the filter):
;;
;; (_thawlayers "*weld*,*gaskets*,*bolts*" t)
(vl-load-com)
(if invert_filter
(defun @Match ( x ) (not (wcmatch x filter))) ;; filter is a
(defun @Match ( x ) (wcmatch x filter)) ;; lexical global
)
(defun @Main ( doc filter clayer / name off frozen)
;; group existing states etc ...
(vlax-for layer (vla-get-layers doc)
(cond
( (eq clayer
(setq
off (eq :vlax-false (vla-get-layeron layer))
frozen (eq :vlax-true (vla-get-freeze layer))
name (strcase (vla-get-name layer))
)
)
(if (@Match name)
;; you can only feck the on state
;; for the active layer -- try to
;; change the freeze state and kaboom
(vla-put-layeron layer :vlax-true)
)
)
( (member name '("0" "DEFPOINTS"))
(vla-put-freeze layer :vlax-false)
(vla-put-layeron layer :vlax-true)
)
( off
(if frozen
(if (@Match name)
(progn
(vla-put-layeron layer :vlax-true)
(vla-put-freeze layer :vlax-false)
)
)
(if (@Match name)
(vla-put-layeron layer :vlax-true)
(vla-put-freeze layer :vlax-true)
)
)
)
( (if frozen
(if (@Match name)
(vla-put-freeze layer :vlax-false)
(vla-put-layeron layer :vlax-false)
)
(if (not (@Match name))
(progn
(vla-put-layeron layer :vlax-false)
(vla-put-freeze layer :vlax-true)
)
)
)
)
)
)
(princ)
)
(@Main
(vla-get-activedocument (vlax-get-acad-object))
(strcase filter)
(strcase (getvar 'clayer))
)
)
Thanks Michael,
I'll test it tonight, but from first glance that looks functionally equivalent to my ActiveX effort
... though mine is not as pretty :-) .. and not as artistically documented
Regards,
(defun ALE_LayerON_Transaction ( )
(vle-start-transaction)
(ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_ON" . "*$???_*")))
(ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_Off" . "*$???_*")))
(vle-end-transaction)
)
Benchmarking .......... elapsed milliseconds / relative timing <64 iterations>
(CMDF_LAYERON) ................ 1484 / 1.32 <fastest>
(ALE_LAYERON_TRANSACTION) ..... 1766 / 1.11
(ALE_LAYERON) ................. 1953 / 1.00 <slowest>
(defun _ThawLayers_MP ( )
(_ThawLayers '("*$???_*") nil)
(_ThawLayers '("*$???_*") T)
)
Elapsed milliseconds / relative speed for 256 iteration(s):
(CMDF_LAYERON)........1373 / 30.4 <fastest>
(ALE_LAYERON)........20530 / 2.03
(_THAWLAYERS_MP).....41746 / 1 <slowest>
Bricscad V15 DWG with 3 layers: 0 $LAY_NORM Defpoints
Elapsed milliseconds / relative speed for 8192 iteration(s):
(ALE_LAYERON).........1186 / 15.46 <fastest>
(_THAWLAYERS_MP)......1809 / 10.13
(CMDF_LAYERON).......18330 / 1 <slowest>
Bricscad V15 All_Layers.dwg:
Elapsed milliseconds / relative speed for 64 iteration(s):
(ALE_LAYERON)....................1778 / 2.77 <fastest>
(ALE_LAYERON_TRANSACTION)........2465 / 2
(CMDF_LAYERON)...................3167 / 1.56
(_THAWLAYERS_MP).................3307 / 1.49
(_THAWLAYERS_MP_TRANSACTION).....4930 / 1 <slowest>
Bricscad V15 All_Layers.dwg 2° round:
Elapsed milliseconds / relative speed for 32 iteration(s):
(ALE_LAYERON)....................1077 / 3.56 <fastest>
(CMDF_LAYERON)...................1326 / 2.89
(_THAWLAYERS_MP_TRANSACTION).....1747 / 2.2
(ALE_LAYERON_TRANSACTION)........3089 / 1.24
(_THAWLAYERS_MP).................3837 / 1 <slowest>
AutoCAD 2013, maybe this is not the right comparison:Code: [Select](defun _ThawLayers_MP ( )
(_ThawLayers '("*$???_*") nil)
(_ThawLayers '("*$???_*") T)
)
(defun _ThawLayers_MP ( )
(_ThawLayers "*$???_*" nil)
)
stange behaviour on my All_layers.dwg:
(_ThawLayers '("$???_*") t) => do not freeze "$FDT_NORM"
I need to Freeze / thaw layers depending on wildcard matches (multiple combinations of course).
There are about 40 wildcard matches that have to be satisfied.
Can you write an equivalent of:AutoCAD 2013, maybe this is not the right comparison:Code: [Select](defun _ThawLayers_MP ( )
(_ThawLayers '("*$???_*") nil)
(_ThawLayers '("*$???_*") T)
)
Ummm not quite.Code: [Select](defun _ThawLayers_MP ( )
(_ThawLayers "*$???_*" nil)
)
Curious why you called the function twice.
I gave the insert_filters options because it's often difficult to achieve some filtering otherwise.
For example if you want to freeze the *gasket* and *weld* layers via a thaw function you might think a (wcmatch string "~*gasket*,~*weld*") filter might work, but it will not, where as (not (wcmatch string "*gasket*,*weld*")) will, ergo the invert_filters flag. Guess my in code comments weren't clear enough. Will try to revise latr if I find time.
I changed mine. I had made it an option to pass a list of filters. I did this because I read:OK, now I understand, my function "OFF" also the current layer, while yours not freeze the layer if it is current.I need to Freeze / thaw layers depending on wildcard matches (multiple combinations of course).
There are about 40 wildcard matches that have to be satisfied.
But no one else appears to be using lists and I'm paying a performance hit for the option, so now it merely a single match string.
I did leave in the invert_filter flag as I think it's quite useful in real world use -- I often have to freeze only welds, gaskets etc.
Cheers.
Roy,
That's an interesting test result for BricsCAD.
I'll fire up and have a play in V15 when I beat this one to death.
It leads me to wonder about the relative actual speed comparison between drawing engines.
Roy,
That's an interesting test result for BricsCAD.
I'll fire up and have a play in V15 when I beat this one to death.
It leads me to wonder about the relative actual speed comparison between drawing engines.
Hi Kerry,
just watching from afar when I noticed this comment.
As I understand it the guys at Bricscad have highly optimised their lisp engine and as lisp is required to work on Linux versions they have even gone as far as bypassing the COM calls (vl- ??) straight to native which may explain the smaller differences in speed.
cheers.
An in-pp programming editor and debugger would be really nice though :-)
Roy,My testing was done with BricsCAD V14. Comparing V14 and V15 seems to show two things. First: (in this situation?) V15 Lisp execution is noticeably slower. Second: using a transaction (vle-start-transaction and vle-end-transaction) probably does not have any speed benefits. This is contrary to my earlier statement.
That's an interesting test result for BricsCAD.
I'll fire up and have a play in V15 when I beat this one to death.
V15
Benchmarking .......... elapsed milliseconds / relative timing <64 iterations>
(ALE_LayerOFFON_NOCATCH) ................. 2579 / 1.62 <fastest>
(ALE_LayerOFFON) ......................... 2812 / 1.48
(cmdf_LayerOFFON) ........................ 3031 / 1.38
(ALE_LayerOFFON_TRANSACTION_NOCATCH) ..... 4079 / 1.02
(ALE_LayerOFFON_TRANSACTION) ............. 4171 / 1.00 <slowest>
V14
Benchmarking .......... elapsed milliseconds / relative timing <64 iterations>
(cmdf_LayerOFFON) ........................ 1313 / 1.54 <fastest>
(ALE_LayerOFFON_NOCATCH) ................. 1781 / 1.13
(ALE_LayerOFFON_TRANSACTION_NOCATCH) ..... 1906 / 1.06
(ALE_LayerOFFON) ......................... 1984 / 1.02
(ALE_LayerOFFON_TRANSACTION) ............. 2016 / 1.00 <slowest>
(or *AcadApp* (setq *AcadApp* (vlax-get-Acad-Object) ))
(or *AcAcDwg* (setq *AcAcDwg* (vla-get-ActiveDocument *AcadApp*)))
(or *AcLayrs* (setq *AcLayrs* (vla-get-Layers *AcAcDwg*)))
(defun cmdf_LayerOFFON ( )
(setvar 'cmdecho 0) ; Slightly faster.
(vl-cmdf "_.layer" "_Off" "*$???_*" "_Y" "")
(vl-cmdf "_.layer" "_ON" "*$???_*" "")
(setvar 'cmdecho 1)
)
(defun ALE_LayerOFFON ( )
(ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_Off" . "*$???_*")))
(ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_ON" . "*$???_*")))
)
(defun ALE_LayerOFFON_NoCatch ( )
(ALE_Layer_PutOnAll_NoCatch *AcAcDwg* *AcLayrs* '(("_Off" . "*$???_*")))
(ALE_Layer_PutOnAll_NoCatch *AcAcDwg* *AcLayrs* '(("_ON" . "*$???_*")))
)
(defun ALE_LayerOFFON_Transaction ( )
(vle-start-transaction)
(ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_Off" . "*$???_*")))
(ALE_Layer_PutOnAll *AcAcDwg* *AcLayrs* '(("_ON" . "*$???_*")))
(vle-end-transaction)
)
(defun ALE_LayerOFFON_Transaction_NoCatch ( )
(vle-start-transaction)
(ALE_Layer_PutOnAll_NoCatch *AcAcDwg* *AcLayrs* '(("_Off" . "*$???_*")))
(ALE_Layer_PutOnAll_NoCatch *AcAcDwg* *AcLayrs* '(("_ON" . "*$???_*")))
(vle-end-transaction)
)
(defun ALE_Layer_OnAndThawTest ( / ChgLst LyrNam BitVal)
(setq
ChgLst '(("_OFF" . "~0") ("_ON" . "$XP*,*HIDDEN*") ("_ON" . "$SDT*")("_ON" . "Defpoints"))
)
(vlax-map-Collection
*aclayers
'(lambda (LmbDat)
(setq
BitVal nil
LyrNam (strcase (vla-get-Name LmbDat))
)
(foreach ForElm ChgLst
(if (wcmatch LyrNam (cdr ForElm))
(if (= (car ForElm) "_ON") (setq BitVal 1) (setq BitVal 0))
)
)
(and
BitVal
(if (zerop BitVal)
(progn
(vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-false))
(vl-catch-all-apply 'vla-put-freeze (list LmbDat :vlax-true))
)
(progn
(vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-true ))
(vl-catch-all-apply 'vla-put-freeze (list LmbDat :vlax-false))
)
)
)
)
)
(vla-put-activelayer *acdoc (vla-item *aclayers "0"))
)
(LAYERONANDTHAWTEST-CMD)......1809 / 2.94 <fastest>
(ALE_LAYER_ONANDTHAWTEST).....4821 / 1.1
(LAYERONANDTHAWTEST-AX).......5319 / 1 <slowest>
Elapsed milliseconds / relative speed for 32 iteration(s):
(ALE_LAYER_ONANDTHAWTEST).....1310 / 2.08 <fastest>
(LAYERONANDTHAWTEST-AX).......1997 / 1.37
(ALE_LAYER_ONANDTHAWTEST).....2059 / 1.33
(ALE_LAYER_ONANDTHAWTEST).....2246 / 1.22
(LAYERONANDTHAWTEST-AX).......2683 / 1.02
(LAYERONANDTHAWTEST-AX).......2730 / 1 <slowest>
Is is very similar, maybe Vlax-map-Collection is a little bit faster...
Is is very similar, maybe Vlax-map-Collection is a little bit faster...
(defun ALE_Layer_OnAndThawTest2 ( / ChgLst LyrNam BitVal)
(setq ChgLst '((0 . "~0") (1 . "$XP*,*HIDDEN*,$SDT*,Defpoints")))
(vlax-map-Collection
*aclayers
'(lambda (LmbDat)
(setq BitVal nil LyrNam (strcase (vla-get-Name LmbDat)))
(foreach ForElm ChgLst
(if (wcmatch LyrNam (cdr ForElm))
(if (zerop (car ForElm)) (setq BitVal 0) (setq BitVal 1))
)
)
(and
BitVal
(if (zerop BitVal)
(progn
(vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-false))
(vl-catch-all-apply 'vla-put-freeze (list LmbDat :vlax-true))
)
(progn
(vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-true ))
(vl-catch-all-apply 'vla-put-freeze (list LmbDat :vlax-false))
)
)
)
)
)
(vla-put-activelayer *acdoc (vla-item *aclayers "0"))
)
Elapsed milliseconds / relative speed for 32 iteration(s):
(ALE_LAYER_ONANDTHAWTEST2).....1872 / 2.72 <fastest>
(LAYERONANDTHAWTEST-AX)........2386 / 2.14
(ALE_LAYER_ONANDTHAWTEST2).....3057 / 1.67
(ALE_LAYER_ONANDTHAWTEST2).....3338 / 1.53
(LAYERONANDTHAWTEST-AX)........4898 / 1.04
(LAYERONANDTHAWTEST-AX)........5101 / 1 <slowest>
; Now I scraped the barrel (my apologies for transl.)
(defun ALE_Layer_OnAndThawTest3 ( / ChgLst LyrNam BitVal)
(setq ChgLst '((0 . "~0") (1 . "$XP*,*HIDDEN*,$SDT*,Defpoints")))
(vlax-map-Collection
*aclayers
'(lambda (LmbDat)
(setq BitVal nil LyrNam (strcase (vla-get-Name LmbDat)))
(foreach ForElm ChgLst
(if (wcmatch LyrNam (cdr ForElm))
(and (wcmatch LyrNam (cdr ForElm)) (setq BitVal (car ForElm)))
)
)
(and
BitVal
(if (zerop BitVal)
(progn
(or
(= (vla-get-LayerOn LmbDat) ':vlax-false)
(vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-false))
)
(or
(= (vla-get-Freeze LmbDat) ':vlax-true)
(vl-catch-all-apply 'vla-put-freeze (list LmbDat :vlax-true))
)
)
(progn
(or
(= (vla-get-LayerOn LmbDat) ':vlax-true)
(vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-true))
)
(or
(= (vla-get-Freeze LmbDat) ':vlax-false)
(vl-catch-all-apply 'vla-put-Freeze (list LmbDat :vlax-false))
)
)
)
)
)
)
(vla-put-activelayer *acdoc (vla-item *aclayers "0"))
)
Elapsed milliseconds / relative speed for 64 iteration(s):
(ALE_LAYER_ONANDTHAWTEST3).....1544 / 6.33 <fastest>
(ALE_LAYER_ONANDTHAWTEST3).....1716 / 5.69
(ALE_LAYER_ONANDTHAWTEST3).....4024 / 2.43
(LAYERONANDTHAWTEST-AX)........5850 / 1.67
(LAYERONANDTHAWTEST-AX)........6490 / 1.5
(LAYERONANDTHAWTEST-AX)........9766 / 1 <slowest>
How about just :Yes... 8) old age puts you sunglasses... updated.Code - Auto/Visual Lisp: [Select]
(defun LayerOnAndThawTest-ax (/ thawList LayerZero layName)
(setq thawList '("$XP*,*HIDDEN*" "$SDT*" "Defpoints"))
(command-s "_.layer" "_On" "*" "_t" "*" "")
...
)
(defun ALE_Layer_OnAndThawTest(n) ( / ChgLst LyrNam BitVal)
(setq ChgLst '((0 . "~0") (1 . "$XP*,*HIDDEN*,$SDT*,Defpoints")))
(command-s "_.layer" "_On" "*" "_t" "*" "")
...
)
(defun LayerOnAndThawTest-cmd (/ thawList)
(setq thawList (_listitems->string
'("$XP*,*HIDDEN*" "$SDT*" "Defpoints")
","
)
)
(command-s "_.layer" "_On" "*" "_t" "*" "_S" "0" "_Freeze" "*" "_On" thawList "_T" thawList "")
(princ)
)
(LAYERONANDTHAWTEST-CMD).......1060 / 4.22 <fastest>
(ALE_LAYER_ONANDTHAWTEST)......1935 / 2.31
(ALE_LAYER_ONANDTHAWTEST3).....3432 / 1.3
(LAYERONANDTHAWTEST-AX)........4477 / 1 <slowest>
< .. >
Yes... 8) old age puts you sunglasses... updated.
I am very very close ... :( ............ ;D< .. >
Yes... 8) old age puts you sunglasses... updated.
I survived the 60's ... so everything is rose tinted for me .