Author Topic: UpdateScreen ...Proof of concept  (Read 514 times)

0 Members and 1 Guest are viewing this topic.

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1368
  • class keyThumper<T>:ILazy<T>
UpdateScreen ...Proof of concept
« on: June 15, 2019, 11:09:30 PM »
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




« Last Edit: June 16, 2019, 04:44:01 AM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1368
  • class keyThumper<T>:ILazy<T>
Re: UpdateScreen ...Proof of concept
« Reply #1 on: June 15, 2019, 11:20:39 PM »
The aim was to demonstrate that Editor.UpdateScreen() Worked in a manner required by the OP

Commands Code
Code - C#: [Select]
  1. // (C) Copyright 2019 by kdub
  2. //
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using Autodesk.AutoCAD.ApplicationServices;
  8. using Autodesk.AutoCAD.Colors;
  9. using Autodesk.AutoCAD.DatabaseServices;
  10. using Autodesk.AutoCAD.EditorInput;
  11. using Autodesk.AutoCAD.Geometry;
  12. using Autodesk.AutoCAD.Runtime;
  13.  
  14. using Exception = System.Exception;
  15. using cadApp = Autodesk.AutoCAD.ApplicationServices.Application;
  16.  
  17. [assembly: ExtensionApplication(typeof(TestDialog0615.Initialization))]
  18. [assembly: CommandClass(typeof(TestDialog0615.Commands))]
  19.  
  20. namespace TestDialog0615
  21. {
  22.     public class Commands
  23.     {
  24.         [CommandMethod("TEST")]
  25.         public void Test()
  26.         {
  27.             SetupForTest();
  28.  
  29.             SetupDialog();
  30.         }
  31.  
  32.         private static void SetupDialog()
  33.         {
  34.             using (var dialog = new ModalDialog())
  35.             {
  36.                 var showResult = cadApp.ShowModalDialog(dialog);
  37.                 if (showResult == System.Windows.Forms.DialogResult.OK)
  38.                 {
  39.                     cadApp.ShowAlertDialog("All Good");
  40.                 }
  41.             }
  42.         }
  43.  
  44.  
  45.         private static void SetupForTest()
  46.         {
  47.             dynamic layerTable = Active.Database.LayerTableId;
  48.             string layerName = "RedStuff";
  49.             if (!layerTable.Has(layerName))
  50.             {
  51.                 Active.Database.CreateLayer(layerName, Color.FromColorIndex(ColorMethod.ByAci, 1));
  52.             }
  53.  
  54.             layerName = "GreenStuff";
  55.             if (!layerTable.Has(layerName))
  56.             {
  57.                 Active.Database.CreateLayer(layerName, Color.FromColorIndex(ColorMethod.ByAci, 3));
  58.             }
  59.  
  60.             layerName = "BlueStuff";
  61.             if (!layerTable.Has(layerName))
  62.             {
  63.                 Active.Database.CreateLayer(layerName, Color.FromColorIndex(ColorMethod.ByAci, 5));
  64.             }
  65.  
  66.             CreateSomeCquircles();
  67.         }
  68.         private static void CreateSomeCquircles()
  69.         {
  70.             Active.Database.UsingModelSpace(
  71.                 (tr, ms) =>
  72.                 {
  73.                     var rnd = new Random(DateTime.Now.Second);
  74.                     string layerName;
  75.                     for (int i = 0; i < 60; i++)
  76.                     {
  77.                         var x = rnd.NextDouble() * 125;
  78.                         var y = rnd.NextDouble() * 100;
  79.                         var r = rnd.NextDouble() * 25;
  80.  
  81.                         if (i > 40) layerName = "RedStuff";
  82.                         else if (i > 20) layerName = "GreenStuff";
  83.                         else layerName = "BlueStuff";
  84.  
  85.                         ms.Create<Circle>(
  86.                             tr, circle =>
  87.                             {
  88.                                 circle.Center = new Point3d(x, y, 0.0);
  89.                                 circle.Radius = r;
  90.                                 circle.Layer = layerName;
  91.                             });
  92.                     }
  93.                 });
  94.         }
  95.     }
  96.  
  97.  
  98.     //=====================================================
  99.  
  100.     public class Initialization : IExtensionApplication
  101.     {
  102.         public void Initialize()
  103.         {
  104.             cadApp.Idle += OnIdle;
  105.         }
  106.  
  107.         private void OnIdle(object sender, EventArgs e)
  108.         {
  109.             if (Active.Document != null)
  110.             {
  111.                 cadApp.Idle -= OnIdle;
  112.                 Active.WriteMessage("\nTestDialog0615 loaded.\n");
  113.                 Active.WriteMessage("Enter \"TEST\" at the CommandLine.\n");
  114.             }
  115.         }
  116.  
  117.         public void Terminate()
  118.         { }
  119.     }
  120. }
  121.  
  122.  



Dialog Code
Code - C#: [Select]
  1. using System;
  2. using System.Windows.Forms;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using cadApp = Autodesk.AutoCAD.ApplicationServices.Application;
  5.  
  6.  
  7. namespace TestDialog0615
  8. {
  9.     public partial class ModalDialog : Form
  10.     {
  11.         public ModalDialog()
  12.         {
  13.             InitializeComponent();
  14.         }
  15.  
  16.         private void ModalDialog_Load(object sender, EventArgs e)
  17.         {
  18.  
  19.         }
  20.  
  21.    
  22.         private void CbRed_CheckedChanged(object sender, EventArgs e)
  23.         {
  24.             if (cbRed.Checked)
  25.             {
  26.                 TurnLayerOnOff("RedStuff", true);
  27.                 textBox.Text = "Red Checked";
  28.                 Active.Editor.UpdateScreen();
  29.             }
  30.             else
  31.             {
  32.                 TurnLayerOnOff("RedStuff", false);
  33.                 textBox.Text = "Red Unchecked";
  34.                 Active.Editor.UpdateScreen();
  35.             }
  36.         }
  37.  
  38.         private void CbGreen_CheckedChanged(object sender, EventArgs e)
  39.         {
  40.             if (cbGreen.Checked)
  41.             {
  42.                 TurnLayerOnOff("GreenStuff", true);
  43.                 textBox.Text = "Green Checked";
  44.                 Active.Editor.UpdateScreen();
  45.             }
  46.             else
  47.             {
  48.                 TurnLayerOnOff("GreenStuff", false);
  49.                 textBox.Text = "Green Unchecked";
  50.                 Active.Editor.UpdateScreen();
  51.             }
  52.         }
  53.  
  54.         private void CbBlue_CheckedChanged(object sender, EventArgs e)
  55.         {
  56.             if (cbBlue.Checked)
  57.             {
  58.                 TurnLayerOnOff("BlueStuff", true);
  59.                 textBox.Text = "Blue Checked";
  60.                 Active.Editor.UpdateScreen();
  61.             }
  62.             else
  63.             {
  64.                 TurnLayerOnOff("BlueStuff", false);
  65.                 textBox.Text = "Blue Unchecked";
  66.                 Active.Editor.UpdateScreen();
  67.             }
  68.         }
  69.  
  70.         private void ButtonZoom_Click(object sender, EventArgs e)
  71.         {
  72.             //Call the COM library
  73.             dynamic acadApp = cadApp.AcadApplication;
  74.             acadApp.ZoomExtents();
  75.             acadApp.ZoomScaled(0.75, 1);
  76.         }
  77.  
  78.         // should not be in the Dialog Stuff; move to control file :kdub
  79.         // and change to use delegates
  80.         private  void TurnLayerOnOff(
  81.             string layerName, bool isOffp)
  82.         {
  83.             using (var tr = Active.Database.TransactionManager.StartTransaction())
  84.             {
  85.                 var layerTable = tr.GetObject(
  86.                     Active.Database.LayerTableId, OpenMode.ForRead) as LayerTable;
  87.                 if (layerTable != null)
  88.                 {
  89.                     if (layerTable.Has(layerName))
  90.                     {
  91.                         var layerTableRecord = tr.GetObject(
  92.                             layerTable[layerName], OpenMode.ForWrite) as LayerTableRecord;
  93.                         if (layerTableRecord != null)
  94.                         {
  95.                             layerTableRecord.IsOff = isOffp;
  96.                         }
  97.                     }
  98.                 }
  99.                 tr.Commit();
  100.             }
  101.         }
  102.     }
  103. }
  104.  
  105.  


called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

gile

  • Water Moccasin
  • Posts: 2231
  • Marseille, France
