Author Topic: merge list_layer to another list_layer  (Read 3762 times)

0 Members and 1 Guest are viewing this topic.

new_mem

  • Newt
  • Posts: 67
Re: merge list_layer to another list_layer
« Reply #15 on: May 22, 2016, 12:39:33 PM »


Glad to hear you got something working for yourself, new_mem.
[/quote]

Thank for your solution.  :smitten:

new_mem

  • Newt
  • Posts: 67
Re: merge list_layer to another list_layer
« Reply #16 on: May 22, 2016, 12:47:06 PM »
LeeMac
How can i merge layer multi drawing in folder but dont open drawing. I saw bfind lisp magic.  :smitten:

ChrisCarlson

  • Guest
Re: merge list_layer to another list_layer
« Reply #17 on: May 23, 2016, 12:56:16 PM »
Look into Lee-Mac's steal routine

http://www.lee-mac.com/steal.html

Code - Auto/Visual Lisp: [Select]
  1. (Steal "C:\\My Folder\\MyDrawing.dwg"
  2.    '(
  3.         (
  4.             "Layers"
  5.             ("Layer1" "Layer2")
  6.         )
  7.         (
  8.             "Dimension Styles"
  9.             ("DimStyle*")
  10.         )
  11.     )

new_mem

  • Newt
  • Posts: 67
Re: merge list_layer to another list_layer
« Reply #18 on: August 26, 2016, 12:30:18 PM »
Thanks for repply,

now i think i will use DBX to merge layer. Can i do it ?

Can i call merge list layer via DBX in multifile? or call acet_laytrans ?

Because cannot call ssget object to put new name layer.

« Last Edit: August 26, 2016, 12:36:43 PM by new_mem »

new_mem

  • Newt
  • Posts: 67
Re: merge list_layer to another list_layer
« Reply #19 on: August 27, 2016, 10:04:52 AM »
i think can do it

Found some code of Lee Mac and write this code:

(defun c:test ( / lst lst_layer)
    (if (setq lst (LM:getfiles "Select Drawings to Process" nil "dwg;dws;dwt"))
      (progn

   (setq lst_layer '(("Layer1" "Arch1") ("Layer2"  "Arch2") ("Layer3" "Arch3")))
   (LM:odbx '(lambda ( doc ) (merge_layer doc lst_layer)) lst t)
        (princ "\n*Cancel*")
   );progn
    )
    (princ)
)
(defun merge_layer (doc lst / layers lay_obj)
  (foreach name lst
    (make_layer doc (cadr name))
    )
  (setq layers (vla-get-layers doc))
  (vlax-for obj (vla-get-modelspace doc)
    (setq lay_obj (vlax-get obj 'Layer))
    (foreach name lst
      (if (wcmatch lay_obj (car name))
   (vla-put-layer obj (cadr name))
   );if
      );foreach name
    );vlax-for obj
  (vla-purgeall doc)
  );defun
(defun make_layer (doc str / )
  (if (not (wcmatch (vla-item lay (vla-get-layers doc) str)))
    (vla-add (vla-get-layers doc) str)
    )
  )

new_mem

  • Newt
  • Posts: 67
Re: merge list_layer to another list_layer
« Reply #20 on: August 27, 2016, 07:45:14 PM »
Wow,

why error: ActiveX Server returned the error: unknown name: PurgeAll

Can someone tell me, pls.!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: merge list_layer to another list_layer
« Reply #21 on: August 27, 2016, 10:40:18 PM »
ODBX docs do not support the PurgeAll method.

You can achieve a similar effect as purging by rolling your own purger, i.e. error trap attempts to delete collection entries.

Simplified concept:

Code: [Select]
(defun _Items ( collection / items )
    (vlax-for i collection (setq items (cons i items)))
    ;;  Since this is a general function reflect
    ;;  the collection's original item order.
    (reverse items)
)

Code: [Select]
(defun _Purge ( collection n )
    ;;  Try to delete collection entries n times
    ;;  (to deal with intra-entry dependencies).
    (   (lambda ( live n / dead )
            (repeat n
                (foreach i live
                    (vl-catch-all-apply 'vla-delete (list i))
                    (if (vlax-erased-p i) (setq dead (cons i dead)))
                )
                (setq live (vl-remove-if (function (lambda (i) (member i dead))) live))
            )
            (length dead)
        )
        ;;  Process newest entries first.
        (reverse (_Items collection))
        ;;  Idiot proof the n argument.
        (if (eq 'int (type n)) n 1)
    )
)

(_Purge (vla-get-layers doc) 1)

might return 42

Expect sloth-like performance.

Why reverse the list? Latter entries (in collections like blocks) may reference earlier entries, so deleting backwards (i.e. newest entries first) would tend to sport a higher success rate.

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

new_mem

  • Newt
  • Posts: 67
Re: merge list_layer to another list_layer
« Reply #22 on: August 28, 2016, 03:06:35 AM »
Cool,

thanks MP  :roll:

I add code then it delete layer and object in layer.

(vlax-for obj (vla-get-paperspace doc)
    (print obj)
    (setq lay_obj (vlax-get obj 'Layer))
    (foreach name lst
      (if (wcmatch lay_obj (car name))
   (vla-put-layer obj (cadr name))
   );if
      );foreach name
    );vlax-for obj
(foreach name lst
      (if (ValidItem layers (car name))
   (vla-delete (vla-item layers (car name)))
   )
      )
;Code found Doug Broad
(defun ValidItem (collection item / res)
  (vl-catch-all-apply
    '(lambda ()
       (setq res (vla-item collection item))
     )
  )
  res
)

Your code have error trap. It still not delete layer if object in paperspace not change another layer. So i used your code in lisp.
One more question: how to put layer all object in paperspace if dwg have >1 layout ?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: merge list_layer to another list_layer
« Reply #23 on: August 28, 2016, 03:32:03 AM »
This code will step through all layouts within the current drawing and print the name of each object type to the command line.

Code - Text: [Select]
  1. (vlax-for i (vla-get-Layouts (vla-get-ActiveDocument  (vlax-get-Acad-Object)))
  2.     (vlax-for j (vla-get-Block i)
  3.         (print (vla-get-ObjectName j))
  4.     )
  5. )
  6.  

If you only want 'paper space' layouts, then the only way I can remember is to check the name of the layout, and if it doesn't equal 'Model' then do your work.  Like:
Code - Text: [Select]
  1. (vlax-for i (vla-get-Layouts (vla-get-ActiveDocument  (vlax-get-Acad-Object)))
  2.     (if (/= (vla-get-Name i) "Model" )
  3.         (vlax-for j (vla-get-Block i)
  4.             (print (vla-get-ObjectName j))
  5.         )
  6.     )
  7. )
  8.  

Hope that helps.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

new_mem

  • Newt
  • Posts: 67
Re: merge list_layer to another list_layer
« Reply #24 on: August 28, 2016, 03:40:49 AM »
Okey Tim,

If only way then let me try it.

Thanks for your code.

new_mem

  • Newt
  • Posts: 67
Re: merge list_layer to another list_layer
« Reply #25 on: August 28, 2016, 07:55:30 AM »
Okey right Tim,

Thanks Tim
add 2 loop get all obj.

(vlax-for i (vla-get-Layouts doc)
    (vlax-for j (vla-get-Block i)
      (if (setq lay_obj (vlax-get j 'Layer))
   (foreach name lst
     (if (wcmatch lay_obj (car name))
       (vla-put-layer j (cadr name))
       );if
     );foreach name
   );if
      );vlax-for j
    );vlax-for i
  (foreach name lst
    (_Purge (vla-get-layers doc) (car name))
    )