Author Topic: Drag jitters 2  (Read 14137 times)

0 Members and 1 Guest are viewing this topic.

Glenn R

  • Guest
Re: Drag jitters 2
« Reply #15 on: September 26, 2007, 08:39:01 PM »
The 'aligned dimension' is for the dynamic dimensions that appear when you are creating objects (the DYN button in the application statusbar).

Glenn R

  • Guest
Re: Drag jitters 2
« Reply #16 on: September 26, 2007, 08:40:56 PM »
There ya go mate:

Code: [Select]
// (C) Copyright 2002-2007 by TCGSoftware.

using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(Bryco.tcgsBrycoJiggy))]

namespace Bryco {
/// <summary>
/// Summary description for tcgsClass.
/// </summary>
public class tcgsBrycoJiggy {
/// <summary>
/// Default ctor.
/// </summary>
public tcgsBrycoJiggy( ) {
// Does nothing in this implementation.
}

#region Circle jigging class
/// <summary>
/// Circle jig class to allow jigging of circle
/// </summary>
public class CircleJig : EntityJig {

private Point3d _centerPt, _radiusPt;
private Vector3d _normal;

private ObjectId _dashLtId = ObjectId.Null;
private double _radius;

private DynamicDimensionDataCollection _dims;

public CircleJig(Point3d centre, Vector3d vec, ObjectId dashLtId) : base(new Circle()) {
_centerPt = centre;
_normal = vec;
_dashLtId = dashLtId;

_dims = new DynamicDimensionDataCollection();
Dimension dim1 = new AlignedDimension();
dim1.SetDatabaseDefaults();
_dims.Add(new DynamicDimensionData(dim1, true, true));

}

public double Radius {
get { return _centerPt.DistanceTo(_radiusPt); }
}

protected override SamplerStatus Sampler(JigPrompts prompts) {
JigPromptOptions jigOpts = new JigPromptOptions();
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates |
UserInputControls.NoZeroResponseAccepted |
UserInputControls.NoNegativeResponseAccepted);

//*******************************************************************
// Required by 2007 - changed name from line above
//JigPromptPointOptions jigOpts = new JigPromptPointOptions();
//jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates |
// UserInputControls.NoZeroResponseAccepted |
// UserInputControls.NoNegativeResponseAccepted);
//*******************************************************************

jigOpts.Message = "\nSpecify radius of circle:";
jigOpts.BasePoint = _centerPt;
jigOpts.UseBasePoint = true;
jigOpts.Cursor = CursorType.RubberBand;
PromptPointResult dres = prompts.AcquirePoint(jigOpts);


Point3d radiusPointTemp = dres.Value;
if(radiusPointTemp != _radiusPt) {
_radiusPt = radiusPointTemp;
} else
return SamplerStatus.NoChange;

if(dres.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
else
return SamplerStatus.OK;

}

protected override bool Update( ) {
_radius = _radiusPt.DistanceTo(_centerPt);

try {
((Circle)Entity).Center = _centerPt;
((Circle)Entity).Radius = _radius;
((Circle)Entity).LinetypeId = _dashLtId;
UpdateDimensions();

} catch(System.Exception) {
return false;
}

return true;

}

protected override DynamicDimensionDataCollection GetDynamicDimensionData(double dimScale) {
return _dims;
}

protected override void OnDimensionValueChanged(Autodesk.AutoCAD.DatabaseServices.DynamicDimensionChangedEventArgs e) {
// base.OnDimensionValueChanged(e);
}

void UpdateDimensions( ) {
Circle myCircle = (Circle)Entity;
AlignedDimension dim = (AlignedDimension)_dims[0].Dimension;
dim.XLine1Point = myCircle.Center;
dim.XLine2Point = _radiusPt;

Vector3d xvec = dim.XLine2Point - dim.XLine1Point;
xvec = xvec.GetNormal();
Vector3d zvec = myCircle.Normal;
zvec = zvec.GetNormal();
Vector3d yvec = zvec.CrossProduct(xvec);
yvec = yvec.GetNormal();

yvec *= myCircle.Radius / 2;

dim.DimLinePoint = myCircle.Center + yvec;
}

public Entity GetEntity( ) {
return Entity;
}

}// class CircleJig

#endregion


#region Command Declarations

// Define Command "BrycesRidgyDidgeCircle"
[CommandMethod("BrycesRidgyDidgeCircle")]
public void BrycesRidgyDidgeCircleCommand( ) {

Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

Transaction tr = null;

try {

tr = db.TransactionManager.StartTransaction();

// Set up the prompting...
PromptPointOptions opts = new PromptPointOptions("\nSpecify centre point for circle:");
PromptPointResult res = ed.GetPoint(opts);

// Calulate our normal vector...
Vector3d NormalVec;

if(IsPaperSpace(db)) {
Vector3d x = db.Pucsxdir;
Vector3d y = db.Pucsydir;
NormalVec = x.CrossProduct(y);
} else {
Vector3d x = db.Ucsxdir;
Vector3d y = db.Ucsydir;
NormalVec = x.CrossProduct(y);
}

Point3d pickPt = res.Value.TransformBy(GetUcsMatrix(db));

//Create Circle jig...
CircleJig jig = new CircleJig(pickPt, NormalVec.GetNormal(), db.ContinuousLinetype);
//first call drag to get the radius
if(ed.Drag(jig).Status != PromptStatus.OK)
return;

BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false) as BlockTableRecord;
btr.AppendEntity(jig.GetEntity());
jig.GetEntity().Draw();
tr.AddNewlyCreatedDBObject(jig.GetEntity(), true);

tr.Commit();

} catch(System.Exception ex) {
tr.Abort();
ed.WriteMessage("\nError: " + ex.Message);
} finally {
if(tr != null) {
tr.Dispose();
}
}

}

#endregion

#region Function to return the current UCS matrix

private Matrix3d GetUcsMatrix(Database db) {

Point3d origin;
Vector3d xAxis, yAxis, zAxis;

if(IsPaperSpace(db)) {
origin = db.Pucsorg;
xAxis = db.Pucsxdir;
yAxis = db.Pucsydir;
} else {
origin = db.Ucsorg;
xAxis = db.Ucsxdir;
yAxis = db.Ucsydir;
}

zAxis = xAxis.CrossProduct(yAxis);

return Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
origin, xAxis, yAxis, zAxis);
}//GetUcsMatrix