Re: UpdateScreen ...Proof of concept
« Reply #2 on: June 16, 2019, 04:04:13 AM »
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).
« Last Edit: June 16, 2019, 04:21:58 AM by gile »
Speaking English as a French Frog

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1368
  • class keyThumper<T>:ILazy<T>
Re: UpdateScreen ...Proof of concept
« Reply #3 on: June 16, 2019, 04:18:02 AM »

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


called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1368
  • class keyThumper<T>:ILazy<T>
Re: UpdateScreen ...Proof of concept
« Reply #4 on: June 16, 2019, 04:24:16 AM »

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


called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

gile

  • Water Moccasin
  • Posts: 2231
  • Marseille, France
Re: UpdateScreen ...Proof of concept
« Reply #5 on: June 16, 2019, 04:26:51 AM »

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.

Yes i understand, it was just a remark before someone come with: "It does not work !".
Speaking English as a French Frog

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1368
  • class keyThumper<T>:ILazy<T>
Re: UpdateScreen ...Proof of concept
« Reply #6 on: June 16, 2019, 04:28:38 AM »

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.

Yes i understand, it was just a remark before someone come with: "It does not work !".

Yep !

called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

Atook

  • Swamp Rat
  • Posts: 937
Re: UpdateScreen ...Proof of concept
« Reply #7 on: June 17, 2019, 01:45:29 AM »
Do you find that UpdateScreen() is faster than Regen()?

Reading this, it seems like Regen() has more calculations in it than UpdateScreen().

I've only used Regen(), this is the first I'd heard of UpdateScreen().

MickD

  • Gator
  • Posts: 3310
  • (x-in)->[process]->(y-out)
Re: UpdateScreen ...Proof of concept
« Reply #8 on: June 17, 2019, 02:16:55 AM »
Do you find that UpdateScreen() is faster than Regen()?

Reading this, it seems like Regen() has more calculations in it than UpdateScreen().

I've only used Regen(), this is the first I'd heard of UpdateScreen().

Just shooting from the hip here but Regen having more calculations 'sounds' about right, it's regenerating the whole image from the database whereas UpdateScreen is probably just checking some flags associated with the last buffered image data, in this case 'Layer' names and only draws what is needed.
that is, it's only drawing what it already knows but with a different 'state'.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1368
  • class keyThumper<T>:ILazy<T>
Re: UpdateScreen ...Proof of concept
« Reply #9 on: June 17, 2019, 02:23:59 AM »
Hi Tim,

I was happy to use UpdateScreen() because all that was being done was turning layers on/off ... nothing that required a recalculation of object locations.
If there was changes to geometry and entity addition/removal Regen() may be better.

I've never done an analysis on the relative uses of either though.

In this case the requirements were simply to visually interactively confirm the resulting display.

Thanks for the comment.
Regards,

added: Ooops, Mick stole my thunder :)



« Last Edit: June 17, 2019, 02:29:05 AM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

MickD

  • Gator
  • Posts: 3310
  • (x-in)->[process]->(y-out)
Re: UpdateScreen ...Proof of concept
« Reply #10 on: June 17, 2019, 02:34:32 AM »

added: Ooops, Mick stole my thunder :)

Not at all, I think both comments compliment each other :)
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1368
  • class keyThumper<T>:ILazy<T>
Re: UpdateScreen ...Proof of concept
« Reply #11 on: June 17, 2019, 02:43:34 AM »
>>>
Reading this, it seems like Regen() has more calculations in it than UpdateScreen().
<<<

Yes, I'd anticipate a difference. Perhaps someone with some spare time will run a test and let us know   :wink:

I'll be interested to hear from the query originator if this solution suits their process.
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1368
  • class keyThumper<T>:ILazy<T>
Re: UpdateScreen ...Proof of concept
« Reply #12 on: June 17, 2019, 03:03:02 AM »
In response to a PM question.:

The Extension class, the Common class and the Linq class are derived from lectures given by Scott McFarlane at Autodesk University.

https://www.autodesk.com/autodesk-university/au-online?query=Scott+McFarlane
2012   Programming AutoCAD® with C#: Best Practices
2014   Sharpen Your C# Code for AutoCAD
2015   Being a Remarkable C# .NET AutoCAD Developer

It's a Wonderland, but be prepared go down the rabbit hole ...

They make no real variation in functionality for this exercise, but they are pretty to look at.
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober