+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 31
  1. #1
    Super Member AQucsaiJr's Avatar
    Computer Details
    AQucsaiJr's Computer Details
    Operating System:
    Windows 7 Pro
    Computer:
    Dell Optiplex 790
    CPU:
    Intel Core i5-2500 @ 3.30 GHz
    RAM:
    8.00 GB
    Graphics:
    AMD Radeon HD 6450
    Monitor:
    Dell
    Discipline
    Electrical
    AQucsaiJr's Discipline Details
    Occupation
    Electrical Engineering Technition / Power Utilities
    Discipline
    Electrical
    Details
    Power Utility Protection and Control Engineering
    Using
    Electrical 2012
    Join Date
    Nov 2008
    Location
    USA, Florida, Orlando
    Posts
    515

    Default Too many layers!!! Need to merge them!

    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.
    Attached Files

  2. #2
    Super Member AQucsaiJr's Avatar
    Computer Details
    AQucsaiJr's Computer Details
    Operating System:
    Windows 7 Pro
    Computer:
    Dell Optiplex 790
    CPU:
    Intel Core i5-2500 @ 3.30 GHz
    RAM:
    8.00 GB
    Graphics:
    AMD Radeon HD 6450
    Monitor:
    Dell
    Discipline
    Electrical
    AQucsaiJr's Discipline Details
    Occupation
    Electrical Engineering Technition / Power Utilities
    Discipline
    Electrical
    Details
    Power Utility Protection and Control Engineering
    Using
    Electrical 2012
    Join Date
    Nov 2008
    Location
    USA, Florida, Orlando
    Posts
    515

    Default

    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.

  3. #3
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,143

    Default

    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...

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,818

    Default

    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 ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,143

    Default

    Is there any benefit to (function over '( ?

    I thought about making the vla-get-layers global, but it seemed pointless since it would only be run once per drawing.

    Quote Originally Posted by Lee Mac View Post
    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))
    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...

  6. #6
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,143

    Default

    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...

  7. #7
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    try to benchmark it alan. i think vovka on theswamp is the one who pointed
    that it makes it faster.

  8. #8
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,143

    Default

    Quote Originally Posted by wizman View Post
    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...

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,818

    Default

    Alan,

    The global #Layers will be much quicker when running the function through a mapcar statement

    Your

    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))))))
    Is not a valid comparison, as both have #Layers global.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,818

    Default

    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 ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. VBA merge layers....copy content of a layer to other layer
    By faith_cad in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 17th Dec 2009, 07:01 pm
  2. How do I merge a large number of layers?
    By Mackao in forum AutoCAD General
    Replies: 1
    Last Post: 26th Nov 2009, 01:41 pm
  3. Merge animation
    By christo in forum Rigging & Animation
    Replies: 3
    Last Post: 2nd Jun 2009, 02:23 pm
  4. Merge layers
    By fostertom in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 3
    Last Post: 24th Mar 2008, 10:48 pm
  5. How to merge?
    By aubob in forum AutoCAD Drawing Management & Output
    Replies: 8
    Last Post: 20th Jan 2005, 01:17 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts