.NET

Reply
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 1 of 7 (386 Views)
Accepted Solution

Is this a ghost?

386 Views, 6 Replies
12-22-2013 12:59 AM

     Now I already understand the mechanism of the rubber band, but I’m not sure what’s name of another mechanism

 

     For example, as shown in attachment picture, when copying a circle, then move the mouse, there is a circle in the center of the cross, what I want to achieve is how to let the moving circle come true.

 

     Maybe this mechanism should call Ghost? I'm not sure.

 

     Is there someone can understand what I'm saying? If you can provide any reference information, very grateful.

Hi,

 

You can do it with a Jig.

Here's a little sample using a class deriving from EntityJig.

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace DragCircleSample
{
public class CommandMethods
{
[CommandMethod("DragCircle")]
public void DragCircle()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
using (Circle circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 3.0))
{
CircleJig jig = new CircleJig(circle);
PromptResult pr = ed.Drag(jig);
if (pr.Status == PromptStatus.OK)
{
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(circle);
tr.AddNewlyCreatedDBObject(circle, true);
}
tr.Commit();
}
}
class CircleJig : EntityJig
{
Circle circle;
Point3d center;
public CircleJig(Circle circle) : base(circle)
{
this.circle = circle;
this.center = circle.Center;
}
protected override bool Update()
{
circle.Center = center;
return true;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
PromptPointResult ppr = 
prompts.AcquirePoint("\nSpecify the circle center: "); if (ppr.Value.DistanceTo(center) < Tolerance.Global.EqualPoint) return SamplerStatus.NoChange; center = ppr.Value; return SamplerStatus.OK; } } } }

 

Mentor
mzakiralam
Posts: 231
Registered: ‎11-09-2012
Message 2 of 7 (369 Views)

Re: Is this a ghost?

12-22-2013 02:22 AM in reply to: HelloWorlddd
you can have a look in below link where move command is implemented. before move you can clone the selected object and the move it .

http://through-the-interface.typepad.com/through_the_interface/2011/03/using-transient-graphics-to-s...
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 3 of 7 (367 Views)

Re: Is this a ghost?

12-22-2013 02:36 AM in reply to: HelloWorlddd

Uh..I think what I want is a sample code then I can study by myslef.

 

I want to express is an effect:
     Such as execute a  command to create a circle, the radius is 3,
     Then, program asks the user to select a center as the anchor point,
     At this time the circle that has been displayed on screen,  the circle can be moved during the mouse is moving
     Yes, this is just a very human mechanism thought it does not change the functionality of the program


This feature is very nice.

I think there must be a class can let it come true.  but I really don't know which one is it..wating for your help., very thanks

 

*Expert Elite*
_gile
Posts: 2,114
Registered: ‎04-29-2006
Message 4 of 7 (347 Views)

Re: Is this a ghost?

12-22-2013 04:10 AM in reply to: HelloWorlddd

Hi,

 

You can do it with a Jig.

Here's a little sample using a class deriving from EntityJig.

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace DragCircleSample
{
    public class CommandMethods
    {
        [CommandMethod("DragCircle")]
        public void DragCircle()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            using (Circle circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 3.0))
            {
                CircleJig jig = new CircleJig(circle);
                PromptResult pr = ed.Drag(jig);
                if (pr.Status == PromptStatus.OK)
                {
                    BlockTableRecord btr =
                        (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    btr.AppendEntity(circle);
                    tr.AddNewlyCreatedDBObject(circle, true);
                }
                tr.Commit();
            }
        }

        class CircleJig : EntityJig
        {
            Circle circle;
            Point3d center;

            public CircleJig(Circle circle) : base(circle)
            {
                this.circle = circle;
                this.center = circle.Center;
            }

            protected override bool Update()
            {
                circle.Center = center;
                return true;
            }

            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                PromptPointResult ppr = 
prompts.AcquirePoint("\nSpecify the circle center: "); if (ppr.Value.DistanceTo(center) < Tolerance.Global.EqualPoint) return SamplerStatus.NoChange; center = ppr.Value; return SamplerStatus.OK; } } } }

 

Gilles Chanteau
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 5 of 7 (334 Views)

Re: Is this a ghost?

12-22-2013 06:07 AM in reply to: _gile
Yes, it's the function that I want to , thank you very much!
New Member
mineshparikh
Posts: 1
Registered: ‎12-24-2013
Message 6 of 7 (269 Views)

Re: Is this a ghost?

12-24-2013 08:14 AM in reply to: HelloWorlddd

i was facing the same problem. i m also looking for the same answer.

Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 7 of 7 (265 Views)

Re: Is this a ghost?

12-24-2013 08:21 AM in reply to: mineshparikh

   You can refer my topic that mention during this days,  there are what you want, I can tell you now how I deal with my problems, finally solve with the DrawJig class

   http://forums.autodesk.com/t5/NET/Rubber-band-and-Jig-I-s-a-balloon/td-p/4711777

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!