Code Red > .NET

UpdateScreen ...Proof of concept

(1/3) > >>

kdub_nz:
Placeholder
Refer : https://forums.autodesk.com/t5/net/show-and-hide-layers-using-c-net/m-p/8818781#M62708
Video .MP4 Attached + Piccys

added kdub:
Source attached in Post Reply #4




kdub_nz:
The aim was to demonstrate that Editor.UpdateScreen() Worked in a manner required by the OP

Commands Code

--- Code - C#: ---// (C) Copyright 2019 by kdub//using System;using System.Collections.Generic;using System.Linq;using System.Text;using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.Colors;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.Runtime; using Exception = System.Exception;using cadApp = Autodesk.AutoCAD.ApplicationServices.Application; [assembly: ExtensionApplication(typeof(TestDialog0615.Initialization))][assembly: CommandClass(typeof(TestDialog0615.Commands))] namespace TestDialog0615{    public class Commands    {        [CommandMethod("TEST")]        public void Test()        {            SetupForTest();             SetupDialog();        }         private static void SetupDialog()        {            using (var dialog = new ModalDialog())            {                var showResult = cadApp.ShowModalDialog(dialog);                if (showResult == System.Windows.Forms.DialogResult.OK)                {                    cadApp.ShowAlertDialog("All Good");                }            }        }          private static void SetupForTest()        {            dynamic layerTable = Active.Database.LayerTableId;            string layerName = "RedStuff";            if (!layerTable.Has(layerName))            {                Active.Database.CreateLayer(layerName, Color.FromColorIndex(ColorMethod.ByAci, 1));            }             layerName = "GreenStuff";            if (!layerTable.Has(layerName))            {                Active.Database.CreateLayer(layerName, Color.FromColorIndex(ColorMethod.ByAci, 3));            }             layerName = "BlueStuff";            if (!layerTable.Has(layerName))            {                Active.Database.CreateLayer(layerName, Color.FromColorIndex(ColorMethod.ByAci, 5));            }             CreateSomeCquircles();        }        private static void CreateSomeCquircles()        {            Active.Database.UsingModelSpace(                (tr, ms) =>                {                    var rnd = new Random(DateTime.Now.Second);                    string layerName;                    for (int i = 0; i < 60; i++)                    {                        var x = rnd.NextDouble() * 125;                        var y = rnd.NextDouble() * 100;                        var r = rnd.NextDouble() * 25;                         if (i > 40) layerName = "RedStuff";                        else if (i > 20) layerName = "GreenStuff";                        else layerName = "BlueStuff";                         ms.Create<Circle>(                            tr, circle =>                            {                                circle.Center = new Point3d(x, y, 0.0);                                circle.Radius = r;                                circle.Layer = layerName;                            });                    }                });        }     }      //=====================================================     public class Initialization : IExtensionApplication    {        public void Initialize()        {            cadApp.Idle += OnIdle;        }         private void OnIdle(object sender, EventArgs e)        {            if (Active.Document != null)            {                cadApp.Idle -= OnIdle;                Active.WriteMessage("\nTestDialog0615 loaded.\n");                Active.WriteMessage("Enter \"TEST\" at the CommandLine.\n");            }        }         public void Terminate()        { }    }}  


Dialog Code

--- Code - C#: ---using System;using System.Windows.Forms;using Autodesk.AutoCAD.DatabaseServices;using cadApp = Autodesk.AutoCAD.ApplicationServices.Application;  namespace TestDialog0615{    public partial class ModalDialog : Form    {        public ModalDialog()        {            InitializeComponent();        }         private void ModalDialog_Load(object sender, EventArgs e)        {         }            private void CbRed_CheckedChanged(object sender, EventArgs e)        {            if (cbRed.Checked)            {                TurnLayerOnOff("RedStuff", true);                textBox.Text = "Red Checked";                Active.Editor.UpdateScreen();            }            else            {                TurnLayerOnOff("RedStuff", false);                textBox.Text = "Red Unchecked";                Active.Editor.UpdateScreen();            }        }         private void CbGreen_CheckedChanged(object sender, EventArgs e)        {            if (cbGreen.Checked)            {                TurnLayerOnOff("GreenStuff", true);                textBox.Text = "Green Checked";                Active.Editor.UpdateScreen();            }            else            {                TurnLayerOnOff("GreenStuff", false);                textBox.Text = "Green Unchecked";                Active.Editor.UpdateScreen();            }        }         private void CbBlue_CheckedChanged(object sender, EventArgs e)        {            if (cbBlue.Checked)            {                TurnLayerOnOff("BlueStuff", true);                textBox.Text = "Blue Checked";                Active.Editor.UpdateScreen();            }            else            {                TurnLayerOnOff("BlueStuff", false);                textBox.Text = "Blue Unchecked";                Active.Editor.UpdateScreen();            }        }         private void ButtonZoom_Click(object sender, EventArgs e)        {            //Call the COM library            dynamic acadApp = cadApp.AcadApplication;            acadApp.ZoomExtents();            acadApp.ZoomScaled(0.75, 1);        }         // should not be in the Dialog Stuff; move to control file :kdub        // and change to use delegates        private  void TurnLayerOnOff(            string layerName, bool isOffp)        {            using (var tr = Active.Database.TransactionManager.StartTransaction())            {                var layerTable = tr.GetObject(                    Active.Database.LayerTableId, OpenMode.ForRead) as LayerTable;                if (layerTable != null)                {                    if (layerTable.Has(layerName))                    {                        var layerTableRecord = tr.GetObject(                            layerTable[layerName], OpenMode.ForWrite) as LayerTableRecord;                        if (layerTableRecord != null)                        {                            layerTableRecord.IsOff = isOffp;                        }                    }                }                tr.Commit();            }        }    }}  

gile:
Hi Kerry,

The code you provided uses static properties of an Active class and some Extension methods you do not show.
I think a 'proof of concept' should be testable by anyone 'as is' (but may be I'm wrong).

kdub_nz:

Hi Gilles

The main issue was the Editor.UpdateScreen() working when there was no user access to more than the dialog.
More than anything I wanted to confirm my understanding.

I'll package the Solution and post it.

Regards


kdub_nz:

Attached are the source files and solution .

I build with VS 2019 for ACAD 2020 on WIN 10 64bit
ObjectARX SDK is D:\ObjectARX 2020

Enjoy


Navigation

[0] Message Index

[#] Next page

Go to full version