Author Topic: Reuse layer properties from X-refs  (Read 1510 times)

0 Members and 1 Guest are viewing this topic.

matrim08

  • Guest
Reuse layer properties from X-refs
« on: March 11, 2014, 12:12:49 PM »
Hello,
The company that I work for does it's own design work and has built multiple manufacturing locations.  Because of this, a number of these locations are designed and built "exactly" the same, using the same equipment tag numbers and "model" orientation.  As expansion and upgrades happen across all facilities, multiple/similar layouts need to be created for each location.  Thanks to the first section of coding in ronjonp's, find and replace (added some user input), I'm able to swap out one projects models for another, XXX-01-M123 for YYY-02-M123, in the master assembly files and all the layouts that pertain.

I'm have trouble with the layout portion of this process.  The assembly files are x-refed into the layout and some of those layers are modified; color, frozen, ect.  Because we use standard layers for everything, I would like to take the modified layer properties from the original layout and apply those same properties to the new x-ref layers.  Because the x-ref layers have different prefixes, I lose all overrides.
I know that renaming an x-ref layer is not possible, but I didn't know if this could be done through a list or a table.

I am fairly new to writing LISP routines and I have searched for answers for a couple of days to no avail.  Any guidance would be greatly appreciated, or you could just tell me that I am asking for the impossible.

Thanks in advance.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Reuse layer properties from X-refs
« Reply #1 on: March 11, 2014, 12:53:06 PM »
Welcome to the Swamp.
I'm sure someone will point you in the right direction.
Off to lunch... 8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Reuse layer properties from X-refs
« Reply #2 on: March 11, 2014, 03:57:12 PM »
Can you clarify:
1.
Do you have a single dwg with multiple xrefs and do you want to apply the layer settings used for xref 'A' to the layers of xref 'B'. In other words: Layer B|Layer1 must match A|Layer1.
2.
When you use the word 'overrides' are you referring to viewport layer overrrides or do you mean VISRETAIN overrrides?

matrim08

  • Guest
Re: Reuse layer properties from X-refs
« Reply #3 on: March 11, 2014, 04:52:44 PM »
Can you clarify:
1.
Do you have a single dwg with multiple xrefs and do you want to apply the layer settings used for xref 'A' to the layers of xref 'B'. In other words: Layer B|Layer1 must match A|Layer1.
2.
When you use the word 'overrides' are you referring to viewport layer overrrides or do you mean VISRETAIN overrrides?
Yes (to start out, see below) this will be done in single dwg with multiple x-refs, most are nested within an assembly x-ref, and yes I would like to apply the layer settings exactly between the x-refs.  All the layer overrides are done in the layout dwg.  Most are done in model space, freezing undesired detail (ie. bolts) or changing the color to indicate existing, but there are some in the viewports.