#endregion

#region Function to check if we're in Paperspace

private bool IsPaperSpace(Database db) {
if(db.TileMode)
return false;

Document doc = acadApp.DocumentManager.GetDocument(db);
Editor ed = doc.Editor;

if(db.PaperSpaceVportId == ed.CurrentViewportObjectId)
return true;

return false;
}//IsPaperSpace

#endregion
}
}

I'm still not happy with the dynamic dimension that shows up - it doesn't seem to be editable like the AutoCAD circle one is.
Somebody else might be able to fill that bit in.

Cheers,
Glenn.
« Last Edit: September 26, 2007, 10:02:45 PM by Glenn R »

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Drag jitters 2
« Reply #17 on: September 26, 2007, 11:02:59 PM »
Beauty, it's a ripper. Now to try figure out why it works.

Glenn R

  • Guest
Re: Drag jitters 2
« Reply #18 on: September 26, 2007, 11:06:17 PM »
You're welcome. Compare them side by side, so to speak - something will leap out.
Let us know what you find.

Cheers,

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Drag jitters 2
« Reply #19 on: September 27, 2007, 12:35:26 AM »
First up, peanuts are in order.
It's a difficult for me getting the whole concept.
1)public CircleJig(Point3d centre, Vector3d vec, ObjectId dashLtId)
                : base(new Circle())
Seeing the new word, I imagine we are making a new circle here (not sure at all.) and because we are in an Entity jig perhaps there is a circle added to the current space at this time, that doesn't need a radius value (perhaps it is zero)
2) public Entity GetEntity() is this exposing the Protected internal entity from the jig?

Glenn R

  • Guest
Re: Drag jitters 2
« Reply #20 on: September 27, 2007, 12:41:57 AM »
1. CircleJig is derived from EntityJig hence you see a call like so:
Code: [Select]
:base(new Circle())

This is a call to the base class's constructor. If you were to look up the constructor for EntityJig, you would find that it requires a DatabaseServices.Entity. The 'new' keyword is creating a circle, but it's NOT database resident and is handled and used by the EntityJig class for graphical purposes amongst other things.

2. yes - spot on.

LE

  • Guest
Re: Drag jitters 2
« Reply #21 on: September 27, 2007, 11:15:55 AM »
How about if we use (using Glenn class):

Code: [Select]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedGrDraw")]
public

