<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Put all Xrefs on a locked layer &amp;quot;C-XREF&amp;quot; in AutoCAD Forum</title>
    <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956023#M36459</link>
    <description>&lt;P&gt;Hi Jayhar, Thanks for the quick response. unfortunately the lisp isn't locking layer C-XREF for me.&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2023 04:08:54 GMT</pubDate>
    <dc:creator>kstapleton</dc:creator>
    <dc:date>2023-05-11T04:08:54Z</dc:date>
    <item>
      <title>Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956001#M36457</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like for the following lisp to include a layer lock function.&lt;/P&gt;&lt;P&gt;Currently, the lisp creates the layer C-XREF and puts all xrefs in the drawing in that layer. I would like it to also lock the C-XREF layer. Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;(defun c:xrlayer ( / a b c d layer )&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;(setq layer "C-XREF")&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;(while (setq a (tblnext "BLOCK" (null a)))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(if (= 4 (logand 4 (cdr (assoc 70 a))))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(setq b (cons "," (cons (cdr (assoc 2 a)) b)))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;(if (setq c&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(ssget "_X"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons 0 "INSERT")&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons 2 (apply 'strcat (cdr b)))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons 8 (strcat "~" layer))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(repeat (setq d (sslength c))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(entmod (list (cons -1 (ssname c (setq d (1- d)))) (cons 8 layer)))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;(princ)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;(command "_.layer"&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"_color" 6 "C-XREF"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;""&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;(princ)&lt;/DIV&gt;&lt;DIV&gt;)&lt;/DIV&gt;</description>
      <pubDate>Thu, 11 May 2023 03:41:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956001#M36457</guid>
      <dc:creator>kstapleton</dc:creator>
      <dc:date>2023-05-11T03:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956012#M36458</link>
      <description>&lt;P&gt;```lisp&lt;BR /&gt;(defun c:xrlayer ( / a b c d layer)&lt;BR /&gt;(setq layer "C-XREF")&lt;BR /&gt;&lt;BR /&gt;;; Lock the layer&lt;BR /&gt;(command "_.-layer" "_Lock" layer "")&lt;/P&gt;&lt;P&gt;(while (setq a (tblnext "BLOCK" (null a)))&lt;BR /&gt;(if (= 4 (logand 4 (cdr (assoc 70 a))))&lt;BR /&gt;(setq b (cons "," (cons (cdr (assoc 2 a)) b)))&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;(if (setq c&lt;BR /&gt;(ssget "_X"&lt;BR /&gt;(list&lt;BR /&gt;(cons 0 "INSERT")&lt;BR /&gt;(cons 2 (apply 'strcat (cdr b)))&lt;BR /&gt;(cons 8 (strcat "~" layer))&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;(repeat (setq d (sslength c))&lt;BR /&gt;(entmod (list (cons -1 (ssname c (setq d (1- d)))) (cons 8 layer)))&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;(princ)&lt;BR /&gt;&lt;BR /&gt;;; Set the layer color to 6&lt;BR /&gt;(command "_.layer" "_color" 6 "C-XREF" "")&lt;BR /&gt;&lt;BR /&gt;(princ)&lt;BR /&gt;)&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;In this modified version, I added the following line to lock the "C-XREF" layer:&lt;BR /&gt;```lisp&lt;BR /&gt;(command "_.-layer" "_Lock" layer "")&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;Now, when you run the `c:xrlayer` command, it will not only create the "C-XREF" layer and assign all xrefs to it but also lock the layer. Additionally, I noticed that you were using the `command` function to set the layer color to 6. I have retained that line in the modified code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if you have any further questions or if there's anything else I can assist you with!&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 03:51:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956012#M36458</guid>
      <dc:creator>jayhar</dc:creator>
      <dc:date>2023-05-11T03:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956023#M36459</link>
      <description>&lt;P&gt;Hi Jayhar, Thanks for the quick response. unfortunately the lisp isn't locking layer C-XREF for me.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 04:08:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956023#M36459</guid>
      <dc:creator>kstapleton</dc:creator>
      <dc:date>2023-05-11T04:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956043#M36460</link>
      <description>&lt;P&gt;Here's the updated Lisp code that includes the layer lock functionality for the "C-XREF" layer:&lt;/P&gt;&lt;P&gt;```lisp&lt;BR /&gt;(defun c:xrlayer (/ a b c d layer doc acadLayers)&lt;BR /&gt;(setq layer "C-XREF")&lt;/P&gt;&lt;P&gt;(setq doc (vla-get-activedocument (vlax-get-acad-object)))&lt;BR /&gt;(setq acadLayers (vla-get-layers doc))&lt;/P&gt;&lt;P&gt;;; Create the "C-XREF" layer if it doesn't exist&lt;BR /&gt;(if (not (vla-item acadLayers layer))&lt;BR /&gt;(vla-add acadLayers layer)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;;; Set the layer color to 6&lt;BR /&gt;(vla-put-color (vla-item acadLayers layer) 6)&lt;/P&gt;&lt;P&gt;;; Lock the "C-XREF" layer&lt;BR /&gt;(vla-put-lock (vla-item acadLayers layer) :vlax-true)&lt;/P&gt;&lt;P&gt;(while (setq a (tblnext "BLOCK" (null a)))&lt;BR /&gt;(if (= 4 (logand 4 (cdr (assoc 70 a))))&lt;BR /&gt;(setq b (cons "," (cons (cdr (assoc 2 a)) b)))&lt;BR /&gt;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;(if (setq c&lt;BR /&gt;(ssget "_X"&lt;BR /&gt;(list&lt;BR /&gt;(cons 0 "INSERT")&lt;BR /&gt;(cons 2 (apply 'strcat (cdr b)))&lt;BR /&gt;(cons 8 (strcat "~" layer))&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;(repeat (setq d (sslength c))&lt;BR /&gt;(entmod (list (cons -1 (ssname c (setq d (1- d)))) (cons 8 layer)))&lt;BR /&gt;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;(princ)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;(princ)&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;This updated code uses the `vla-put-lock` method to lock the "C-XREF" layer. It retrieves the Active Document and Layers objects from AutoCAD's ActiveX interface using the Visual LISP functions. Then, it creates the "C-XREF" layer if it doesn't exist, sets its color to 6, and locks it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 04:23:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956043#M36460</guid>
      <dc:creator>jayhar</dc:creator>
      <dc:date>2023-05-11T04:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956062#M36461</link>
      <description>&lt;P&gt;Hi Jayhar, when I run the lisp I get this error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kstapleton_0-1683780644899.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1213036i0E353E5EC60FE117/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kstapleton_0-1683780644899.png" alt="kstapleton_0-1683780644899.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 04:51:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956062#M36461</guid>
      <dc:creator>kstapleton</dc:creator>
      <dc:date>2023-05-11T04:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956077#M36462</link>
      <description>&lt;P&gt;&lt;SPAN&gt;if possible, provide any additional information or context that may help in identifying the issue.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 05:04:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956077#M36462</guid>
      <dc:creator>jayhar</dc:creator>
      <dc:date>2023-05-11T05:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956280#M36463</link>
      <description>&lt;P&gt;***modified response below***&lt;/P&gt;&lt;P&gt;this is the section of the code that causes that error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;;; Create the "C-XREF" layer if it doesn't exist
(if (not (vla-item acadLayers layer))
(vla-add acadLayers layer)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unfortunately, if the layer doesn't exist, the vla-item function will fail and crash the program.&lt;/P&gt;&lt;P&gt;here's another way to check if the layer exists:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;;; Create the "C-XREF" layer if it doesn't exist
(if (not (tblsearch "LAYER" layer))
(vla-add acadLayers layer)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or just go ahead &amp;amp; create the layer without checking because the vla-add function executes regardless:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;;; Create the "C-XREF" layer regardless if it already exists
(vla-add acadLayers layer)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;***modified here***&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1055426"&gt;@jayhar&lt;/a&gt;&amp;nbsp;original code did not lock the layer because the following line was placed at the beginning of the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(command "_.-layer" "_Lock" layer "")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instead the above should be placed right after changing the layer's color to 6,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;;; Set the layer color to 6
(command "_.layer" "_color" 6 "C-XREF" "")
;; Lock the layer
(command "_.-layer" "_Lock" layer "")
;; or the following works also
(command "_.-layer" "_Lock" "C-XREF" "")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 07:38:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11956280#M36463</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2023-05-11T07:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11958339#M36464</link>
      <description>&lt;P&gt;Hi Paullimapa, your modification did the trick. Works perfectly!&lt;/P&gt;&lt;P&gt;Thank you both for your time and efforts. Much appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 22:36:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11958339#M36464</guid>
      <dc:creator>kstapleton</dc:creator>
      <dc:date>2023-05-11T22:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11958388#M36465</link>
      <description>&lt;P&gt;Glad to have helped…cheers !!!&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 23:02:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11958388#M36465</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2023-05-11T23:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Put all Xrefs on a locked layer "C-XREF"</title>
      <link>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11958496#M36466</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1055426"&gt;@jayhar&lt;/a&gt;&amp;nbsp;if you're going to use Chat GPT to write your code, at least test it to make sure it works and makes sense before positing it &lt;span class="lia-unicode-emoji" title=":winking_face_with_tongue:"&gt;😜&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 00:33:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-forum/put-all-xrefs-on-a-locked-layer-quot-c-xref-quot/m-p/11958496#M36466</guid>
      <dc:creator>autocadet01liams</dc:creator>
      <dc:date>2023-05-12T00:33:49Z</dc:date>
    </item>
  </channel>
</rss>

