<?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: How to change UCS for model space inside viewport ? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/13341276#M10168</link>
    <description>&lt;P&gt;Wow thanks Mr. Chanteau!&amp;nbsp; So fast a response!&lt;/P&gt;</description>
    <pubDate>Wed, 26 Feb 2025 15:39:09 GMT</pubDate>
    <dc:creator>ivanstarr3</dc:creator>
    <dc:date>2025-02-26T15:39:09Z</dc:date>
    <item>
      <title>How to change UCS for model space inside viewport ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/11713518#M10162</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Currently, I want to change UCS of model space in viewport but don't know how to do.&lt;/P&gt;&lt;P&gt;I found the method&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;.SetUcs()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;but it's not working.&lt;/P&gt;&lt;P&gt;Does anyone knows to do it, please advise me.&lt;/P&gt;&lt;P&gt;Thanks and Regards.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nghiabt04_0-1674983379774.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1168621i734EE3F9191DDF6B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nghiabt04_0-1674983379774.png" alt="nghiabt04_0-1674983379774.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jan 2023 09:11:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/11713518#M10162</guid>
      <dc:creator>nghiabt04</dc:creator>
      <dc:date>2023-01-29T09:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to change UCS for model space inside viewport ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/11713661#M10163</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The Viewport type has a &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_Viewport_Ucs" target="_blank" rel="noopener"&gt;Ucs&lt;/A&gt; read/write property.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jan 2023 12:13:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/11713661#M10163</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-01-29T12:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to change UCS for model space inside viewport ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/11715040#M10164</link>
      <description>Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;,&lt;BR /&gt;I also try this but see nothing change.</description>
      <pubDate>Mon, 30 Jan 2023 08:30:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/11715040#M10164</guid>
      <dc:creator>nghiabt04</dc:creator>
      <dc:date>2023-01-30T08:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to change UCS for model space inside viewport ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/11716059#M10165</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Most often when dealing with viewport, we need to swich them off and on to update the changes.&lt;/P&gt;
