Author Topic: Trying to Display Transient Text  (Read 2638 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Trying to Display Transient Text
« on: August 11, 2015, 10:59:51 PM »
Trying to display text temporarily... need help with a few things. Need to know why this won't always clear the text as well as would like to know how to get the text to display at the center of my screen. I tried getting the average of the screen points but didn't seem to work so I just set the position at a temporary location for now.
Code - C#: [Select]
  1.  public static DBObjectCollection temptext = new DBObjectCollection();
  2.         public static IntegerCollection intColl = new IntegerCollection();
  3.         public static void DisplayText(string mystring)
  4.         {
  5.             Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  6.             Editor MyEditor = Application.DocumentManager.MdiActiveDocument.Editor;
  7.             Point2d screenSize = (Point2d)Application.GetSystemVariable("SCREENSIZE");
  8.             System.Drawing.Point upperLeft = new System.Drawing.Point(0, 0);
  9.             System.Drawing.Point lowerRight = new System.Drawing.Point((int)screenSize.X, (int)screenSize.Y);
  10.             Point3d upperLeftWorld = MyEditor.PointToWorld(upperLeft, 0);
  11.             Point3d lowerRightWorld = MyEditor.PointToWorld(lowerRight, 0);
  12.             double screensize = upperLeftWorld.DistanceTo(lowerRightWorld);
  13.             acDoc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
  14.             DBText mytext = new DBText();
  15.             mytext.TextString = mystring;
  16.             mytext.Height = screensize * .02;
  17.             mytext.Position = new Point3d(lowerRightWorld.X-20,lowerRightWorld.Y+20,0);
  18.             mytext.ColorIndex = 140;
  19.             aGi.TransientManager.CurrentTransientManager.AddTransient(mytext, aGi.TransientDrawingMode.DirectTopmost, 128, intColl);
  20.             temptext.Add(mytext);
  21.         }
  22.         public static void doc_CommandWillStart(object sender, CommandEventArgs e)
  23.         {
  24.             if (e.GlobalCommandName.Contains("REGEN"))
  25.             {
  26.                 ClearMarkers();
  27.                 Document doc = Application.DocumentManager.MdiActiveDocument;
  28.                 doc.CommandWillStart -= new CommandEventHandler(doc_CommandWillStart);
  29.             }
  30.         }
  31.         public static void ClearMarkers()
  32.         {
  33.             aGi.TransientManager.CurrentTransientManager.EraseTransient(temptext[0], intColl);
  34.             temptext[0].Dispose();
  35.             temptext.Clear();
  36.         }

Revised kdub : code tag:-> code=csharp
« Last Edit: August 11, 2015, 11:21:09 PM by Alien »

n.yuan

  • Bull Frog
  • Posts: 348
Re: Trying to Display Transient Text
« Reply #1 on: August 12, 2015, 10:08:19 AM »
No time to do a test-run, but this could be the possible reason:

You used a static IntegerCollection that only instantiates once as the parameter for the adding/erasing transient graphics. It should be instantiated as new IntegerCollection each time adding/erasing transient graphics is called.


nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Trying to Display Transient Text
« Reply #2 on: August 13, 2015, 07:50:04 PM »
soooo...tried to do a multitude of things based on what I thought you meant.... but that's a lot of big programming words for a lowly cad guy bahaha....

anyway you can help me out...dumby it down a bit?


Jeff H

  • Needs a day job
  • Posts: 6150
Re: Trying to Display Transient Text
« Reply #3 on: August 13, 2015, 08:04:17 PM »
Trying to display text temporarily....
...
 Need to know why this won't always clear the text
Does it clear it sporadically?
always works the first time?
never works the first time?
never works the second time?
sometimes works the second time?
etc...

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Trying to Display Transient Text
« Reply #4 on: August 13, 2015, 11:20:10 PM »
Seems for the most part if I regen right away it works. If I perform the action again without a regen, they tend to stay.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Trying to Display Transient Text
« Reply #5 on: August 13, 2015, 11:58:10 PM »
From what I can tell why would you expect it to work without calling regen?

From what I can only guess is that you some how call
DisplayText which
 
  • Adds transient text
  • Adds a command starting handler

Then the command handler
  • Checks if command is Regen
  • If command is Regen it calls ClearMarkers and then removes the command starting handler


nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Trying to Display Transient Text
« Reply #6 on: August 14, 2015, 12:39:18 AM »

Thanks Jeff, first time I've tried using transient graphics in civil 3d, as well as using an event handler like this.  Seems here it's per instance, where in something like LUA, etc., when I assign an even handler it fires no matter when that event occurs, whether I put it inside a function or make it it's own.  All a bit confusing lol.  At least it seems I have to fire Regen right-away. If I don't the text stays...which makes me think it's per instance.
Should clarify that I am using "regen" and it's not clearing...so not sure why.

I abandoned using it for now but wish there was more concerning the topic I could learn from.

Much appreciated.
« Last Edit: August 14, 2015, 12:45:32 AM by Alien »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Trying to Display Transient Text
« Reply #7 on: August 14, 2015, 10:52:08 AM »
Alien,
I've revised your code so that the event handler only gets added once, when needed, and to delete all instances of the text. If this isn't what you were wanting to accomplish, maybe explain some more?
Code - C#: [Select]
  1.         [CommandMethod("DoText")]
  2.         public void dotext()
  3.         {
  4.             DisplayText("Testing");
  5.         }
  6.         public static DBObjectCollection temptext = new DBObjectCollection();
  7.         public static IntegerCollection intColl = null;
  8.         public static bool eventadded = false;
  9.  
  10.         public static void DisplayText(string mystring)
  11.         {
  12.             intColl = new IntegerCollection();
  13.             Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  14.             Editor MyEditor = Application.DocumentManager.MdiActiveDocument.Editor;
  15.             Point2d screenSize = (Point2d)Application.GetSystemVariable("SCREENSIZE");
  16.             System.Drawing.Point upperLeft = new System.Drawing.Point(0, 0);
  17.             System.Drawing.Point lowerRight = new System.Drawing.Point((int)screenSize.X, (int)screenSize.Y);
  18.             Point3d upperLeftWorld = MyEditor.PointToWorld(upperLeft, 0);
  19.             Point3d lowerRightWorld = MyEditor.PointToWorld(lowerRight, 0);
  20.             double screensize = upperLeftWorld.DistanceTo(lowerRightWorld);
  21.             if (!eventadded)
  22.             {
  23.                 acDoc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
  24.                 eventadded = true;
  25.             }
  26.             DBText mytext = new DBText();
  27.             mytext.TextString = mystring;
  28.             mytext.Height = screensize * .02;
  29.             mytext.Position = new Point3d(lowerRightWorld.X - 20, lowerRightWorld.Y + 20, 0);
  30.             mytext.ColorIndex = 140;
  31.             aGi.TransientManager.CurrentTransientManager.AddTransient(mytext, aGi.TransientDrawingMode.DirectTopmost, 128, intColl);
  32.             temptext.Add(mytext);
  33.         }
  34.         public static void doc_CommandWillStart(object sender, CommandEventArgs e)
  35.         {
  36.             if (e.GlobalCommandName.Contains("REGEN"))
  37.             {
  38.                 ClearMarkers();
  39.                 Document doc = Application.DocumentManager.MdiActiveDocument;
  40.                 doc.CommandWillStart -= new CommandEventHandler(doc_CommandWillStart);
  41.                 eventadded = false;
  42.             }
  43.         }
  44.         public static void ClearMarkers()
  45.         {
  46.             for (int i = 0; i < temptext.Count; i++)
  47.             {
  48.                 aGi.TransientManager.CurrentTransientManager.EraseTransient(temptext[i], intColl);
  49.                 temptext[i].Dispose();
  50.             }
  51.             temptext.Clear();
  52.         }
  53.  

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Trying to Display Transient Text
« Reply #8 on: August 15, 2015, 06:32:48 PM »
Thanks for this. It's exactly what I needed.