The script I wrote calls out the built in layer merge command. My problem is there are so many drawings that need this fix that I wanted to make this a batch file, however the script I wrote gets stuck to often and is not a time saver.
Registered forum members do not see this ad.
So here is the deal,
I have a list of bogus layers that exist in a bunch of drawings that need to be merged into the correct layer. I tried writing a script for this but not all the drawings have the bogus layers so the script gets stuck every time it reaches a layer that is not in the drawing. It is not a time saver to have to resume the script after every pause. Anyone know of a lisp or other type of program that can do this? I have attached the script I wrote up if maybe I can make some changes to it to have it work.
The script I wrote calls out the built in layer merge command. My problem is there are so many drawings that need this fix that I wanted to make this a batch file, however the script I wrote gets stuck to often and is not a time saver.
You could try something like this:
Code:(defun MergeLayers (#OldLayers #NewLayers / #Layers) (setq #Layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))) (mapcar '(lambda (o n) (and (tblsearch "layer" o) (or (tblsearch "layer" n) (vla-add #Layers n)) (vl-cmdf "_.-laymrg" "_n" o "" "_n" n "_y") ) ;_ and ) ;_ lambda #OldLayers #NewLayers ) ;_ mapcar ) ;_ defun
Example:
Code:(MergeLayers '("A" "B" "C" "D") '("1" "2" "3" "4"))
DropBox | finding the light...
Seann: ...it went crazy ex-girlfriend on me...
eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...
A touch quicker:
Code:(defun MergeLayers (#OldLayers #NewLayers) (setq #Layers (cond (#Layers) ((vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))))) (mapcar (function (lambda (o n) (and (tblsearch "layer" o) (or (tblsearch "layer" n) (vla-add #Layers n)) (vl-cmdf "_.-laymrg" "_n" o "" "_n" n "_y")))) #OldLayers #NewLayers))![]()
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
DropBox | finding the light...
Seann: ...it went crazy ex-girlfriend on me...
eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...
Just because I was curious:
Code:Command: (benchmark '( (tl) (ta) )) Elapsed milliseconds / relative speed for 32768 iteration(s): (TL).....1578 / 1.01 <fastest> (TA).....1593 / 1 <slowest> Command: (benchmark '( (tl) (ta) )) Elapsed milliseconds / relative speed for 32768 iteration(s): (TL).....1594 / 1 <fastest> (TA).....1594 / 1 <slowest> Command: (benchmark '( (tl) (ta) )) Elapsed milliseconds / relative speed for 32768 iteration(s): (TL).....1593 / 1 <fastest> (TA).....1594 / 1 <slowest>
Code:(defun tl () (setq #Layers (cond (#Layers) ((vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))))) (defun ta () (or #Layers (setq #Layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))))
DropBox | finding the light...
Seann: ...it went crazy ex-girlfriend on me...
eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...
try to benchmark it alan. i think vovka on theswamp is the one who pointed
that it makes it faster.
Code:Command: (benchmark '( (test1) (test2) )) Elapsed milliseconds / relative speed for 4096 iteration(s): (TEST1).....1625 / 1 <fastest> (TEST2).....1625 / 1 <slowest> Command: (benchmark '( (test1) (test2) )) Elapsed milliseconds / relative speed for 4096 iteration(s): (TEST1).....1625 / 1 <fastest> (TEST2).....1625 / 1 <slowest> Command: (benchmark '( (test1) (test2) )) Elapsed milliseconds / relative speed for 4096 iteration(s): (TEST1).....1609 / 1.02 <fastest> (TEST2).....1640 / 1 <slowest> Command: (benchmark '( (test1) (test2) )) Elapsed milliseconds / relative speed for 4096 iteration(s): (TEST1).....1609 / 1.01 <fastest> (TEST2).....1625 / 1 <slowest>Code:(defun test1 (/) (repeat 10 (mapcar '(lambda (a b) (strcat a " " b)) '("A" "B" "C") '("1" "2" "3")))) (defun test2 (/) (repeat 10 (mapcar (function (lambda (a b) (strcat a " " b))) '("A" "B" "C") '("1" "2" "3"))))
I need to run it on something a little more complex.
DropBox | finding the light...
Seann: ...it went crazy ex-girlfriend on me...
eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...
Alan,
The global #Layers will be much quicker when running the function through a mapcar statement
Your
Is not a valid comparison, as both have #Layers global.Code:(defun tl () (setq #Layers (cond (#Layers) ((vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))))) (defun ta () (or #Layers (setq #Layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))))
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
Registered forum members do not see this ad.
Code:Elapsed milliseconds / relative speed for 65536 iteration(s): (TL).....1872 / 3.23 <fastest> (TA).....6053 / 1.00 <slowest>Code:(defun ta (/ #Layers) (setq #Layers (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))) (defun tl ( ) (setq #Layers (cond (#Layers) ((vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))))))
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
Bookmarks