Author Topic: Switching back to the original view after creating a UCS.  (Read 2340 times)

0 Members and 1 Guest are viewing this topic.

tik

  • Guest
Switching back to the original view after creating a UCS.
« on: December 16, 2011, 01:24:28 PM »
I am creating a new UCS and aligning it to the line that user picks in the drawing. For picking the line I am setting the coordinate system to be WCS and after picking the link I am creating a new UCS and setting it to current.

For example if the user picks the line in the SW Isometric View, I see that my command is creating the new UCS and setting it to current but instead of going back to SW Isometric View it is setting to Top View.

What do I need to do to set it back to the original view.

Thanks in advance.

Following is the code I am using to Create the UCS and Make it current and I am not doing any thing to change the views.

Code - C#: [Select]
  1. public static void CreateUCS(string ucsName, double[] origin, double[] xAxis, double[] yAxis, bool makeCurrent)
  2.         {
  3.             // Get the current document and database, and start a transaction
  4.             Document acDoc = AQME_ACAD.AQMEACADInstance.ActiveDocument;
  5.             Database acCurDb = acDoc.Database;
  6.             using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  7.             {
  8.                 using (DocumentLock dl = AQME_ACAD.AQMEACADInstance.ActiveDocument.LockDocument())
  9.                 {
  10.                     // Open the UCS table for read
  11.                     UcsTable acUCSTbl;
  12.                     acUCSTbl = acTrans.GetObject(acCurDb.UcsTableId, OpenMode.ForWrite) as UcsTable;
  13.                     UcsTableRecord acUCSTblRec;
  14.                     // Check to see if the ucsName UCS table record exists
  15.                     if (acUCSTbl.Has(ucsName) == false)
  16.                     {
  17.                         acUCSTblRec = new UcsTableRecord();
  18.                         acUCSTblRec.Name = ucsName;
  19.                         acUCSTbl.Add(acUCSTblRec);
  20.                         acTrans.AddNewlyCreatedDBObject(acUCSTblRec, true);
  21.                     }
  22.                     else
  23.                     {
  24.                         acUCSTblRec = acTrans.GetObject(acUCSTbl[ucsName], OpenMode.ForWrite) as UcsTableRecord;
  25.                     }
  26.                     acUCSTblRec.Origin = new Point3d(origin);
  27.                     //calulate vector between two points
  28.                     Point3d origin1 = new Point3d(origin);
  29.                     Point3d xPoint = new Point3d(xAxis);
  30.                     Point3d yPoint = new Point3d(yAxis);
  31.  
  32.                     Vector3d vectx = origin1.GetVectorTo(xPoint);
  33.                     Vector3d vecty = origin1.GetVectorTo(yPoint);
  34.  
  35.                     acUCSTblRec.XAxis = vectx;
  36.                     acUCSTblRec.YAxis = vecty;
  37.                     acTrans.Commit();
  38.                 }
  39.             }
  40.  
  41.             if (makeCurrent == true)
  42.             {
  43.                 using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  44.                 {
  45.                     using (DocumentLock dl = AQME_ACAD.AQMEACADInstance.ActiveDocument.LockDocument())
  46.                     {
  47.                          // Open the UCS table for read
  48.                          UcsTable acUCSTbl;
  49.                         acUCSTbl = acTrans.GetObject(acCurDb.UcsTableId, OpenMode.ForWrite) as UcsTable;
  50.                         UcsTableRecord acUCSTblRec;
  51.                         // Check to see if the ucsName UCS table record exists
  52.                         if (acUCSTbl.Has(ucsName) == true)
  53.                         {
  54.                             acUCSTblRec = acTrans.GetObject(acUCSTbl[ucsName], OpenMode.ForWrite) as UcsTableRecord;
  55.                             // call the set tolerances method to set the tolerances.                        
  56.                             // Open the active viewport
  57.                              ViewportTableRecord acVportTblRec;
  58.                              acVportTblRec = acTrans.GetObject(acDoc.Editor.ActiveViewportId, OpenMode.ForWrite) as ViewportTableRecord;
  59.                                // Display the UCS Icon at the origin of the current viewport
  60.                                 acVportTblRec.IconAtOrigin = true;
  61.                                 acVportTblRec.IconEnabled = true;
  62.                                 // Set the UCS current
  63.                                 acVportTblRec.SetUcs(acUCSTblRec.ObjectId);
  64.                                 acDoc.Editor.UpdateTiledViewportsFromDatabase();
  65.                                 acTrans.Commit();
  66.                             }
  67.                     }
  68.                 }
  69.             }
  70.         }
  71.  

edit kdub: code tags addd
« Last Edit: December 18, 2011, 01:59:05 AM by Kerry »

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Switching back to the original view after creating a UCS.
« Reply #1 on: December 16, 2011, 07:25:54 PM »
Before code
    ViewTableRecord CurrentVtr = ed.GetCurrentView();

end of code
acDoc.Editor.SetCurrentView(CurrentVtr);

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Switching back to the original view after creating a UCS.
« Reply #2 on: December 19, 2011, 08:04:08 AM »
This also works:
Code: [Select]
Matrix3d olducs = ed.CurrentUserCoordinateSystem;

......

ed.CurrentUserCoordinateSystem = olducs;
Revit 2019, AMEP 2019 64bit Win 10

tik

  • Guest
Re: Switching back to the original view after creating a UCS.
« Reply #3 on: December 19, 2011, 09:34:36 AM »
Bryco, MexicanCustard,

Thanks for the suggestions. I will give them a try.

tik.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Switching back to the original view after creating a UCS.
« Reply #4 on: December 20, 2011, 03:52:49 AM »

Can you satisfy my curiosity please ?

What is
AQME_ACAD
and
AQME_ACAD.AQMEACADInstance

Regards
kdub
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

tik

  • Guest
Re: Switching back to the original view after creating a UCS.
« Reply #5 on: December 20, 2011, 02:20:49 PM »
Hi Kerry,

AQME_ACAD is a wrapper class I wrote for the CAD Interactions, I want to have singleton object for my CAD interactions.

tik.