Author Topic: How can I get the Model's localized name from the Layout's viewport?  (Read 1552 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
The current space is the Layout's some viewport. How can I get the Model localized name? When the current space is the Model tab I can get the localized name through the CTAB system variable. But what about my case?

Code - C#: [Select]
  1. // SpaceEnum.cs
  2. // © Andrey Bushman, 2013
  3.  
  4. namespace Bushman.CAD.DatabaseServices {
  5.         /// <summary>
  6.         /// This enum indicates the current space in the current Database.
  7.         /// </summary>
  8.         public enum SpaceEnum {
  9.                 /// <summary>
  10.                 /// The Model space.
  11.                 /// </summary>
  12.                 Model,
  13.                 /// <summary>
  14.                 /// The Layout space.
  15.                 /// </summary>
  16.                 Layout,
  17.                 /// <summary>
  18.                 /// The Model space through the Layout's viewport.
  19.                 /// </summary>
  20.                 Viewport
  21.         }
  22. }

Below read the row 43, please:

Code - C#: [Select]
  1. // LayoutManagerExtensionMethods.cs
  2. // © Andrey Bushman, 2013
  3.  
  4. //Microsoft
  5. using System;
  6.  
  7. //Autodesk
  8. using cad = Autodesk.AutoCAD.ApplicationServices.Application;
  9. using Db = Autodesk.AutoCAD.DatabaseServices;
  10.  
  11. namespace Bushman.CAD.DatabaseServices {
  12.  
  13.         public static class LayoutManagerExtensionMethods {
  14.                 /// <summary>
  15.                 /// This is Extension Method for the <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c>
  16.                 /// class. It gets the current space in the current Database.
  17.                 /// </summary>
  18.                 /// <param name="mng">Target <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c> instance.</param>
  19.                 /// <returns>Returns the SpaceEnum value.</returns>            
  20.                 public static SpaceEnum GetCurrentSpaceEnum(this Db.LayoutManager mng) {
  21.                         Db.Database db = cad.DocumentManager.MdiActiveDocument.Database;
  22.                         Int16 tilemode = (Int16)cad.GetSystemVariable("TILEMODE");
  23.  
  24.                         if (tilemode == 1)
  25.                                 return SpaceEnum.Model;
  26.  
  27.                         Int16 cvport = (Int16)cad.GetSystemVariable("CVPORT");
  28.                         if (cvport == 1)
  29.                                 return SpaceEnum.Layout;
  30.                         else
  31.                                 return SpaceEnum.Viewport;
  32.                 }
  33.  
  34.                 /// <summary>
  35.                 /// This is Extension Method for the <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c>
  36.                 /// class. It gets the name of the current space in the current Database.
  37.                 /// </summary>
  38.                 /// <param name="mng">Target <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c> instance.</param>
  39.                 /// <returns>Returns the name of current space.</returns>
  40.                 public static String GetCurrentSpaceName(this Db.LayoutManager mng) {
  41.                         SpaceEnum space = GetCurrentSpaceEnum(mng);
  42.                         String result = space == SpaceEnum.Viewport ?
  43.                                 "Model" as String : mng.CurrentLayout; // TODO: I need to set the localized name of the Model space
  44.                         return result;
  45.                 }
  46.         }
  47. }

Thank you.
« Last Edit: December 24, 2013, 02:42:13 AM by Andrey Bushman »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: How can I get the Model's localized name from the Layout's viewport?
« Reply #1 on: December 24, 2013, 03:03:43 AM »
I solved my problem:

Code - C#: [Select]
  1. /// <summary>
  2. /// This is Extension Method for the <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c>
  3. /// class. It gets the name of the current space in the current Database.
  4. /// </summary>
  5. /// <param name="mng">Target <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c> instance.</param>
  6. /// <returns>Returns the name of current space.</returns>
  7. public static String GetCurrentSpaceName(this Db.LayoutManager mng) {
  8.         SpaceEnum space = GetCurrentSpaceEnum(mng);
  9.         Db.Database db = cad.DocumentManager.MdiActiveDocument.Database;
  10.         String modelSpaceLocalizedName = String.Empty;
  11.         using (Db.Transaction tr = db.TransactionManager.StartTransaction()) {
  12.                 Db.BlockTable bt = tr.GetObject(db.BlockTableId, Db.OpenMode.ForRead) as Db.BlockTable;
  13.                 Db.BlockTableRecord btr = tr.GetObject(bt[Db.BlockTableRecord.ModelSpace], Db.OpenMode.ForRead)
  14.                         as Db.BlockTableRecord;
  15.                 modelSpaceLocalizedName = (tr.GetObject(btr.LayoutId, Db.OpenMode.ForRead) as Db.Layout).LayoutName;
  16.         }
  17.         String result = space == SpaceEnum.Viewport ?
  18.                 modelSpaceLocalizedName as String : mng.CurrentLayout;
  19.         return result;
  20. }

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: How can I get the Model's localized name from the Layout's viewport?
« Reply #2 on: December 24, 2013, 03:14:45 AM »
I thought that in the AutoCAD localized versions the name of the Model tab and the 410 code's value are localized. I couldn't check. Now I learned that this value always is English. So this topic need to be deleted.

 :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How can I get the Model's localized name from the Layout's viewport?
« Reply #3 on: December 24, 2013, 03:26:13 AM »
Leave it here Andrey, it may be useful for others.
I was just going to post and ask what you meant by localised.
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.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: How can I get the Model's localized name from the Layout's viewport?
« Reply #4 on: December 24, 2013, 03:42:02 AM »
Quote from: AutoCAD Console
Command: (entget(car(entsel)))

Select object: ((-1 . <Entity name: 7ffffc03ef0>) (0 . "LWPOLYLINE") (330 .
<Entity name: 7ffffc03e50>) (5 . "6F") (100 . "AcDbEntity") (67 . 0) (410 .
"Model") (8 . "0") (100 . "AcDbPolyline") (90 . 5) (70 . 0) (43 . 0.0) (38 .
0.0) (39 . 0.0) (10 139.058 81.6326) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10
202.57 117.612) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 191.701 82.9903) (40 .
0.0) (41 . 0.0) (42 . 0.0) (10 239.93 107.09) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 250.991 84.9535) (40 . 0.0) (41 . 0.0) (42 . 0.0) (210 0.0 0.0 1.0))
I was afraid that this value can be localized.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How can I get the Model's localized name from the Layout's viewport?
« Reply #5 on: December 24, 2013, 03:56:46 AM »
Ahhhhh ... I understand.
Thanks :)

added for fun.
something like "модель"
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.