.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Activity during drag

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
566 Views, 7 Replies

Activity during drag

I'm writing a simple (I hope) C#.NET dll that will work with AutoCAD 2007
VBA.
The dll provides jig/ghost functionality.
What I have seems to work fine except that the object that is being dragged
flickers alot. It doesn't look like the native AutoCAD drag. This happens
even when the cursor is not being moved at all.
Also not everything shows for example attribute text.

Is there a trick to displaying the "ghosted" entities like AutoCAD native
commands do?

=Mark
7 REPLIES 7
Message 2 of 8
NathTay
in reply to: Anonymous

Post your code. It sounds like you are not checking whether the cursor has moved.

Regards - Nathan
Message 3 of 8
Anonymous
in reply to: Anonymous

Here is the code. Some of it is borrowed from various examples.
I have a function that checks for cursor movement. The original
CursorHasMoved function didn't have a Tolerance argument.
The object didn't behave like I wanted so I added the "Tolerance" argument
to try to get the cursor to stop twitching when I wasn't moving it.
That didn't work. The objects twitched regardless of the Tolerance value
although it did not move until the Tolerance was met.

// HERE IS THE CODE
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;

[assembly: CommandClass(typeof(ClassLibrary.DragByID))]

namespace ClassLibrary
{
///
/// Summary description for WestClass.
///


public class DragByID
{
[ComVisible(true)]
public long myObjectID;
public double x;
public double y;
public double z;

public DragByID()
{
x = 0;
y = 0;
z = 0;
}

public bool DragIt()
{
if (myObjectID == 0) return false;
Point3d myPoint = new Point3d(x, y, z);
myJig oDrag = new myJig();
oDrag.DragDropObject(myObjectID, myPoint);
return true;
}

[ComVisible(false)]
public class myJig : DrawJig
{
#region private member fields
private Point3d previousCursorPosition;
private Point3d currentCursorPosition;
#endregion

public string entID;
private Entity entityToDrag;

public void DragDropObject(long oID, Point3d iPnt)
{
//Initialize cursor position
previousCursorPosition = iPnt; // new Point3d(x, y, z);
Database db =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Editor ed =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =
db.TransactionManager;
using (Transaction aTran = tm.StartTransaction())
{
entityToDrag = (Entity)tm.GetObject(new
ObjectId((int)oID), OpenMode.ForWrite);
ed.Drag(this);
aTran.Commit();
}
}

protected override SamplerStatus Sampler(JigPrompts prompts)
{
//Get the current cursor position
PromptPointResult userFeedback = prompts.AcquirePoint();
currentCursorPosition = userFeedback.Value;

if (CursorHasMoved(1))
{
Vector3d displacementVector =
currentCursorPosition.GetVectorTo(previousCursorPosition);

displacementVector = displacementVector.MultiplyBy(-1);
entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));

previousCursorPosition = currentCursorPosition;

return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}

protected override bool WorldDraw(WorldDraw draw)
{
draw.Geometry.Draw(entityToDrag);
return true;
}

private bool CursorHasMoved(double Tolerance)
{
double xDiff;
double yDiff;
double zDiff;
xDiff = currentCursorPosition.X - previousCursorPosition.X;
yDiff = currentCursorPosition.Y - previousCursorPosition.Y;
zDiff = currentCursorPosition.Z - previousCursorPosition.Z;
if (xDiff < 0) xDiff = xDiff * -1;
if (yDiff < 0) yDiff = yDiff * -1;
if (zDiff < 0) zDiff = zDiff * -1;
return ((xDiff + yDiff + zDiff) > Tolerance);
}
}
}
}
// END OF THE CODE

wrote in message news:5248331@discussion.autodesk.com...
Post your code. It sounds like you are not checking whether the cursor has
moved.

Regards - Nathan
Message 4 of 8
NathTay
in reply to: Anonymous

I can't see anything wrong with your code. I haven't tried yours but I have a VB block insert example that does not twitch. Checking a tolerance should be unnecessary.

Regards - Nathan
Message 5 of 8
Anonymous
in reply to: Anonymous

Thanks Nathan,
I did see your VB example. I was hoping to do this in C# but I may just
build on your example. I agree that checking for amount of movement should
be unnecessary. It was something I did just to see what would happen.
(hoping for a clue)

Maybe a reader with experience in C# can point me in the right direction.
(hint Tony)

wrote in message news:5248434@discussion.autodesk.com...
I can't see anything wrong with your code. I haven't tried yours but I have
a VB block insert example that does not twitch. Checking a tolerance should
be unnecessary.

Regards - Nathan
Message 6 of 8
Anonymous
in reply to: Anonymous

Hey Mark,
I'm no Tony, but maybe I can help.

You are transforming a database resident object with each move of the mouse.
Your jig should be working with non db resident objects. Check out this
example http://www.theswamp.org/index.php?topic=8198.0, just note that I
never did finish this to my liking. Run it and move your mouse out of the
drawing area to see what I mean.

However, since you are targeting 2007, you can use the overloaded Drag
method that wraps acedDragGen().

public class EntityDragger
{
private Point3d m_basePoint;
[CommandMethod("dragSS")]
public void SsDragger()
{
Editor currentEditor = acadApp.DocumentManager.MdiActiveDocument.Editor;
//Create a new selection set options object
PromptSelectionOptions ssOptions = new PromptSelectionOptions();
ssOptions.AllowDuplicates = true;
ssOptions.MessageForAdding = "Select objects to copy: ";
//Get a selection from the user
PromptSelectionResult ssResult = currentEditor.GetSelection(ssOptions);
if (ssResult.Status != PromptStatus.OK)
{
return;
}
//Get a base point from the user
PromptPointResult pointResult = currentEditor.GetPoint("\nSelect base point:
");
if (pointResult.Status != PromptStatus.OK)
{
return;
}
m_basePoint = pointResult.Value;
//Initiate the drag callback delegate
DragCallback dragCallbackDelegate = this.FollowCursor;
//Start the drag operation
PromptDragOptions dragOptions = new PromptDragOptions(ssResult.Value,
"\nSelect destination point: ", dragCallbackDelegate);
PromptPointResult destinationPointResult = currentEditor.Drag(dragOptions);
if (destinationPointResult.Status != PromptStatus.OK)
{
return;
}
//Determine the final displacement matrix
Matrix3d transMat =
Matrix3d.Displacement(m_basePoint.GetVectorTo(destinationPointResult.Value));
//transform the ss to the new location
this.TransformSelectionSet(ssResult.Value, transMat);
}

//DragCallback Delegate
public SamplerStatus FollowCursor(Point3d currentPoint, ref Matrix3d
transMat)
{
transMat = Matrix3d.Displacement(m_basePoint.GetVectorTo(currentPoint));
return SamplerStatus.OK;
}
}

Also note that they fixed the GetVectorTo() method in 07; this:

Vector3d displacementVector =
currentCursorPosition.GetVectorTo(previousCursorPosition);
displacementVector = displacementVector.MultiplyBy(-1);

can be replaced with this:
Vector3d displacementVector =
previousCursorPosition.GetVectorTo(currentCursorPosition);

p.s. - I just saw that you posted over in the swamp. I'll post this code
there so you can see it with some formatting.
--
Bobby C. Jones


"Mark Johnston" wrote in message
news:5249253@discussion.autodesk.com...
Thanks Nathan,
I did see your VB example. I was hoping to do this in C# but I may just
build on your example. I agree that checking for amount of movement should
be unnecessary. It was something I did just to see what would happen.
(hoping for a clue)

Maybe a reader with experience in C# can point me in the right direction.
(hint Tony)

wrote in message news:5248434@discussion.autodesk.com...
I can't see anything wrong with your code. I haven't tried yours but I have
a VB block insert example that does not twitch. Checking a tolerance should
be unnecessary.

Regards - Nathan
Message 7 of 8
Anonymous
in reply to: Anonymous

Hi Mark - If you can post a complete working project (including
the code needed to select the objects, and do the dragging),
I might be able to take a look at it, but what you posted is
not a complete working sample, and it would require coding
to test.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Mark Johnston" wrote in message news:5249253@discussion.autodesk.com...
Thanks Nathan,
I did see your VB example. I was hoping to do this in C# but I may just
build on your example. I agree that checking for amount of movement should
be unnecessary. It was something I did just to see what would happen.
(hoping for a clue)

Maybe a reader with experience in C# can point me in the right direction.
(hint Tony)

wrote in message news:5248434@discussion.autodesk.com...
I can't see anything wrong with your code. I haven't tried yours but I have
a VB block insert example that does not twitch. Checking a tolerance should
be unnecessary.

Regards - Nathan
Message 8 of 8
Anonymous
in reply to: Anonymous

Attached is the .NET project along with a VBA module to add to a VBA
project.
I'm not doing an on-screen select of objects but am creating them in VBA.
You will need to have a TestBlock.dwg file on C: or change the hard-coded
path in the VBA module.

Thanks


"Tony Tanzillo" wrote in message
news:5249916@discussion.autodesk.com...
Hi Mark - If you can post a complete working project (including
the code needed to select the objects, and do the dragging),
I might be able to take a look at it, but what you posted is
not a complete working sample, and it would require coding
to test.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Mark Johnston" wrote in message
news:5249253@discussion.autodesk.com...
Thanks Nathan,
I did see your VB example. I was hoping to do this in C# but I may just
build on your example. I agree that checking for amount of movement should
be unnecessary. It was something I did just to see what would happen.
(hoping for a clue)

Maybe a reader with experience in C# can point me in the right direction.
(hint Tony)

wrote in message news:5248434@discussion.autodesk.com...
I can't see anything wrong with your code. I haven't tried yours but I have
a VB block insert example that does not twitch. Checking a tolerance should
be unnecessary.

Regards - Nathan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost