Author Topic: Draw temporary red circle (gets removed on regen)  (Read 4656 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
Draw temporary red circle (gets removed on regen)
« on: June 19, 2011, 06:20:00 AM »
I need help on drawing temporary red circle (like the one in hatch command when no valid boundary is found).
Is that even doable from .net?
I know about Editor.DrawVector but that is only to draw straight lines and another problem, it gets removed on zoom :(

Functionality description from hatch: Errors are marked with red circles that stays on screen even after zoom in/out, it automatically scales, but it gets removed on Regen/Redraw...

Thanks in advance for any pointers :angel:

gile

  • Water Moccasin
  • Posts: 2261
  • Marseille, France
Re: Draw temporary red circle (gets removed on regen)
« Reply #1 on: June 19, 2011, 07:07:16 AM »
Hi,

Maybe implementing a class which inherits the abstract Autodesk.AutoCAD.GraphicsInterface.Glyph class.
Speaking English as a French Frog

pedroantonio

  • Guest
Re: Draw temporary red circle (gets removed on regen)
« Reply #2 on: June 19, 2011, 10:04:28 AM »
What I would like to know is can I gain access to the same .net command/wrapper  that autocad does when he tries to mark errors (like after a hatching entity with not connected boudary)

Jeff_M

  • King Gator
  • Posts: 3977
  • C3D user & customizer
Re: Draw temporary red circle (gets removed on regen)
« Reply #3 on: June 19, 2011, 01:19:41 PM »
Yes. Here's a quick example. More would need to be done to autoscale the circle based on the screen size but this should get you started.
Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using aGi = Autodesk.AutoCAD.GraphicsInterface;


namespace MyTest
{
    public class testing
    {
        private DBObjectCollection m_mrkers = new DBObjectCollection();
        private IntegerCollection intColl = new IntegerCollection();

        [CommandMethod("TempCirc")]
        public void tempcirc()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            doc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
            Point3d ctrPt = new Point3d(100,100,0);
            Circle circ = new Circle(ctrPt, Vector3d.ZAxis, 5);
            circ.ColorIndex = 1;
            aGi.TransientManager.CurrentTransientManager.AddTransient(circ, aGi.TransientDrawingMode.DirectTopmost, 128, intColl);
            m_mrkers.Add(circ);
        }

        void doc_CommandWillStart(object sender, CommandEventArgs e)
        {
            if (e.GlobalCommandName.Contains("REGEN"))
            {
                ClearMarkers();
                Document doc = Application.DocumentManager.MdiActiveDocument;
                doc.CommandWillStart -= new CommandEventHandler(doc_CommandWillStart);
            }
        }
        private void ClearMarkers()
        {
                aGi.TransientManager.CurrentTransientManager.EraseTransient(m_mrkers[0], intColl);
                m_mrkers[0].Dispose();
                m_mrkers.Clear();
            }

        }
    }

gablackburn

  • Guest
Re: Draw temporary red circle (gets removed on regen)
« Reply #4 on: October 25, 2011, 04:27:23 PM »
I'm trying to do something similar with lines instead of circles but I'm using VB.NET.  I've converted Jeff_M's code using a C# to VB converter, but I'm having trouble with two lines of his code.

C# Code
doc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
doc.CommandWillStart -= new CommandEventHandler(doc_CommandWillStart);


... converts to VB Code           
doc.CommandWillStart += New CommandEventHandler(AddressOf doc_CommandWillStart)
doc.CommandWillStart -= New CommandEventHandler(AddressOf doc_CommandWillStart)


It doesn't understand doc.CommandWillStart and gives me a message, "Public Event CommandWillStart(...) is an event, and cannot be called directly.  Use a 'RaiseEvent' statement to raise an event" when I hover over its blue squiggly underline.  The closest option intellisense gives me is doc.CommandInProgress.  I don't understand what it means by 'raising an event'.

I am new to VB.NET and the AutoCAD API so I'm apologizing in advance for being dense.

George

fixo

  • Guest
Re: Draw temporary red circle (gets removed on regen)
« Reply #5 on: October 25, 2011, 05:19:02 PM »
 instead of this line (as converted)
               
Code: [Select]
doc.CommandWillStart += New CommandEventHandler(AddressOf doc_CommandWillStart)use this one
               
Code: [Select]
AddHandler doc.CommandWillStart, New CommandEventHandler(AddressOf doc_CommandWillStart)
 instead of this line
               
Code: [Select]
'doc.CommandWillStart -= New CommandEventHandler(AddressOf doc_CommandWillStart) use next one:
               
Code: [Select]
RemoveHandler doc.CommandWillStart, AddressOf doc_CommandWillStart
and also if you will be draw circles multiple
try something like this:
Code: [Select]
        Private Sub ClearMarkers()
            If (m_mrkers.Count) > 0 Then
                For i As Integer = 0 To m_mrkers.Count - 1
                    aGi.TransientManager.CurrentTransientManager.EraseTransient(m_mrkers(i), intColl)
                    m_mrkers(i).Dispose()
                Next
            End If
        End Sub

Jeff beat me to it :)

gablackburn

  • Guest
Re: Draw temporary red circle (gets removed on regen)
« Reply #6 on: October 26, 2011, 12:50:44 PM »
Wow, thanks fixo, that was quick and it works like a charm.  I don't think I could have stumbled upon figuring that out for a long time.

Kace

  • Guest
Re: Draw temporary red circle (gets removed on regen)
« Reply #7 on: November 01, 2013, 03:34:04 AM »
i'm having simular problems like above.

i'm drawing transient graphics to indicate problems in the design.



When I zoom the circles stay in place, but when i regen my circles moves.



I can't find an event that triggers after regen to update the graphics. Is there such an event?
Or is there something to do with the Transientmanager?
Or what happens in the regen to the transient Graphics?

guohq

  • Newt
  • Posts: 79
Re: Draw temporary red circle (gets removed on regen)
« Reply #8 on: March 22, 2016, 06:40:59 AM »
Yes. Here's a quick example. More would need to be done to autoscale the circle based on the screen size but this should get you started.
Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using aGi = Autodesk.AutoCAD.GraphicsInterface;


namespace MyTest
{
    public class testing
    {
        private DBObjectCollection m_mrkers = new DBObjectCollection();
        private IntegerCollection intColl = new IntegerCollection();

        [CommandMethod("TempCirc")]
        public void tempcirc()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            doc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
            Point3d ctrPt = new Point3d(100,100,0);
            Circle circ = new Circle(ctrPt, Vector3d.ZAxis, 5);
            circ.ColorIndex = 1;
            aGi.TransientManager.CurrentTransientManager.AddTransient(circ, aGi.TransientDrawingMode.DirectTopmost, 128, intColl);
            m_mrkers.Add(circ);
        }

        void doc_CommandWillStart(object sender, CommandEventArgs e)
        {
            if (e.GlobalCommandName.Contains("REGEN"))
            {
                ClearMarkers();
                Document doc = Application.DocumentManager.MdiActiveDocument;
                doc.CommandWillStart -= new CommandEventHandler(doc_CommandWillStart);
            }
        }
        private void ClearMarkers()
        {
                aGi.TransientManager.CurrentTransientManager.EraseTransient(m_mrkers[0], intColl);
                m_mrkers[0].Dispose();
                m_mrkers.Clear();
            }

        }
    }



how to use aGi.TransientManager.CurrentTransientManager.AddTransient in autocad 2008?