Tool Release: XREFOBJCHANGE.LSP — Easily Modify XREF Layer Properties

Tool Release: XREFOBJCHANGE.LSP — Easily Modify XREF Layer Properties

tclappER5PH
Participant Participant
164 Views
2 Replies
Message 1 of 3

Tool Release: XREFOBJCHANGE.LSP — Easily Modify XREF Layer Properties

tclappER5PH
Participant
Participant

I recently started working with a team that relies heavily on XREFs in their workflow — and for good reason. It keeps things modular and efficient. But with every new project, there’s always a need to tweak the appearance of XREF layers to match client standards and final deliverable expectations.

 

That’s where this routine comes in.

XREFOBJCHANGE lets you click on any object — including within an XREF — and instantly targets its layer for editing. It then gives you the option to:

Set a new color via the color picker

Choose a different linetype from loaded types

Assign a new lineweight from a predefined list

No need to scroll through endless layer names or hunt through the layer manager. Just click, change, and move on.

 

Requirements: AutoCAD with VLISP support
Included: Lee Mac’s listbox dialog (embedded inline for compatibility)
Usage: Type XREFOBJCHANGE at the command line and follow the prompts

Let me know what you think — and feel free to improve or share it with your teams.

;;; ------------------------------------------------------------------------
;;; XREFOBJCHANGE.LSP
;;;
;;; Author: Todd Clapp
;;; Version: 1.0
;;; Date: June 10, 2025
;;;
;;; Description:
;;; This routine allows the user to select an object within an XREF
;;; (or any object) and change the properties of the layer it resides on.
;;; The user can optionally modify the layer's color, linetype, and lineweight.
;;;
;;; Features:
;;; - Select an object and identify its layer.
;;; - Prompt for new color (via color dialog).
;;; - Prompt for new linetype from list of loaded types.
;;; - Prompt for new lineweight from standard options.
;;; - Updates the layer with selected values.
;;;
;;; Requirements:
;;; - AutoCAD with VLISP support
;;; - Lee Mac's ListBox function is included inline for compatibility
;;;
;;; Usage:
;;; Type `XREFOBJCHANGE` in the command line and follow prompts.
;;; ------------------------------------------------------------------------

(defun c:xrefobjchange ( / col ent lay typ lw lwList )
(while
(progn (setvar 'errno 0)
(not
(or (setq ent (car (nentsel "\nSelect object on layer to change: ")))
(= 52 (getvar 'errno))
)
)
)
(princ "\nMissed, try again.")
)
(if ent
(progn
(setq lay (cdr (assoc 8 (entget ent))))

;; Color selection (can skip)
(setq col (acad_colordlg (cdr (assoc 62 (tblsearch "layer" lay))) nil))

;; Linetype selection (can skip)
(setq typ (LM:listbox "Select Linetype" (GetLinetypes) nil))

;; Lineweight selection (can skip)
(setq lwList '("Default" "0.00" "0.05" "0.09" "0.13" "0.15" "0.18" "0.20" "0.25" "0.30" "0.35" "0.40" "0.50" "0.53" "0.60" "0.70" "0.80" "0.90" "1.00" "1.06" "1.20" "1.40" "1.58" "2.00" "2.11"))
(setq lw (LM:listbox "Select Lineweight" lwList nil))

;; Apply changes
(command "_.-layer")
(if col (command "_C" col lay))
(if typ (command "_L" (car typ) lay))
(if lw (command "_LW" (car lw) lay))
(command "")
)
)
(princ)
)

(defun GetLinetypes ( / def lst )
(setq def nil lst '())
(while (setq def (tblnext "ltype" (null def)))
(if (not (wcmatch (cdr (assoc 2 def)) "*|*"))
(setq lst (cons (cdr (assoc 2 def)) lst))
)
)
(acad_strlsort lst)
)

;; Lee Mac - List Box function (included for portability)
(defun LM:listbox ( msg lst mtp / dch des tmp res )
(cond
( (not
(and
(setq tmp (vl-filename-mktemp nil nil ".dcl"))
(setq des (open tmp "w"))
(write-line
(strcat "listbox : dialog { label=\"" msg
"\"; spacer; : list_box { key=\"list\"; multiple_select="
(if mtp "true" "false") "; } spacer; ok_cancel; }"
)
des
)
(not (close des))
(< 0 (setq dch (load_dialog tmp)))
(new_dialog "listbox" dch)
)
)
(prompt "\nError Loading List Box Dialog.")
)
( t
(start_list "list")
(foreach itm lst (add_list itm))
(end_list)
(setq res (set_tile "list" "0"))
(action_tile "list" "(setq res $value)")
(setq res
(if (= 1 (start_dialog))
(mapcar '(lambda ( x ) (nth x lst)) (read (strcat "(" res ")")) )
)
)
)
)
(if (< 0 dch) (unload_dialog dch))
(if (and tmp (setq tmp (findfile tmp))) (vl-file-delete tmp))
res
)

(princ)

 

 

165 Views
2 Replies
Replies (2)
Message 2 of 3

pbejse
Mentor
Mentor

Thank you for sharing @tclappER5PH 

0 Likes
Message 3 of 3

Moshe-A
Mentor
Mentor

@tclappER5PH  hi,

 

Yes 🙏 very nice tool, sure some of us will find it useful - thank you

 

if you want improve it? here some options to think of

1. display xref name you operate on

2. display the layer name you operate

3. give user the option to save these changes back to xref file. 

 

Moshe

 

0 Likes