Script or lisp to control layers properties in certain viewports

Script or lisp to control layers properties in certain viewports

Anonymous
Not applicable
1,252 Views
4 Replies
Message 1 of 5

Script or lisp to control layers properties in certain viewports

Anonymous
Not applicable

Hi,

I am looking for a way to automate a repetitive task. I need a lisp (or script) that changes the color of a certain group of layers in certain viewports.

 

In our office, we create individual files for different parts of a building’s drawings, such as floor plans and slab edge plans, once the common pieces of the drawing are put together, then we recolor the xrefered layers to be able to distinguish them more easily (some people escape this step). Then we xclip some areas and draw live to complete the drawing. All of these happen in the model space.

 

See file reference structure at the image below as an example.Image 1Image 1

 

Once the xrefing, xcliping and drawing is completed, it’s time to put these drawings in plot sheets using the xrefing command. In plotsheets, we create viewports to display the desired part of the part. Since the xrefed file is consisted of many layers carrying from the different pieces of that file, sometimes it’s confusing to track a layer to its roots.

Please see the example plotsheet below

2.jpg

 

We only show new information – live drawing portion - in their original color and recolor the repeated –xrefed- parts to a certain color that prints gray. To do so, we have to override the layer color on that specific viewport to get the desired outcome. This process repeats at many sheets and is tedious to manage all those layers compiling from different drawings, popping up in the plot sheet files. -Some projects have more than a hundred sheets!

 

Now, i am searching for ways to manage layers in viewports smarter!

I know with script files we can control live layers in the modeling space, but I wanted to ask if anyone knows a way that help us to facilitate the whole process – especially plotsheet graphic control- and to automate a good amount of the task.

 

 Best,

 

 

0 Likes
1,253 Views
4 Replies
Replies (4)
Message 2 of 5

marko_ribar
Advisor
Advisor

See if this snippet could be of some help...

;;; Changes the selected XREF's Layer color to AutoCAD Color 253 in the current drawing only
;;; Useful for Existing Base (E-Base) XREFs
(defun c:XR253	(/ xr1 xr2 xr3 xr4 xr5 xr6 tx1 tb1)
  (if (setq
       xr1 (entsel "\nSelect Xref to change all layers to color 253: ")  ;; <--- Change color number as needed
      ) ;_ end of setq
    (progn
      (setq xr2 (entget (car xr1)))
      (setq tx1 (cdr (assoc 0 xr2)))
      (if (and (= tx1 "INSERT")
         ) ;_ end of and
       (progn
         (setq xr3 (cdr (assoc 2 xr2)))
         (setq xr4 (tblsearch "block" xr3))
         (if (setq xr5 (cdr (assoc 1 xr4)))
           (progn
             (setq xr6 (strcat xr3 "|*"))
             (vl-cmdf "_.-LAYER" "_C" "253" xr6 "")  ;;; <---Change color number as needed
           ) ;_ end of progn
           (prompt (strcat "\n" xr3 " is not an X-Ref."))
         ) ;_ end of if
       ) ;_ end of progn
       (prompt "\nNo valid XREF selected")
      ) ;_ end of if
    ) ;_ end of progn
    (princ " ...Nothing selected")
  ) ;_ end of if
  (princ)
)

Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 5

Anonymous
Not applicable

It seems like, this lisp changes the color of the base xrefed model in the plotsheet, I am looking for a way and give me the option for changing the colors of the nested xrefs. 

please see the attached image:

 

 

Thanks for your reply.

0 Likes
Message 4 of 5

marko_ribar
Advisor
Advisor

Sorry for late reply, I was busy doing other things... I think that this mod. works for nested xrefs as well...

 

;;; Changes the selected XREF's Layer color to AutoCAD Color 253 in the current drawing only
(defun c:XR253	( / GetList ePick sLayer sObjectType sLineType sColor sBlockname sStyleName xr3 xr4 xr5 xr6 )

  (defun GetList ( / iNest eList )
    (setq iNest (length (last ePick)))
   
  ;The next if statement handles block within blocks. iNest = 1 means no nesting. Since (nentsel) goes all the
  ;way to the root AutoCAD object we have to traverse back up to the top level of the nesting to get a block name.
    (if (= iNest 1)
      (setq eList (entget (car ePick))) ;then pull the list from the standard nentsel call.
      (setq eList (entget (nth (- iNest 2) (last ePick))))  ;else last last our way back up to the top block definition
    );end if
   
   
  ;Pull out the assoc codes.
    (setq sLayer (cdr (assoc 8 eList))
                  sObjectType (cdr (assoc 0 eList))
          sLineType (cdr (assoc 6 eList))     ; This is optional, we check for it later.
                  sColor (cdr (assoc 62 eList))
      sBlockname ""
      sStyleName ""
        ); end setq
   
   
  ;Check for no linetype override, in which case it is bylayer.
        (if (= sLineType nil) (setq sLineType "Bylayer"))   ;Tidy up the optional DXF codes for linetype
   
   
  ;If the object is a vertex, call a vertex a polyline
        (if (= "VERTEX" sObjectType) (setq sObjectType "POLYLINE"))
   
  ;If the object is a block, call an insert a block and find out the block name
    (if (= "INSERT" sObjectType)
      (progn
        (setq   sObjectType "BLOCK"
           sBlockname (cdr (assoc 2 eList))
        )
      );end progn
    );end if
   
  ;If the object is text or mtext, find out the style name
    (if (or (= "TEXT" sObjectType) (= "MTEXT" sObjectType))
      (setq sStyleName (cdr (assoc 7 eList)))
    );end if
   
  ; Sort out the colors and assign names to the first 8 plus bylayer and byblock
        (cond ( (= nil sColor) (setq sColor "Bylayer"))
            ( (= 0 sColor) (setq sColor "Byblock"))
              ( (= 1 sColor) (setq sColor "Red"))
              ( (= 2 sColor) (setq sColor "Yellow"))
      ( (= 3 sColor) (setq sColor "Green"))
              ( (= 4 sColor) (setq sColor "Cyan"))
              ( (= 5 sColor) (setq sColor "Blue"))
            ( (= 6 sColor) (setq sColor "Magenta"))
              ( (= 7 sColor) (setq sColor "White"))
              ( (= 256 sColor) (setq sColor "Bylayer"))
              (t (setq sColor (itoa sColor)))
        );end cond
   
  ;(princ (strcat sLayer sColor sObjectType sLinetype sThickness sStylename sBlockname))  ; for debugging purposes
   
  ); End GetList

;The next while loop checks for null or invalid selection.
  (while (or
    (not (setq ePick (nentsel "\nSelect nested xref to change all layers to color 253: ")))
    (< (length ePick) 3)
    );end or
    (progn  (princ "\nObject was invalid or was not selected."))
  );end while

  (GetList)

  (if (and sLayer sObjectType sLineType sColor sBlockname sStyleName)
    (if (wcmatch sObjectType "INSERT,BLOCK")
      (progn
        (setq xr3 sBlockname)
        (setq xr4 (tblsearch "block" xr3))
        (if (setq xr5 (cdr (assoc 1 xr4)))
          (progn
            (setq xr6 (strcat xr3 "|*"))
            (vl-cmdf "_.-LAYER" "_C" "253" xr6 "")  ;;; <---Change color number as needed
          ) ;_ end of progn
          (prompt (strcat "\n" xr3 " is not an X-Ref."))
        ) ;_ end of if
      ) ;_ end of progn
      (prompt "\nNo valid XREF selected")
    ) ;_ end of if
  ) ;_ end of if
  (princ)
) 

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 5 of 5

Anonymous
Not applicable

Thank you, my friend.

This lisp works charmingly!

There are a few minor things that I would like to revise.

Is there a way to contact you directly? 

This is my email mmohammadi@roberthidey.com, maybe we can work together and optimize this lisp you wrote.

Best, 

 

 

0 Likes