newer 发表于 2021-1-27 00:19:05

是否可以使用AutoCAD .NET API模拟命令LIVESECTION

Is it possible to emulate command LIVESECTION with AutoCAD .NET API

This question is coming from one of our beloved Forum contributor and Mentor Alexander Rivilis


I am working with code which change color of Intersection Fill of Live Section. But although the color is changed, but this is not visible on the screen until I turn off and turn LIVESECTION:
I made slight changes to have this working

Note: To work this make sure LIVESECTION is not turned on

This code will change color of SECTION which converted to LIVESECTION



public void SetSectionColor()
       {
          Document doc = Application.DocumentManager.MdiActiveDocument;
          if (doc == null) return;
          Editor ed = doc.Editor;

          PromptEntityOptions peo =
                new PromptEntityOptions("\nSelect section: ");
          peo.SetRejectMessage("\nIt is not a section!");
          peo.AddAllowedClass(typeof(Section), true);
          PromptEntityResult per = ed.GetEntity(peo);
          if (per.Status != PromptStatus.OK) return;
          ObjectId idSecSets = ObjectId.Null;
          using (Transaction tr =
          doc.TransactionManager.StartOpenCloseTransaction())
          {
            Section sec =
            tr.GetObject(per.ObjectId,
                           OpenMode.ForWrite) as Section;
            sec.IsLiveSectionEnabled = true;               
            idSecSets = sec.Settings;
            tr.Commit();
          }
      using (Transaction tr = doc.TransactionManager
                                     .StartOpenCloseTransaction())
      {
          SectionSettings secset = tr.GetObject(idSecSets,
                                 OpenMode.ForWrite) as SectionSettings;
          secset.CurrentSectionType = SectionType.LiveSection;
          Color clr = secset.Color(SectionType.LiveSection,
                                 SectionGeometry.IntersectionFill);
          ColorDialog cd = new ColorDialog
          {
            Color = clr
          };
          System.Windows.Forms.DialogResult dr = cd.ShowDialog();
          if (dr != System.Windows.Forms.DialogResult.OK) return;
          ed.WriteMessage("\nSelected Color: " + cd.Color.ToString());
          clr = cd.Color;
          // Define that color we change
          secset.SetColor(SectionType.LiveSection,
          SectionGeometry.IntersectionFill, clr);
          tr.Commit();
      }
    }

Gifhttps://adndevblog.typepad.com/.a/6a0167607c2431970b026bde95e17d200c-pi





页: [1]
查看完整版本: 是否可以使用AutoCAD .NET API模拟命令LIVESECTION