Code: [Select]
void UpdateDimensions()
{
    Circle myCircle = (Circle)Entity;
    //AlignedDimension dim = (AlignedDimension)_dims[0].Dimension;
    //dim.XLine1Point = myCircle.Center;
    //dim.XLine2Point = _radiusPt;

    Point3d ctr = myCircle.Center, radiusPt = _radiusPt;
    double[] fromPoint = new double[2], toPoint = new double[2];
    fromPoint[0] = ctr.X;
    fromPoint[1] = ctr.Y;
    fromPoint[2] = ctr.Z;
    toPoint[0] = radiusPt.X;
    toPoint[1] = radiusPt.Y;
    toPoint[2] = radiusPt.Z;
    acedGrDraw(fromPoint, toPoint, 7, 7);

    //Vector3d xvec = dim.XLine2Point - dim.XLine1Point;
    //xvec = xvec.GetNormal();
    //Vector3d zvec = myCircle.Normal;
    //zvec = zvec.GetNormal();
    //Vector3d yvec = zvec.CrossProduct(xvec);
    //yvec = yvec.GetNormal();

    //yvec *= myCircle.Radius / 2;

    //dim.DimLinePoint = myCircle.Center + yvec;
}
« Last Edit: September 27, 2007, 11:19:16 AM by LE »

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Drag jitters 2
« Reply #22 on: September 27, 2007, 04:32:17 PM »
I'll look at that tonight Luis.

Glenn R

  • Guest
Re: Drag jitters 2
« Reply #23 on: September 27, 2007, 07:40:02 PM »
How about if we use (using Glenn class):

Code: [Select]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedGrDraw")]
public

Code: [Select]
void UpdateDimensions()
{
    Circle myCircle = (Circle)Entity;
    //AlignedDimension dim = (AlignedDimension)_dims[0].Dimension;
    //dim.XLine1Point = myCircle.Center;
    //dim.XLine2Point = _radiusPt;

    Point3d ctr = myCircle.Center, radiusPt = _radiusPt;
    double[] fromPoint = new double[2], toPoint = new double[2];
    fromPoint[0] = ctr.X;
    fromPoint[1] = ctr.Y;
    fromPoint[2] = ctr.Z;
    toPoint[0] = radiusPt.X;
    toPoint[1] = radiusPt.Y;
    toPoint[2] = radiusPt.Z;
    acedGrDraw(fromPoint, toPoint, 7, 7);

    //Vector3d xvec = dim.XLine2Point - dim.XLine1Point;
    //xvec = xvec.GetNormal();
    //Vector3d zvec = myCircle.Normal;
    //zvec = zvec.GetNormal();
    //Vector3d yvec = zvec.CrossProduct(xvec);
    //yvec = yvec.GetNormal();

    //yvec *= myCircle.Radius / 2;

    //dim.DimLinePoint = myCircle.Center + yvec;
}

Not going to work Luis, as that call to acedGrDraw is just going to draw a vector - you need to draw the dimension with extension lines just like AutoCAD does.

LE

  • Guest
Re: Drag jitters 2
« Reply #24 on: September 27, 2007, 09:19:04 PM »
Not going to work Luis, as that call to acedGrDraw is just going to draw a vector - you need to draw the dimension with extension lines just like AutoCAD does.

I guess, I missread the original request..... and do not use the dyn stuff - slap on my face sorry...  :oops:

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Drag jitters 2
« Reply #25 on: September 27, 2007, 10:05:25 PM »
KnownasLuis has a great ring to it.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Drag jitters 2
« Reply #26 on: September 27, 2007, 11:17:22 PM »
The way things go, my next step was to apply this to all the different kinds of entities. Line worked without a hitch until I looked at the dynamic dims (never have used those things personally). so now I have a whole new field of pain to investigate.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Drag jitters 2
« Reply #27 on: September 28, 2007, 11:14:58 AM »
KnownasLuis has a great ring to it.
I was almost expecting "TheCoderFormerlyKnownAsLuis" :-)

LE

  • Guest
Re: Drag jitters 2
« Reply #28 on: September 28, 2007, 01:35:40 PM »
KnownasLuis has a great ring to it.
I was almost expecting "TheCoderFormerlyKnownAsLuis" :-)

That's a great suggestion.... granted! (and thanks)  :)

Was a good suggestion, but the name is too long and does not appear in full .... so, went back to the previous one....  :-P
« Last Edit: September 28, 2007, 01:55:10 PM by KnownAsLuis »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Drag jitters 2
« Reply #29 on: September 28, 2007, 01:45:31 PM »
How about WillDeletePostsForFood?

:lmao:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst