Author Topic: Freezing/Thawing Layers by Wildcard Match.  (Read 12740 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #15 on: November 11, 2014, 08:20:45 AM »
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #16 on: November 11, 2014, 08:36:12 AM »
stange behaviour on my All_layers.dwg:
 (_ThawLayers '("$???_*") t) => do not freeze "$FDT_NORM"

Shrug, works on my machine.

(_ThawLayers "$???_*") nil) >> Layers "0", "DEFPOINTS" and "$FDT_NORM" on & thawed, all others off & frozen.
(_ThawLayers "$???_*")   t) >> Layer "$FDT_NORM" off & frozen, all others on & thawed.

Works precisely as I intended.

Edit: That said, maybe my intention isn't clear. Apologies -- revising code comments to reflect.
« Last Edit: November 11, 2014, 08:59:35 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #17 on: November 11, 2014, 08:51:46 AM »
I changed mine. I had made it an option to pass a list of filters. I did this because I read:

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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #18 on: November 11, 2014, 09:01:02 AM »
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.
Can you write an equivalent of:
(defun cmdf_LayerON ( )
 (vl-cmdf "_.layer" "_Off" "*$???_*" "_Y" "")
 (vl-cmdf "_.layer" "_ON" "*$???_*" "")
)
to test?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #19 on: November 11, 2014, 09:05:50 AM »
I changed mine. I had made it an option to pass a list of filters. I did this because I read:

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.
OK, now I understand, my function "OFF" also the current layer, while yours not freeze the layer if it is current.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #20 on: November 11, 2014, 09:55:39 AM »
Just a quick note ... I'm late for bed.

Thanks for the input so far.


@Blackbox, you asked for the C# ... see attached. It's a little rough.

This test is pretty self explanatory.
and uses  Marc'Antonio's drawing.
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (setvar 'CMDecho 0 )
  3. (BenchMark2 50 '(
  4.                 (command-s "_.layer" "_S" "0" "_t" "*" "")
  5.                 (command-s "_.layer" "_T" "$XP*,*HIDDEN*,$SDT*" "")
  6.                 (command-s "_.layer" "_t" "$WST*,$$DT*" "")
  7.                 (command-s "_.layer" "_t" "*" "")
  8. ;; C# called from Lisp
  9.                 (MyLispFunction (list "$XP*" "*HIDDEN*" "$SDT*"))
  10.                 (MyLispFunction (list "$WST*" "$$DT*"))                  
  11.   )
  12. )
  13. (setvar 'CMDecho 1 )
  14.  

Results :
Benchmarking-V2 :B=50 [M.P.2005 <revised kdub 2005,2014>] ...........
Elapsed milliseconds for 256 iteration(s)/ relative Timing :

    (mylispfunction (LIST "$XP*" "*HIDDE...).....3338 / 30.6239 <slowest>
    (mylispfunction (LIST "$WST*" "$$DT*"))......2246 / 20.6055
    (COMMAND-S "_.layer" "_S" "0" "_t" "...)......249 / 2.2844
    (COMMAND-S "_.layer" "_t" "*" "").............203 / 1.8624
    (COMMAND-S "_.layer" "_T" "$XP*,*HID...)......187 / 1.7156
    (COMMAND-S "_.layer" "_t" "$WST*,$$D...)......109 / 1.0000 <fastest> : 0.425781250000ms Per iteration



Code - C#: [Select]
  1. // (C) Copyright 2014 by  kdub Services
  2. //
  3.  
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Linq.Expressions;
  9. using System.Windows.Documents;
  10. using Autodesk.AutoCAD.Runtime;
  11. using Autodesk.AutoCAD.ApplicationServices;
  12. using Autodesk.AutoCAD.DatabaseServices;
  13. using Autodesk.AutoCAD.Geometry;
  14. using Autodesk.AutoCAD.EditorInput;
  15. //
  16. using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
  17. using Exception = System.Exception;
  18.  
  19. [assembly: CommandClass(typeof (LayerToggle_03.LayerToggle))]
  20.  
  21. namespace LayerToggle_03
  22. {
  23.     public class LayerToggle
  24.     {
  25.         [CommandMethod("MyGroup", "MyCommand", "MyCommandLocal",
  26.             CommandFlags.Modal)]
  27.         public static void LayerToggle3()
  28.         {
  29.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  30.             Database db = Application.DocumentManager.MdiActiveDocument.Database;
  31.  
  32.             ed.WriteMessage("Hello, this Hal.");
  33.  
  34.             List<string> patternList = new List<string>();
  35.             patternList.Add("STH*");
  36.             patternList.Add("??5*");
  37.  
  38.             ThawtoMatchPattern(db, patternList);
  39.         }
  40.  
  41.         public static void ThawtoMatchPattern(
  42.             Database db,
  43.             List<string> patternList)
  44.         {
  45.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  46.  
  47.             using (Transaction tr = db.TransactionManager.StartTransaction())
  48.             {
  49.                 LayerTable lt =
  50.                     (LayerTable) tr.GetObject(db.LayerTableId, OpenMode.ForRead);
  51.                 var currentLayeriD = db.Clayer;
  52.  
  53.                 foreach (ObjectId obID in lt)
  54.                 {
  55.                     LayerTableRecord ltr =
  56.                         (LayerTableRecord) tr.GetObject(obID, OpenMode.ForWrite);
  57.                     foreach (var pattern in patternList)
  58.                     {
  59.                         var layerName = ltr.Name;
  60.                         if (layerName.Matches(pattern)
  61.                             &&
  62.                             ltr.IsFrozen)
  63.                         {
  64.                             ltr.IsOff = false;
  65.                             ltr.IsFrozen = false;
  66.                             //break;
  67.                             continue;
  68.                         }
  69.                         else
  70.                         {
  71.                             if (!obID.Equals(currentLayeriD)
  72.                                 ||
  73.                                 layerName != "Defpoints")
  74.                             {
  75.                                 ltr.IsFrozen = true;
  76.                             }
  77.                         }
  78.                     }
  79.                 }
  80.                 tr.Commit();
  81.             }
  82.         }
  83.  
  84.         [LispFunction("MyLispFunction", "MyLispFunctionLocal")]
  85.         public int MyLispFunction(ResultBuffer pArgs)
  86.         {
  87.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  88.             Database db = Application.DocumentManager.MdiActiveDocument.Database;
  89.             try
  90.             {
  91.                 List<string> patternList = (from TypedValue typedValue in pArgs
  92.                                             where
  93.                                                 (LispDataType)
  94.                                                 typedValue.TypeCode ==
  95.                                                 LispDataType.Text
  96.                                             select typedValue.Value.ToString())
  97.                     .ToList();
  98.  
  99.                 ThawtoMatchPattern(db, patternList);
  100.                 ed.Regen();
  101.             }
  102.             catch (System.Exception ex)
  103.             {
  104.                 ed.WriteMessage(
  105.                                 "\nError: {0}\nStackTrace: {1}",
  106.                                 ex.Message,
  107.                                 ex.StackTrace);
  108.             }
  109.             return 1;
  110.         }
  111.     }
  112. }
  113.  

Code - C#: [Select]
  1.  
  2. namespace LayerToggle_03
  3. {
  4.     public static class WcMatchExtensionMethods
  5.     {
  6.         // Thanks to Tony T
  7.         //
  8.         public static bool Matches(
  9.             this string str,
  10.             string pattern,
  11.             bool ignoreCase)
  12.         {
  13.             return Autodesk.AutoCAD.Internal.Utils.WcMatchEx(str, pattern, ignoreCase);
  14.         }
  15.  
  16.         public static bool Matches(this string str, string pattern)
  17.         {
  18.             return Autodesk.AutoCAD.Internal.Utils.WcMatchEx(str, pattern, true);
  19.         }
  20.     }
  21. }
  22.  


modification required to code:
original post changed.
Changed break to continue

Code - C#: [Select]
  1.  
  2.                         if (layerName.Matches(pattern)
  3.                             &&
  4.                             ltr.IsFrozen)
  5.                         {
  6.                             ltr.IsOff = false;
  7.                             ltr.IsFrozen = false;
  8.                             // break;
  9.                             continue;
  10.                         }
  11.                         else
  12.                         {
  13.                             if (!obID.Equals(currentLayeriD)
  14.                                 ||
  15.                                 layerName != "Defpoints")
  16.                             {
  17.                                 ltr.IsFrozen = true;
  18.                             }
  19.                         }
  20.  
  21.  
« Last Edit: November 11, 2014, 08:56:26 PM by Kerry »
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: Freezing/Thawing Layers by Wildcard Match.
« Reply #21 on: November 11, 2014, 08:50:27 PM »
Regarding the parameters :
I'm not fussed if it's a list of strings or a comma separated string.

My parameters are built from dialog input to define the "Layer Groups" status.
... mainly to target Layers in Xrefs .. which can get fairly complicated.

//--------------------------

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.

//--------------------------

Just an aside:
I was originally going to do this app in C#.
My prototyping and proof of concept work was done in VisualLisp.
When I noticed how slow the C# process was due to the restrictions caused by Wildcard requirement I went back to VisualLisp and OpenDCL.

Thankfully, I have a couple of toolboxes and a client who just wants it to work, and be reasonably fast.

Thanks for the input.
Regards,


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.

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #22 on: November 11, 2014, 10:15:11 PM »

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.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #23 on: November 11, 2014, 10:28:12 PM »

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.

Hi Mick,
Yes, I believe your optimisation comment is correct. It's developing into a very neat application.

I think Torsten Moses has a lot to be proud of.

An in-app programming editor and debugger would be really nice though :-)
« Last Edit: November 11, 2014, 11:00:54 PM by Kerry »
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.

danallen

  • Guest
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #24 on: November 11, 2014, 10:38:48 PM »
An in-pp programming editor and debugger would be really nice though :-)

+1

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #25 on: November 12, 2014, 03:42:18 AM »
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.
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.
Note: for this test I have modified Marc'Antonio's *ON functions. They did not all have the off-on order.

Code: [Select]
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>

Code: [Select]
(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)
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #26 on: November 14, 2014, 12:00:54 AM »
These were my Command and ActiveX tests.

Code - Auto/Visual Lisp: [Select]
  1. (defun LayerOnAndThawTest-ax (/ thawList LayerZero layName)
  2.   (setq thawList '("$XP*,*HIDDEN*" "$SDT*" "Defpoints"))
  3.  
  4.   ;; Ensure Layer '0 is ON, THAWED and ACTIVE (CurrentLayer)
  5.   (setq LayerZero (vla-item *aclayers "0"))
  6.   (vla-put-layeron LayerZero :vlax-true)
  7.   (if (= :vlax-true (vla-get-freeze LayerZero))
  8.     (vla-put-freeze LayerZero :vlax-false)
  9.   )
  10.   (vla-put-activelayer *acdoc LayerZero)
  11.  
  12.   ;; Turn OFF and FREEZE layers except those nominated
  13.   (vlax-for layObj *aclayers
  14.     (setq layName (vla-get-name layObj))
  15.     (if (not (equal LayerZero layObj))
  16.       (if (vl-some '(lambda (pattern) (wcmatch layName pattern)) thawList)
  17.         (progn (vla-put-layeron layObj :vlax-true)
  18.                (vla-put-freeze layObj :vlax-false)
  19.         )
  20.         (progn (vla-put-layeron layObj :vlax-false)
  21.                (vla-put-freeze layObj :vlax-true)
  22.         )
  23.       )
  24.     )
  25.   )
  26.   (princ)
  27. )
  28.  

Code - Auto/Visual Lisp: [Select]
  1. (defun LayerOnAndThawTest-cmd (/ thawList)
  2.   (setq thawList (_listitems->string
  3.                    '("$XP*,*HIDDEN*" "$SDT*" "Defpoints")
  4.                    ","
  5.                  )
  6.   )
  7.  
  8.   (command-s "_.layer" "_On" "0" "_t" "0" "_S" "0" "Freeze" "*" "")
  9.   (command-s "_.layer" "_On" thawList "_T" thawList "")
  10.   (princ)
  11. )
  12.  
  13. ;;//---------------------------------------  
  14. (defun _listitems->string (lst delimiter / result)
  15.   (setq result (car lst))
  16.   (foreach item (cdr lst) (setq result (strcat result delimiter item)))
  17.   result
  18. )
  19.  

Code - Auto/Visual Lisp: [Select]
  1.       *aclayers (vla-get-layers *acdoc)
  2. )
  3. (setvar 'REGENMODE 1)
  4. (command-s "_.layer" "_On" "*" "_t" "*" "_S" "0" "")
  5.  
  6. (setvar 'CMDecho 0)
  7. (BenchMark2
  8.   200
  9.   '((LayerOnAndThawTest-cmd)
  10.     (LayerOnAndThawTest-ax)  
  11.    )
  12. )
  13. (setvar 'CMDecho 1)
  14.  

Benchmarking-V2 :B=200 [M.P.2005 <revised kdub 2005,2014>] ........
Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (LAYERONANDTHAWTEST-AX)......1669 / 5.9395 <slowest>: 52.15625ms Per iteration
    (LAYERONANDTHAWTEST-CMD)......281 / 1 <fastest>: 8.78125ms Per iteration
« Last Edit: November 14, 2014, 12:06:48 AM by Kerry »
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.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #27 on: November 14, 2014, 06:12:02 AM »
@Kerry: I have modified the function to do exactly what do yours (AutoCAD 2013):
Code: [Select]
(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"))
)
Code: [Select]
    (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...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #28 on: November 14, 2014, 07:21:27 AM »
Marc'Antonio,

Quote
Is is very similar, maybe Vlax-map-Collection is a little bit faster...

Yes, that may be the case ... worth investigating further.

Also, because you are using the equivalent of :
Code - Auto/Visual Lisp: [Select]
  1. (setq layObj  (vla-item *aclayers "0") )
  2. (vl-catch-all-apply 'vla-put-freeze (list LayObj :vlax-true))
you don't need to test each layer name against the current layer during the iteration of the layer collection
... That may be saving a few ticks. I'll investigate that further when I can find the time.

This is a nice touch.
Code - Auto/Visual Lisp: [Select]
  1. (wcmatch layName "~0")

Thanks for the input.



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: Freezing/Thawing Layers by Wildcard Match.
« Reply #29 on: November 14, 2014, 07:37:54 AM »
Regarding  vlax-map-collection
 

Code - Auto/Visual Lisp: [Select]
  1. (BenchMark2
  2.   500
  3.      *aclayers
  4.      '(lambda (LayerObj)
  5.         (vl-catch-all-apply 'vla-put-freeze (list LayerObj :vlax-true))
  6.         (vl-catch-all-apply 'vla-put-freeze (list LayerObj :vlax-false))
  7.       )
  8.     )
  9.     (vlax-for
  10.      LayerObj
  11.      *aclayers
  12.      (vl-catch-all-apply 'vla-put-freeze (list LayerObj :vlax-true))
  13.      (vl-catch-all-apply 'vla-put-freeze (list LayerObj :vlax-false))
  14.     )
  15.    )
  16. )

It's pretty close :-)

_$
Benchmarking-V2 :B=500 [M.P.2005 <revised kdub 2005,2014>] ........
Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (VLAX-FOR LAYEROBJ *ACLAYERS (VL-CAT...).....890 / 1.0011 <slowest>: 27.8125ms Per iteration
    (vlax-map-Collection *ACLAYERS (QUOT...).....889 / 1 <fastest>: 27.78125ms Per iteration

 
_$
Benchmarking-V2 :B=500 [M.P.2005 <revised kdub 2005,2014>] ........
Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (VLAX-FOR LAYEROBJ *ACLAYERS (VL-CAT...).....873 / 1.0175 <slowest>: 27.28125ms Per iteration
    (vlax-map-Collection *ACLAYERS (QUOT...).....858 / 1 <fastest>: 26.8125ms Per iteration

 
_$
Benchmarking-V2 :B=500 [M.P.2005 <revised kdub 2005,2014>] ........
Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (vlax-map-Collection *ACLAYERS (QUOT...).....874 / 1 <slowest>: 27.3125ms Per iteration
    (VLAX-FOR LAYEROBJ *ACLAYERS (VL-CAT...).....874 / 1 <fastest>: 27.3125ms Per iteration

 
_$
Benchmarking-V2 :B=500 [M.P.2005 <revised kdub 2005,2014>] ........
Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (vlax-map-Collection *ACLAYERS (QUOT...).....889 / 1 <slowest>: 27.78125ms Per iteration
    (VLAX-FOR LAYEROBJ *ACLAYERS (VL-CAT...).....889 / 1 <fastest>: 27.78125ms Per iteration

 
_$
Benchmarking-V2 :B=500 [M.P.2005 <revised kdub 2005,2014>] ........
Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (vlax-map-Collection *ACLAYERS (QUOT...).....905 / 1.018 <slowest>: 28.28125ms Per iteration
    (VLAX-FOR LAYEROBJ *ACLAYERS (VL-CAT...).....889 / 1 <fastest>: 27.78125ms Per iteration
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.