&lt;P&gt;Try this way:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;vp.On = false;
vp.Ucs = ucs;
vp.On = true;&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 30 Jan 2023 16:00:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/11716059#M10165</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-01-30T16:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to change UCS for model space inside viewport ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/13340746#M10166</link>
      <description>&lt;P&gt;I'm also having the same problem but in pure model space (tilemode=1).&amp;nbsp; Also, after including the code in my project, the plugin made autocad run very slow.&amp;nbsp; very strange.&amp;nbsp; I will include the code below.&amp;nbsp; Thanks in advance Mr. Chanteau, or whoever else helps!&amp;nbsp; Also, how do I create that code window that you have your code example in above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using System;&lt;BR /&gt;using Autodesk.AutoCAD.Runtime;&lt;BR /&gt;using Autodesk.AutoCAD.ApplicationServices;&lt;BR /&gt;using Autodesk.AutoCAD.DatabaseServices;&lt;BR /&gt;using Autodesk.AutoCAD.EditorInput;&lt;BR /&gt;using Autodesk.AutoCAD.Geometry;&lt;/P&gt;&lt;P&gt;namespace ArchitecturalWindows&lt;BR /&gt;{&lt;BR /&gt;public class UCSCommands&lt;BR /&gt;{&lt;BR /&gt;private static ObjectId previousUcsId = ObjectId.Null; // Store the previous UCS ObjectId&lt;BR /&gt;private static bool wasWorldUCS = true; // Track if the previous UCS was World UCS&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;public static void SetNewUCS()&lt;BR /&gt;{&lt;BR /&gt;Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database db = doc.Database;&lt;BR /&gt;Editor ed = doc.Editor;&lt;/P&gt;&lt;P&gt;using (Transaction tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;// Get the UCS table&lt;BR /&gt;UcsTable ucsTable = tr.GetObject(db.UcsTableId, OpenMode.ForRead) as UcsTable;&lt;/P&gt;&lt;P&gt;// Get the current viewport settings&lt;BR /&gt;ObjectId viewportId = db.CurrentViewportTableRecordId;&lt;BR /&gt;ViewportTableRecord vpRecord = tr.GetObject(viewportId, OpenMode.ForWrite) as ViewportTableRecord;&lt;BR /&gt;previousUcsId = vpRecord.UcsName;&lt;BR /&gt;// Store the current UCS&lt;BR /&gt;if (ucsTable.Has(vpRecord.UcsName))&lt;BR /&gt;{&lt;BR /&gt;previousUcsId = vpRecord.UcsName;&lt;BR /&gt;wasWorldUCS = false;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;previousUcsId = ObjectId.Null;&lt;BR /&gt;wasWorldUCS = true;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Define a new UCS&lt;BR /&gt;string ucsName = "MyNewUCS";&lt;BR /&gt;UcsTableRecord newUcs;&lt;/P&gt;&lt;P&gt;if (ucsTable.Has(ucsName))&lt;BR /&gt;{&lt;BR /&gt;newUcs = tr.GetObject(ucsTable[ucsName], OpenMode.ForRead) as UcsTableRecord;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;ucsTable.UpgradeOpen();&lt;BR /&gt;newUcs = new UcsTableRecord&lt;BR /&gt;{&lt;BR /&gt;Name = ucsName,&lt;BR /&gt;Origin = new Point3d(10, 10, 0), // Example new origin&lt;BR /&gt;XAxis = new Vector3d(0, 0, 1),&lt;BR /&gt;YAxis = new Vector3d(0, 1, 0)&lt;BR /&gt;};&lt;BR /&gt;ucsTable.Add(newUcs);&lt;BR /&gt;tr.AddNewlyCreatedDBObject(newUcs, true);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Set the new UCS to the viewport&lt;BR /&gt;vpRecord.SetUcs(newUcs.ObjectId);&lt;BR /&gt;vpRecord.UcsSavedWithViewport = true; // Mark UCS as saved with this viewport&lt;/P&gt;&lt;P&gt;tr.Commit();&lt;BR /&gt;ed.WriteMessage("\nNew UCS set as current.");&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 12:29:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/13340746#M10166</guid>
      <dc:creator>ivanstarr3</dc:creator>
      <dc:date>2025-02-26T12:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to change UCS for model space inside viewport ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/13340976#M10167</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The Database.CurrentViewportTableRecordId property is not reliable because it does not update correctly.&lt;/P&gt;
&lt;P&gt;To set a new UCS in the current viewport, you can simply set the Editor.CurrentCoordinateSystem property.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;public static void SetUCS(Point3d origin, Vector3d xAxis, Vector3d yAxis)
{
    var zAxis = xAxis.CrossProduct(yAxis);
    Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem = 
        Matrix3d.AlignCoordinateSystem(
            Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
            origin, xAxis.GetNormal(), yAxis.GetNormal(), zAxis.GetNormal());
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8651675"&gt;@ivanstarr3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Also, how do I create that code window that you have your code example in above?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;1. Hit the "Expand toolbar" button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_gile_0-1740577017437.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1471568i5DA5FF92DF9ECFEE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_gile_0-1740577017437.png" alt="_gile_0-1740577017437.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;2. Hit the "Insert/Edit code sample" button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_gile_1-1740577149077.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1471571iA86E8E016BEC7571/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_gile_1-1740577149077.png" alt="_gile_1-1740577149077.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;3. Choose the language and past the code:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_gile_2-1740577249111.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1471576i74F63D4A6BE89B09/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_gile_2-1740577249111.png" alt="_gile_2-1740577249111.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 13:41:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/13340976#M10167</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-02-26T13:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to change UCS for model space inside viewport ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/13341276#M10168</link>
      <description>&lt;P&gt;Wow thanks Mr. Chanteau!&amp;nbsp; So fast a response!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 15:39:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-change-ucs-for-model-space-inside-viewport/m-p/13341276#M10168</guid>
      <dc:creator>ivanstarr3</dc:creator>
      <dc:date>2025-02-26T15:39:09Z</dc:date>
    </item>
  </channel>
</rss>

