Author Topic: Transient Graphics  (Read 3932 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Transient Graphics
« on: July 14, 2016, 01:07:52 AM »
Until tonight, I've avoided transient graphics. I got something permanently stuck in a drawing and since then it gave me a bit of cold feet bahaha.

I want to make a circle follow my cursor. The code below shows I am monitoring my cursor position okay, but my circle only updates if I do a regen.

I'd like the circle to simply follow my cursor. Any assistance is appreciated. Thanks!

Code - C#: [Select]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Geometry;
  5. using Autodesk.AutoCAD.Runtime;
  6. using graphicinterface = Autodesk.AutoCAD.GraphicsInterface;
  7.  
  8. public class PointMonitorTooltips
  9.  
  10. {
  11.     private static DBObjectCollection markers = new DBObjectCollection();
  12.     private static IntegerCollection collectints = new IntegerCollection();
  13.     private static Circle circle;
  14.  
  15.     [CommandMethod("start")]
  16.     public static void StartMonitor()
  17.     {
  18.  
  19.         Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;        
  20.         Point3d ctrPt = new Point3d(0,0,0);
  21.         circle = new Circle(ctrPt, Vector3d.ZAxis, 5);
  22.         circle.ColorIndex = 1;
  23.         graphicinterface.TransientManager.CurrentTransientManager.AddTransient(circle, graphicinterface.TransientDrawingMode.DirectTopmost, 128, collectints);
  24.         markers.Add(circle);
  25.         ed.PointMonitor += new PointMonitorEventHandler(ed_PointMonitor);
  26.     }
  27.  
  28.     [CommandMethod("stop")]
  29.     public static void StopMonitor()
  30.     {
  31.         Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  32.         ed.PointMonitor -= new PointMonitorEventHandler(ed_PointMonitor);
  33.         graphicinterface.TransientManager.CurrentTransientManager.EraseTransient(markers[0], collectints);
  34.         markers[0].Dispose();
  35.         markers.Clear();
  36.     }
  37.  
  38.     static void ed_PointMonitor(object sender, PointMonitorEventArgs e)
  39.     {
  40.         Editor ed = (Editor)sender;
  41.         Document doc = ed.Document;
  42.         circle.Center = e.Context.RawPoint;  
  43.     }
  44. }
  45.  
  46.  

huiz

  • Swamp Rat
  • Posts: 917
  • Certified Prof C3D
Re: Transient Graphics
« Reply #1 on: July 14, 2016, 01:49:22 AM »
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Transient Graphics
« Reply #2 on: July 14, 2016, 02:20:31 AM »
A jig may very well be what you want.

In case you've decided against it, you need to update the transient graphics in the point monitor. I have a call to this method in my point monitor, and I pass it a list of drawables, as well as the last point. In the future I'll be adding text and such to the list of drawables, but for now it's a circle and a rubberband line.

I want to convert it into a jig, but jigs bend my mind in funny directions. Someday perhaps.

Code - C#: [Select]
  1. private static void UpdateTransGraphics(List<Drawable> drawables, Point3d originPt, Point3d lastPt, Point3dCollection rubberBandPoints )
  2. {
  3.         // Displace each of our drawables
  4.  
  5.         Matrix3d mat =
  6.           Matrix3d.Displacement(originPt.GetVectorTo(lastPt));
  7.  
  8.         // Update their graphics
  9.  
  10.         Circle cir = drawables[0] as Circle;
  11.         if (cir != null)
  12.         {
  13.                 cir.Center = lastPt;
  14.                 TransientManager.CurrentTransientManager.UpdateTransient(cir, new IntegerCollection());
  15.         }
  16.  
  17.         // draw the rubberband
  18.         Polyline rBand = drawables[1] as Polyline;
  19.         if (rBand != null && rubberBandPoints.Count>0)
  20.         {
  21.                 rBand.Reset(false,0);
  22.                 for (int i = 0; i < rubberBandPoints.Count; i++)
  23.                 {
  24.                         Point2d pt = new Point2d(rubberBandPoints[i].X, rubberBandPoints[i].Y);
  25.                         rBand.AddVertexAt(i, pt, 0, 0, 0);
  26.                 }
  27.                 rBand.AddVertexAt(rubberBandPoints.Count, lastPt.Convert2D(), 0,  0,  0);
  28.                 TransientManager.CurrentTransientManager.UpdateTransient(rBand, new IntegerCollection());
  29.         }
  30.         Debug.WriteLine("Updated " + drawables.Count + " transgraphics");
  31. }

SEANT

  • Bull Frog
  • Posts: 345
Re: Transient Graphics
« Reply #3 on: July 14, 2016, 04:34:58 AM »
Not an exact match to the requirements listed in the OP but the code I attached here (post #5):
http://www.cadtutor.net/forum/showthread.php?41649-VB.net-Create-a-circle
may serve as an “jigging” example for a cursor located circle.  It actually uses two jigging elements, the first to create/size the circle, the second to place it via the center point.

Here’s a screencast of the routine:
http://autode.sk/29GlZIi
Sean Tessier
AutoCAD 2016 Mechanical

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Transient Graphics
« Reply #4 on: July 14, 2016, 12:06:24 PM »
Alien Dude, I use the TransientGraphics to follow the cursor when asking the user to select a location in the PipeEditor command in Sincpac. This is how I'd modify your code to be similar to that:
Code - C#: [Select]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Geometry;
  5. using Autodesk.AutoCAD.Runtime;
  6. using aGi = Autodesk.AutoCAD.GraphicsInterface;
  7.  
  8. public class PointMonitorTooltips
  9. {
  10.     private static DBObjectCollection m_markers = new DBObjectCollection();
  11.     private static IntegerCollection collectints = new IntegerCollection();
  12.  
  13.     [CommandMethod("start")]
  14.     public static void StartMonitor()
  15.     {
  16.         Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  17.         ed.PointMonitor += new PointMonitorEventHandler(ed_PointMonitor);        
  18.     }
  19.  
  20.     [CommandMethod("stop")]
  21.     public static void stopmonitor()
  22.     {
  23.         Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  24.         ed.PointMonitor -= ed_PointMonitor;
  25.         ClearMarkers();
  26.     }
  27.     static void ed_PointMonitor(object sender, PointMonitorEventArgs e)
  28.     {
  29.         showcircle(e.Context.RawPoint);
  30.     }
  31.  
  32.     static void showcircle(Point3d pt)
  33.     {
  34.         ClearMarkers();
  35.         Circle circle = new Circle(pt, Vector3d.ZAxis, 5);
  36.         circle.ColorIndex = 1;
  37.         m_markers.Add(circle);
  38.         aGi.TransientManager.CurrentTransientManager.AddTransient(circle, aGi.TransientDrawingMode.DirectShortTerm, 128, collectints);
  39.     }
  40.  
  41.     static void ClearMarkers()
  42.     {
  43.         for (int i = 0; i < m_markers.Count; i++)
  44.         {
  45.             aGi.TransientManager.CurrentTransientManager.EraseTransient(m_markers[i], collectints);
  46.             m_markers[i].Dispose();
  47.         }
  48.         m_markers.Clear();
  49.     }
  50. }
  51.  

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Transient Graphics
« Reply #5 on: July 14, 2016, 04:00:36 PM »
Thank you for this

Alien Dude, I use the TransientGraphics to follow the cursor when asking the user to select a location in the PipeEditor command in Sincpac. This is how I'd modify your code to be similar to that:
Code - C#: [Select]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Geometry;
  5. using Autodesk.AutoCAD.Runtime;
  6. using aGi = Autodesk.AutoCAD.GraphicsInterface;
  7.  
  8. public class PointMonitorTooltips
  9. {
  10.     private static DBObjectCollection m_markers = new DBObjectCollection();
  11.     private static IntegerCollection collectints = new IntegerCollection();
  12.  
  13.     [CommandMethod("start")]
  14.     public static void StartMonitor()
  15.     {
  16.         Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  17.         ed.PointMonitor += new PointMonitorEventHandler(ed_PointMonitor);        
  18.     }
  19.  
  20.     [CommandMethod("stop")]
  21.     public static void stopmonitor()
  22.     {
  23.         Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  24.         ed.PointMonitor -= ed_PointMonitor;
  25.         ClearMarkers();
  26.     }
  27.     static void ed_PointMonitor(object sender, PointMonitorEventArgs e)
  28.     {
  29.         showcircle(e.Context.RawPoint);
  30.     }
  31.  
  32.     static void showcircle(Point3d pt)
  33.     {
  34.         ClearMarkers();
  35.         Circle circle = new Circle(pt, Vector3d.ZAxis, 5);
  36.         circle.ColorIndex = 1;
  37.         m_markers.Add(circle);
  38.         aGi.TransientManager.CurrentTransientManager.AddTransient(circle, aGi.TransientDrawingMode.DirectShortTerm, 128, collectints);
  39.     }
  40.  
  41.     static void ClearMarkers()
  42.     {
  43.         for (int i = 0; i < m_markers.Count; i++)
  44.         {
  45.             aGi.TransientManager.CurrentTransientManager.EraseTransient(m_markers[i], collectints);
  46.             m_markers[i].Dispose();
  47.         }
  48.         m_markers.Clear();
  49.     }
  50. }
  51.  


nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Transient Graphics
« Reply #7 on: July 21, 2016, 02:44:58 AM »