<?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: Setting and accessing USERS1 variable in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/setting-and-accessing-users1-variable/m-p/13397405#M604</link>
    <description>&lt;P&gt;Thank you both for your responses. May be I was doing something incorrect earlier as your code works just fine.&lt;/P&gt;</description>
    <pubDate>Sat, 29 Mar 2025 07:07:18 GMT</pubDate>
    <dc:creator>thilak.rao</dc:creator>
    <dc:date>2025-03-29T07:07:18Z</dc:date>
    <item>
      <title>Setting and accessing USERS1 variable</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-and-accessing-users1-variable/m-p/13363286#M601</link>
      <description>&lt;P&gt;Here is something interesting that I thought I knew well for decades.&lt;/P&gt;&lt;P&gt;I thought USERS1 is a setvar that can be set and accessed. This is true as long as I am in the same&amp;nbsp; API context, meaning if I am using COM (ActiveX) then this is set and returned in a document context. If I am using .Net then it can only be set using Application.SetSystemVariable and accessed using Application.GetSystemVariable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My situation is that I want to set this in .Net using&amp;nbsp;Application.SetSystemVariable and access it from COM that is out of process. I am unable to get the desired value here. Can someone shed more light on these USERS1 variables and the context it is created?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I know USERS1 is not saved anywhere and is temporary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-Thilak Rao&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 02:26:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-and-accessing-users1-variable/m-p/13363286#M601</guid>
      <dc:creator>TK_Rao5AR2</dc:creator>
      <dc:date>2025-03-11T02:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Setting and accessing USERS1 variable</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-and-accessing-users1-variable/m-p/13369259#M602</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17050962"&gt;@TK_Rao5AR2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;My situation is that I want to set this in .Net using&amp;nbsp;Application.SetSystemVariable and access it from COM that is out of process. I am unable to get the desired value here. Can someone shed more light on these USERS1 variables and the context it is created?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: I know USERS1 is not saved anywhere and is temporary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;-Thilak Rao&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You did not describe how you are "...unable to get desired value...". However, the knowledge you knew well for decades still remains true: there is only one value of each USERSx variable, regardless how its value being set (manually at command line, with code of different APIs of LISP/COM/.NET), or where it is accessed to (from in-process, or out-process).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I took a bit of time to write some simply code and recorded the code execution in video clip to prove it here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a console app that uses AutoCAD COM API to get AutoCAD's USERS1 value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AcadComAutomationApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Do you want to start an AutoCAD session? (Y/N):");
            var an = Console.ReadLine();
            if (!an.ToUpper().StartsWith("Y")) return;

            var comAcad = new Autodesk.AutoCAD.Interop.AcadApplication();
            comAcad.Visible = true;
            while(true)
            {
                if (comAcad.ActiveDocument!=null)
                {
                    var users1 = comAcad.ActiveDocument.GetVariable("USERS1").ToString();
                    Console.WriteLine($"System variable \"USERS1\" -&amp;gt; {users1}");
                    Console.WriteLine("Press any key to get value again, \"X\" to quit:");
                    an = Console.ReadLine();
                    if (an.ToUpper().StartsWith("X"))
                    {
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("\nNo drawing is opened in AutoCAD.");
                    Console.WriteLine("Preaa any key toopen a new/existing drawing in AutoCAD");
                    Console.WriteLine("Or press \"X\" to quit:");
                    an = Console.ReadLine();
                    if (an.ToUpper().StartsWith("X"))
                    {
                        break;
                    }
                }
            }
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a simple .NET plugin's CommandMethod that set USERS1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("SetUserS1")]
        public static void SetUserS1Variable()
        {
            var dwg = CadApp.DocumentManager.MdiActiveDocument;
            var ed = dwg.Editor;

            var res = ed.GetString("\nEnter value for \"USERS1\":");
            if (res.Status == PromptStatus.OK)
            {
                CadApp.SetSystemVariable("USERS1", res.StringResult);
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is how to run the code to prove USERS1 value is the same when accessed from the out-process (the console app) regardless how it is set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Start the console app, which would start a new AutoCAD session;&lt;/P&gt;
&lt;P&gt;2. In AutoCAD command line. enter "USERS1" to set its value manually;&lt;/P&gt;
&lt;P&gt;3. Go back to the console app, press any key to read "USERS1" value from AutoCAD;&lt;/P&gt;
&lt;P&gt;4. Go back to AutoCAD, load the .NET plugin and run command "SetUserS1" to set a new value to "USERS1";&lt;/P&gt;
&lt;P&gt;5. Go back to the console app, press any key to read "USERS1" value again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see that regardless how the value is set - manually, or by .NET API, the out-process app always get the latest USERS1 value, as expected. If your code does not get the "desired value", it is something wrong with your code, for sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To further prove what I described, see the video clip here:&lt;/P&gt;
&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6369972778112w998h540r140" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6369972778112" data-account="6057940548001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6057940548001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6369972778112w998h540r140');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://forums.autodesk.com/t5/video/gallerypage/video-id/6369972778112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2025 15:33:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-and-accessing-users1-variable/m-p/13369259#M602</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2025-03-13T15:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: Setting and accessing USERS1 variable</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-and-accessing-users1-variable/m-p/13369910#M603</link>
      <description>&lt;P&gt;I'm assuming that you are aware that USERSx system variables have document scope, and therefore have a different value for each document. So, the value assigned or returned is always the value associated with the active document.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2025 21:00:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-and-accessing-users1-variable/m-p/13369910#M603</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2025-03-13T21:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: Setting and accessing USERS1 variable</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-and-accessing-users1-variable/m-p/13397405#M604</link>
      <description>&lt;P&gt;Thank you both for your responses. May be I was doing something incorrect earlier as your code works just fine.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Mar 2025 07:07:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-and-accessing-users1-variable/m-p/13397405#M604</guid>
      <dc:creator>thilak.rao</dc:creator>
      <dc:date>2025-03-29T07:07:18Z</dc:date>
    </item>
  </channel>
</rss>

