Можно ли средствами .NET эмулировать команду VIEWBASE?

Автор Тема: Можно ли средствами .NET эмулировать команду VIEWBASE?  (Прочитано 10745 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Оффлайн Александр РивилисАвтор темы

  • Administrator
  • *****
  • Сообщений: 13898
  • Карма: 1790
  • Рыцарь ObjectARX
  • Skype: rivilis
Получил письмо с темой "Реализация команды VIEWBASE" и вопросом:
Цитировать
Здравствуйте!
Подскажите как программно вставить на лист 2D вид из 3D модели в AutoCAD 2014, на .NET?
Ответ который дал Balaji Ramamoorthy (член команды ADN DevTech):
Цитировать
Объекты "Вид чертежа" ("Drawing View") на данный момент не  доступны ни через один из API. В данный момент с помощью API можно лишь получать информацию о видах и создавать и редактировать видовые стили.

Так что пока увы...
Не забывайте про правильное Форматирование кода на форуме
Создание и добавление Autodesk Screencast видео в сообщение на форуме
Если Вы задали вопрос и на форуме появился правильный ответ, то не забудьте про кнопку Решение

Оффлайн Алексей Кириллов

  • ADN OPEN
  • Сообщений: 2
  • Карма: 0
Можно вот код:
Код - C# [Выбрать]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Runtime;
  5. using Autodesk.AutoCAD.Geometry;
  6. using System;
  7. [assembly: CommandClass(typeof(SolidSection.Commands))]
  8. namespace SolidSection
  9. {
  10.     public class Commands
  11.     {
  12.         [CommandMethod("SS")]
  13.         public void SectionSolid()
  14.         {
  15.             Document doc =
  16.               Application.DocumentManager.MdiActiveDocument;
  17.             Database db = doc.Database;
  18.             Editor ed = doc.Editor;
  19.  
  20.             // Ask the user to select an entity to section
  21.  
  22.             PromptEntityOptions peo =
  23.               new PromptEntityOptions(
  24.                 "\nSelect entity to section: "
  25.               );
  26.  
  27.             peo.SetRejectMessage(
  28.               "\nEntity must be a 3D solid, " +
  29.               "surface, body or region."
  30.             );
  31.             peo.AddAllowedClass(typeof(Solid3d), false);
  32.             peo.AddAllowedClass(
  33.               typeof(Autodesk.AutoCAD.DatabaseServices.Surface),
  34.               false
  35.             );
  36.             peo.AddAllowedClass(typeof(Body), false);
  37.             peo.AddAllowedClass(typeof(Region), false);
  38.  
  39.             PromptEntityResult per =
  40.               ed.GetEntity(peo);
  41.  
  42.             if (per.Status != PromptStatus.OK)
  43.                 return;
  44.  
  45.             ObjectId entId =
  46.               per.ObjectId;
  47.  
  48.             // Ask the user to define a section plane
  49.  
  50.             Point3dCollection pts =
  51.               new Point3dCollection();
  52.  
  53.             PromptPointResult ppr =
  54.               ed.GetPoint("\nPick first point for section: ");
  55.  
  56.             if (ppr.Status != PromptStatus.OK)
  57.                 return;
  58.  
  59.             pts.Add(ppr.Value);
  60.  
  61.             PromptPointOptions ppo =
  62.               new PromptPointOptions(
  63.                 "\nPick end point for section: "
  64.               );
  65.             ppo.BasePoint = ppr.Value;
  66.             ppo.UseBasePoint = true;
  67.  
  68.             ppr =
  69.               ed.GetPoint(ppo);
  70.  
  71.             if (ppr.Status != PromptStatus.OK)
  72.                 return;
  73.  
  74.             pts.Add(ppr.Value);
  75.  
  76.             // Ask what type of section to create
  77.  
  78.             PromptKeywordOptions pko =
  79.               new PromptKeywordOptions(
  80.                 "Enter section type "
  81.               );
  82.             pko.AllowNone = true;
  83.             pko.Keywords.Add("2D");
  84.             pko.Keywords.Add("3D");
  85.             pko.Keywords.Add("Live");
  86.             pko.Keywords.Default = "3D";
  87.  
  88.             PromptResult pkr =
  89.               ed.GetKeywords(pko);
  90.  
  91.             if (pkr.Status != PromptStatus.OK)
  92.                 return;
  93.  
  94.             SectionType st;
  95.             if (pkr.StringResult == "2D")
  96.                 st = SectionType.Section2d;
  97.             else if (pkr.StringResult == "Live")
  98.                 st = SectionType.LiveSection;
  99.             else // pkr.StringResult == "3D"
  100.                 st = SectionType.Section3d;
  101.  
  102.             // Now we're ready to do the real work
  103.  
  104.             Transaction tr =
  105.               db.TransactionManager.StartTransaction();
  106.             using (tr)
  107.             {
  108.                 try
  109.                 {
  110.                     BlockTable bt =
  111.                       (BlockTable)tr.GetObject(
  112.                         db.BlockTableId,
  113.                         OpenMode.ForRead
  114.                       );
  115.                     BlockTableRecord ms =
  116.                       (BlockTableRecord)tr.GetObject(
  117.                         bt[BlockTableRecord.ModelSpace],
  118.                         OpenMode.ForWrite
  119.                       );
  120.  
  121.                     // Now let's create our section
  122.  
  123.                     Section sec =
  124.                       new Section(pts, Vector3d.ZAxis);
  125.                     sec.State = SectionState.Plane;
  126.  
  127.                     // The section must be added to the drawing
  128.  
  129.                     ObjectId secId =
  130.                       ms.AppendEntity(sec);
  131.                     tr.AddNewlyCreatedDBObject(sec, true);
  132.  
  133.                     // Set up some of its direct properties
  134.  
  135.                     sec.SetHeight(
  136.                       SectionHeight.HeightAboveSectionLine,
  137.                       3.0
  138.                     );
  139.                     sec.SetHeight(
  140.                       SectionHeight.HeightBelowSectionLine,
  141.                       1.0
  142.                     );
  143.  
  144.                     // ... and then its settings
  145.  
  146.                     SectionSettings ss =
  147.                       (SectionSettings)tr.GetObject(
  148.                         sec.Settings,
  149.                         OpenMode.ForWrite
  150.                       );
  151.  
  152.                     // Set our section type
  153.  
  154.                     ss.CurrentSectionType = st;
  155.  
  156.                     // We only set one additional option if "Live"
  157.  
  158.                     if (st == SectionType.LiveSection)
  159.                         //sec.EnableLiveSection(true);
  160.                         sec.IsLiveSectionEnabled = true;
  161.                     else
  162.                     {
  163.                         // Non-live (i.e. 2D or 3D) settings
  164.  
  165.                         ObjectIdCollection oic =
  166.                           new ObjectIdCollection();
  167.                         oic.Add(entId);
  168.  
  169.                         ss.SetSourceObjects(st, oic);
  170.  
  171.                         if (st == SectionType.Section2d)
  172.                         {
  173.                             // 2D-specific settings
  174.  
  175.                             ss.SetVisibility(
  176.                               st,
  177.                               SectionGeometry.BackgroundGeometry,
  178.                               true
  179.                             );
  180.                             ss.SetHiddenLine(
  181.                               st,
  182.                               SectionGeometry.BackgroundGeometry,
  183.                               false
  184.                             );
  185.                         }
  186.                         else if (st == SectionType.Section3d)
  187.                         {
  188.                             // 3D-specific settings
  189.  
  190.                             ss.SetVisibility(
  191.                               st,
  192.                               SectionGeometry.ForegroundGeometry,
  193.                               true
  194.                             );
  195.                         }
  196.  
  197.                         // Finish up the common 2D/3D settings
  198.  
  199.                         ss.SetGenerationOptions(
  200.                           st,
  201.                           SectionGeneration.SourceSelectedObjects |
  202.                           SectionGeneration.DestinationFile
  203.                         );
  204.                     }
  205.  
  206.                     // Open up the main entity
  207.  
  208.                     Entity ent =
  209.                       (Entity)tr.GetObject(
  210.                         entId,
  211.                         OpenMode.ForRead
  212.                       );
  213.  
  214.                     // Generate the section geometry
  215.  
  216.                     Array flEnts, bgEnts, fgEnts, ftEnts, ctEnts;
  217.                     sec.GenerateSectionGeometry(
  218.                       ent,
  219.                       out flEnts,
  220.                       out bgEnts,
  221.                       out fgEnts,
  222.                       out ftEnts,
  223.                       out ctEnts
  224.                     );
  225.  
  226.                     // Add the geometry to the modelspace
  227.                     // (start by combining the various arrays,
  228.                     // so we then have one loop, not four)
  229.  
  230.                     int numEnts =
  231.                       flEnts.Length + fgEnts.Length +
  232.                       bgEnts.Length + ftEnts.Length +
  233.                       ctEnts.Length;
  234.  
  235.                     // Create the appropriately-sized array
  236.  
  237.                     Array ents =
  238.                     Array.CreateInstance(
  239.                       typeof(Entity),
  240.                       numEnts
  241.                     );
  242.  
  243.                     // Copy across the contents of the
  244.                     // various arrays
  245.  
  246.                     int index = 0;
  247.                     flEnts.CopyTo(ents, index);
  248.                     index += flEnts.Length;
  249.                     fgEnts.CopyTo(ents, index);
  250.                     index += fgEnts.Length;
  251.                     bgEnts.CopyTo(ents, index);
  252.                     index += bgEnts.Length;
  253.                     ftEnts.CopyTo(ents, index);
  254.                     index += ftEnts.Length;
  255.                     ctEnts.CopyTo(ents, index);
  256.  
  257.                     // Our single loop to add entities
  258.  
  259.                     foreach (Entity ent2 in ents)
  260.                     {
  261.                         ms.AppendEntity(ent2);
  262.                         tr.AddNewlyCreatedDBObject(ent2, true);
  263.                     }
  264.  
  265.                     tr.Commit();
  266.                 }
  267.                 catch (System.Exception ex)
  268.                 {
  269.                     ed.WriteMessage(
  270.                       "\nException: " + ex.Message
  271.                     );
  272.                 }
  273.             }
  274.         }
  275.     }
  276. }

« Последнее редактирование: 11-12-2014, 09:32:26 от Александр Ривилис »

Оффлайн Александр РивилисАвтор темы

  • Administrator
  • *****
  • Сообщений: 13898
  • Карма: 1790
  • Рыцарь ObjectARX
  • Skype: rivilis
Насколько я понимаю виды и сечения - это разные вещи.
Не забывайте про правильное Форматирование кода на форуме
Создание и добавление Autodesk Screencast видео в сообщение на форуме
Если Вы задали вопрос и на форуме появился правильный ответ, то не забудьте про кнопку Решение

Оффлайн avc

  • ADN Club
  • *****
  • Сообщений: 839
  • Карма: 168
    • Мои плагины к Автокаду
С момента создания плагина ModelDoc (ViewBase) прошло десятилетие. Не изменилась ли ситуация? Может кто-то научился создавать виды ModelDoc из .Net ? И мне еще важнее - считывать информацию, о том какие объекты отображает вид, направление, масштаб. То есть настоящие параметры вида, а не ту обманку, которую выдает фальшивый вьюпорт, скрывающийся за этим видом. Неужели никто так и не нашел никаких обходных путей?