We are transitioning to a "document management system" and when these dwg's are first created they are multi-tab drawings, but when the time comes to plot/issue them, we have to split them into separate dwg's (for plotting and tracking of pdf's in the system).  At some point down the road we will have to issue "similar" drawings for another facility and we would like to keep some consistency between these drawings and this seems to be the best and quickest way to accomplish this (if possible).

Hope that wasn't too long winded.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Reuse layer properties from X-refs
« Reply #4 on: March 12, 2014, 08:15:37 AM »
Here is some code that will handle what I have called 'VISRETAIN overrides'. For the viewport overrides you will have to do some work yourself. There is enough information on this forum on the VP freezing of layers and my guess is that you don't use other VP overrides.

Code - Auto/Visual Lisp: [Select]
  1. ; For: http://www.theswamp.org/index.php?topic=46527.0
  2.  
  3. ; The targetNameList argument can be nil.
  4. ; (XrefLayerMatch "A" '("B" "c"))
  5. ; (XrefLayerMatch "A"  nil)
  6. ; Return value: T or nil.
  7. (defun XrefLayerMatch (sourceName targetNameList / allNameList layerDataList)
  8.   (setq targetNameList (mapcar 'strcase targetNameList))
  9.   (setq allNameList (mapcar 'strcase (XrefNameListGet)))
  10.   (if
  11.     (and
  12.       (vl-position (strcase sourceName) allNameList)
  13.       (setq allNameList (vl-remove (strcase sourceName) allNameList))
  14.       (setq targetNameList
  15.         (if targetNameList
  16.           (vl-remove-if-not
  17.             '(lambda (xref) (vl-position xref allNameList))
  18.             targetNameList
  19.           )
  20.           allNameList
  21.         )
  22.       )
  23.     )
  24.     (progn
  25.       (setq layerDataList
  26.         (apply
  27.           'append
  28.           (mapcar
  29.             '(lambda (lst)
  30.               (mapcar
  31.                 '(lambda (xref)
  32.                   (cons
  33.                     (strcat xref "|" (car lst))
  34.                     (cdr lst)
  35.                   )
  36.                 )
  37.                 targetNameList
  38.               )
  39.             )
  40.             (XrefLayerDataListGet sourceName)
  41.           )
  42.         )
  43.       )
  44.       (foreach lst layerDataList
  45.         (XrefLayerDataListSet lst)
  46.       )
  47.       (setvar 'cmdecho 0)
  48.       (command "_.regenall")
  49.       (setvar 'cmdecho 1)
  50.       T ; Return value.
  51.     )
  52.   )
  53. )
  54.  
  55. (defun XrefNameListGet ( / item return)
  56.   (setq item (tblnext "block" T))
  57.   (while item
  58.     (if (= (logand (cdr (assoc 70 item)) 4) 4)
  59.       (setq return (cons (cdr (assoc 2 item)) return))
  60.     )
  61.     (setq item (tblnext "block"))
  62.   )
  63.   (reverse return)
  64. )
  65.  
  66. ; Return value format:
  67. ; (("NEWLAYER1" (70 . 1) (62 . 4) (6 . "Continuous")) ("NEWLAYER2" (70 . 0) (62 . 7) (6 . "Continuous")))
  68. (defun XrefLayerDataListGet (sourceName / item match return)
  69.   (setq match (strcat (strcase sourceName) "|*"))
  70.   (setq item (tblnext "layer" T))
  71.   (while item
  72.     (if (wcmatch (strcase (cdr (assoc 2 item))) match)
  73.       (setq return
  74.         (cons
  75.           (list
  76.             (strcase
  77.               (substr
  78.                 (cdr (assoc 2 item))
  79.                 (+ (vl-string-search "|" (cdr (assoc 2 item))) 2)
  80.               )
  81.             )
  82.             (cons 70 (logand (cdr (assoc 70 item)) 1)) ; Only look at the first bit (Freeze/Thaw).
  83.             (assoc 62 item) ; Color and On/Off.
  84.             (assoc 6 item)  ; Linetype.
  85.           )
  86.           return
  87.         )
  88.       )
  89.     )
  90.     (setq item (tblnext "layer"))
  91.   )
  92.   (reverse return)
  93. )
  94.  
  95. ; Argument format: ("B|NEWLAYER1" (70 . 1) (62 . 4) (6 . "Continuous"))
  96. (defun XrefLayerDataListSet (layerDataList / elist ename)
  97.   (if (setq ename (tblobjname "layer" (car layerDataList)))
  98.     (progn
  99.       (setq elist (entget ename))
  100.       (setq elist
  101.         (subst
  102.           (cons
  103.             70
  104.             (boole
  105.               (if (zerop (cdr (assoc 70 (cdr layerDataList)))) 2 7)
  106.               (cdr (assoc 70 elist))
  107.               1
  108.             )
  109.           )
  110.           (assoc 70 elist)
  111.           elist
  112.         )
  113.       )
  114.       (setq elist
  115.         (subst
  116.           (assoc 62 (cdr layerDataList))
  117.           (assoc 62 elist)
  118.           elist
  119.         )
  120.       )
  121.       (setq elist
  122.         (subst
  123.           (assoc 6 (cdr layerDataList))
  124.           (assoc 6 elist)
  125.           elist
  126.         )
  127.       )
  128.       (entmod elist)
  129.     )
  130.   )
  131. )