.NET

Reply
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 1 of 5 (206 Views)

How to use dimension in custom ucs?

206 Views, 4 Replies
07-09-2005 09:01 AM
when I work in custom ucs, my own dimension command always get wrong points coordinates, I think I must use cordinate convertion through transformby method , but I don't know how to use it, could someone give me some codes about how to use it .
*Albert Szilvasy
Message 2 of 5 (206 Views)

Re: How to use dimension in custom ucs?

07-14-2005 09:00 AM in reply to: netcai
Editor.GetPoint returns points in the current UCS. You must transform these
points to WCS:
Matrix3d mat = ed.CurrentUserCoordinateSystem.Inverse();

Point3d ptInUcs;

ptInUcs = ptInUcs.TransformBy(mat);



Albert

wrote in message news:4897130@discussion.autodesk.com...
when I work in custom ucs, my own dimension command always get wrong points
coordinates, I think I must use cordinate convertion through transformby
method , but I don't know how to use it, could someone give me some codes
about how to use it .
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 3 of 5 (206 Views)

Re: How to use dimension in custom ucs?

07-15-2005 01:48 AM in reply to: netcai
I don't understand why you use ed.CurrentUserCoordinateSystem.Inverse() instead of ed.CurrentUserCoordinateSystem. I use ed.CurrentUserCoordinateSystem to transform a point from wcs to current ucs.
the following is my dimension code , in wcs it works well ,but in custom ucs,the dimension point is not correct, i have tried to transform points to WCS,but problem still exit.


enum DimensionDirection
{
Horizental, Vertical, Rotated
}

class RotatedDimensionJig : EntityJig
{
Point3d mStartPt, mEndPt, mLocPt;
Point3d mNewEndPt;
double mRotation;
ObjectId mDimLayer;
int mPromptCounter;
Matrix3d m3d;
double curUcsAngle;
DimensionDirection mDimensionDirection;
public RotatedDimensionJig(Point3d startPt, Point3d endPt,ObjectId dimLayer)
: base(new RotatedDimension(0, new Point3d(), new Point3d(), new Point3d(), "", ObjectId.Null))
{
m3d = Arx.Ed.CurrentUserCoordinateSystem ;
Plane p = new Plane(Point3d.Origin, new Vector3d(0, 0, 1));
curUcsAngle = m3d.CoordinateSystem3d.Xaxis.AngleOnPlane(p);
mStartPt = startPt;
mEndPt = endPt;
mPromptCounter = 0;
mDimensionDirection = DimensionDirection.Horizental;
mDimLayer = dimLayer;
}


protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptOptions jigOpts = new JigPromptOptions();
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted | UserInputControls.NoNegativeResponseAccepted | UserInputControls.NullResponseAccepted);
if (mPromptCounter == 0)
{
jigOpts.Message = "\nPlease Input Location of dimension";
PromptPointResult dres = prompts.AcquirePoint(jigOpts);

Point3d locPointTemp = dres.Value;
//Arx.Ed.WriteMessage("\n"+locPointTemp.ToString());
if (locPointTemp != mLocPt)
{
mLocPt = locPointTemp;
}
else
return SamplerStatus.NoChange;

if (dres.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
else
return SamplerStatus.OK;
}
else if (mPromptCounter == 1)
{
jigOpts.Message = "\nPlease Input Next Point";
PromptPointResult dres = prompts.AcquirePoint(jigOpts);

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

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

}
else
{
return SamplerStatus.NoChange;
}
}

protected override bool Update()
{
try
{

switch (mPromptCounter)
{
case 0:
GetRotationAndDimensionDirection();
break;
case 1:
break;
}
GetNewEndPoint();
RotatedDimension dimEnt = ((RotatedDimension)Entity);
dimEnt.XLine1Point = mStartPt.TransformBy(m3d);
dimEnt.XLine2Point = mNewEndPt.TransformBy(m3d); ;
dimEnt.DimLinePoint = mLocPt.TransformBy(m3d); ;
dimEnt.LayerId = mDimLayer;
dimEnt.Rotation = mRotation;
}
catch (System.Exception)
{
return false;
}
return true;

}
void GetRotationAndDimensionDirection()
{
double deltaX = mEndPt.X - mStartPt.X;
double deltaY = mEndPt.Y - mStartPt.Y;
mRotation = curUcsAngle;

if (
System.Math.Abs(deltaY) < 1e-3 ||
(Math.Abs(mLocPt.X - mStartPt.X) < Math.Abs(mEndPt.X - mStartPt.X)) &&
(Math.Abs(mLocPt.X - mEndPt.X) < Math.Abs(mEndPt.X - mStartPt.X))) //horizental
{
mRotation += 0;
mDimensionDirection = DimensionDirection.Horizental;
}
else if (
System.Math.Abs(deltaX) < 1e-3 ||
(Math.Abs(mLocPt.Y - mStartPt.Y) < Math.Abs(mEndPt.Y - mStartPt.Y)) &&
(Math.Abs(mLocPt.Y - mEndPt.Y) < Math.Abs(mEndPt.Y - mStartPt.Y))) //vertical
{
mDimensionDirection = DimensionDirection.Vertical;
mRotation += System.Math.PI / 2;
}
else // rotated
{
mDimensionDirection = DimensionDirection.Rotated;
double k = deltaY / deltaX;
mRotation += System.Math.Atan(k);
}
}

void GetNewEndPoint()
{
switch (mDimensionDirection)
{
case DimensionDirection.Horizental:
mNewEndPt = new Point3d(mEndPt.X, mStartPt.Y, 0);
break;
case DimensionDirection.Vertical:
mNewEndPt = new Point3d(mStartPt.X, mEndPt.Y, 0);
break;
case DimensionDirection.Rotated:
double deltaX = mEndPt.X - mStartPt.X;
double deltaY = mEndPt.Y - mStartPt.Y;
double k = deltaY / deltaX;
double temp1 = mEndPt.Y - mStartPt.Y + mEndPt.X / k + mStartPt.X * k;
double temp2 = 1 / k + k;
double x = temp1 / temp2;
double y = mEndPt.X * k + mStartPt.Y - k * mStartPt.X;
mNewEndPt = new Point3d(x, y, 0);
break;
default:
break;
}

}

public void setPromptCounter(int i)
{
mPromptCounter = i;
if (i == 1)
{
mStartPt = mNewEndPt;
}
}



public RotatedDimension GetEntity()
{

RotatedDimension dimEnt = ((RotatedDimension)Entity);
return new RotatedDimension(dimEnt.Rotation, dimEnt.XLine1Point, dimEnt.XLine2Point, dimEnt.DimLinePoint, "", ObjectId.Null);
}

public DimensionDirection GetDimensionDirection()
{
return mDimensionDirection;
}
}


[CommandMethod("Cai_DimLinear")]
public static void DoIt()
{

#region Get start point and end point
string prompt;
PromptPointOptions po;
PromptPointResult res;

prompt = "\nPlease Input Start Point";
po = new PromptPointOptions(prompt);
po.AllowNone = true;
res = Arx.Ed.GetPoint(po);
if (res.Status != PromptStatus.OK) return;
Point3d startPoint = res.Value;

prompt = "\nPlease Input Next Point";
po.UseBasePoint = true;
po.UseDashedLine = true;
po.BasePoint = startPoint;
po.Message = prompt;
res = Arx.Ed.GetPoint(po);
if (res.Status != PromptStatus.OK) return;
Point3d endPoint = res.Value;
#endregion

//Create Dimensionjig
RotatedDimensionJig jig = new RotatedDimensionJig(startPoint, endPoint, layerId);
ArrayList list = new ArrayList();

//first call drag to get the major axis
jig.setPromptCounter(0);
if (Arx.Ed.Drag(jig).Status != PromptStatus.OK) return;

RotatedDimension firstDim = jig.GetEntity();
firstDim.LayerId = layerId;
list.Add(Arx.AddEntity(firstDim));

bool exit = false;
do
{
jig.setPromptCounter(1);
PromptResult nRes = Arx.Ed.Drag(jig);
if (nRes.Status != PromptStatus.OK)
{
exit = true;
}
else
{
RotatedDimension nextDim = jig.GetEntity();
if (Math.Abs(nextDim.Measurement) > 1e-3)
{
nextDim.LayerId = layerId;
list.Add(Arx.AddEntity(nextDim));
}
}
} while (!exit);
}
*Albert Szilvasy
Message 4 of 5 (206 Views)

Re: How to use dimension in custom ucs?

07-15-2005 08:48 AM in reply to: netcai
AcquirePoint unlike GetPoint returns the point in WCS so you don't need to
transform it at all.

Albert
wrote in message news:4902418@discussion.autodesk.com...
I don't understand why you use ed.CurrentUserCoordinateSystem.Inverse()
instead of ed.CurrentUserCoordinateSystem. I use
ed.CurrentUserCoordinateSystem to transform a point from wcs to current ucs.
the following is my dimension code , in wcs it works well ,but in custom
ucs,the dimension point is not correct, i have tried to transform points to
WCS,but problem still exit.


enum DimensionDirection
{
Horizental, Vertical, Rotated
}

class RotatedDimensionJig : EntityJig
{
Point3d mStartPt, mEndPt, mLocPt;
Point3d mNewEndPt;
double mRotation;
ObjectId mDimLayer;
int mPromptCounter;
Matrix3d m3d;
double curUcsAngle;
DimensionDirection mDimensionDirection;
public RotatedDimensionJig(Point3d startPt, Point3d
endPt,ObjectId dimLayer)
: base(new RotatedDimension(0, new Point3d(), new Point3d(),
new Point3d(), "", ObjectId.Null))
{
m3d = Arx.Ed.CurrentUserCoordinateSystem ;
Plane p = new Plane(Point3d.Origin, new Vector3d(0, 0, 1));
curUcsAngle = m3d.CoordinateSystem3d.Xaxis.AngleOnPlane(p);
mStartPt = startPt;
mEndPt = endPt;
mPromptCounter = 0;
mDimensionDirection = DimensionDirection.Horizental;
mDimLayer = dimLayer;
}


protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptOptions jigOpts = new JigPromptOptions();
jigOpts.UserInputControls =
(UserInputControls.Accept3dCoordinates |
UserInputControls.NoZeroResponseAccepted |
UserInputControls.NoNegativeResponseAccepted |
UserInputControls.NullResponseAccepted);
if (mPromptCounter == 0)
{
jigOpts.Message = "\nPlease Input Location of
dimension";
PromptPointResult dres = prompts.AcquirePoint(jigOpts);

Point3d locPointTemp = dres.Value;
//Arx.Ed.WriteMessage("\n"+locPointTemp.ToString());
if (locPointTemp != mLocPt)
{
mLocPt = locPointTemp;
}
else
return SamplerStatus.NoChange;

if (dres.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
else
return SamplerStatus.OK;
}
else if (mPromptCounter == 1)
{
jigOpts.Message = "\nPlease Input Next Point";
PromptPointResult dres = prompts.AcquirePoint(jigOpts);

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

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

}
else
{
return SamplerStatus.NoChange;
}
}

protected override bool Update()
{
try
{

switch (mPromptCounter)
{
case 0:
GetRotationAndDimensionDirection();
break;
case 1:
break;
}
GetNewEndPoint();
RotatedDimension dimEnt = ((RotatedDimension)Entity);
dimEnt.XLine1Point = mStartPt.TransformBy(m3d);
dimEnt.XLine2Point = mNewEndPt.TransformBy(m3d); ;
dimEnt.DimLinePoint = mLocPt.TransformBy(m3d); ;
dimEnt.LayerId = mDimLayer;
dimEnt.Rotation = mRotation;
}
catch (System.Exception)
{
return false;
}
return true;

}
void GetRotationAndDimensionDirection()
{
double deltaX = mEndPt.X - mStartPt.X;
double deltaY = mEndPt.Y - mStartPt.Y;
mRotation = curUcsAngle;

if (
System.Math.Abs(deltaY) < 1e-3 ||
(Math.Abs(mLocPt.X - mStartPt.X) < Math.Abs(mEndPt.X -
mStartPt.X)) &&
(Math.Abs(mLocPt.X - mEndPt.X) < Math.Abs(mEndPt.X -
mStartPt.X))) //horizental
{
mRotation += 0;
mDimensionDirection = DimensionDirection.Horizental;
}
else if (
System.Math.Abs(deltaX) < 1e-3 ||
(Math.Abs(mLocPt.Y - mStartPt.Y) < Math.Abs(mEndPt.Y -
mStartPt.Y)) &&
(Math.Abs(mLocPt.Y - mEndPt.Y) < Math.Abs(mEndPt.Y -
mStartPt.Y))) //vertical
{
mDimensionDirection = DimensionDirection.Vertical;
mRotation += System.Math.PI / 2;
}
else // rotated
{
mDimensionDirection = DimensionDirection.Rotated;
double k = deltaY / deltaX;
mRotation += System.Math.Atan(k);
}
}

void GetNewEndPoint()
{
switch (mDimensionDirection)
{
case DimensionDirection.Horizental:
mNewEndPt = new Point3d(mEndPt.X, mStartPt.Y, 0);
break;
case DimensionDirection.Vertical:
mNewEndPt = new Point3d(mStartPt.X, mEndPt.Y, 0);
break;
case DimensionDirection.Rotated:
double deltaX = mEndPt.X - mStartPt.X;
double deltaY = mEndPt.Y - mStartPt.Y;
double k = deltaY / deltaX;
double temp1 = mEndPt.Y - mStartPt.Y + mEndPt.X / k
+ mStartPt.X * k;
double temp2 = 1 / k + k;
double x = temp1 / temp2;
double y = mEndPt.X * k + mStartPt.Y - k *
mStartPt.X;
mNewEndPt = new Point3d(x, y, 0);
break;
default:
break;
}

}

public void setPromptCounter(int i)
{
mPromptCounter = i;
if (i == 1)
{
mStartPt = mNewEndPt;
}
}



public RotatedDimension GetEntity()
{

RotatedDimension dimEnt = ((RotatedDimension)Entity);
return new RotatedDimension(dimEnt.Rotation,
dimEnt.XLine1Point, dimEnt.XLine2Point, dimEnt.DimLinePoint, "",
ObjectId.Null);
}

public DimensionDirection GetDimensionDirection()
{
return mDimensionDirection;
}
}


[CommandMethod("Cai_DimLinear")]
public static void DoIt()
{

#region Get start point and end point
string prompt;
PromptPointOptions po;
PromptPointResult res;

prompt = "\nPlease Input Start Point";
po = new PromptPointOptions(prompt);
po.AllowNone = true;
res = Arx.Ed.GetPoint(po);
if (res.Status != PromptStatus.OK) return;
Point3d startPoint = res.Value;

prompt = "\nPlease Input Next Point";
po.UseBasePoint = true;
po.UseDashedLine = true;
po.BasePoint = startPoint;
po.Message = prompt;
res = Arx.Ed.GetPoint(po);
if (res.Status != PromptStatus.OK) return;
Point3d endPoint = res.Value;
#endregion

//Create Dimensionjig
RotatedDimensionJig jig = new RotatedDimensionJig(startPoint,
endPoint, layerId);
ArrayList list = new ArrayList();

//first call drag to get the major axis
jig.setPromptCounter(0);
if (Arx.Ed.Drag(jig).Status != PromptStatus.OK) return;

RotatedDimension firstDim = jig.GetEntity();
firstDim.LayerId = layerId;
list.Add(Arx.AddEntity(firstDim));

bool exit = false;
do
{
jig.setPromptCounter(1);
PromptResult nRes = Arx.Ed.Drag(jig);
if (nRes.Status != PromptStatus.OK)
{
exit = true;
}
else
{
RotatedDimension nextDim = jig.GetEntity();
if (Math.Abs(nextDim.Measurement) > 1e-3)
{
nextDim.LayerId = layerId;
list.Add(Arx.AddEntity(nextDim));
}
}
} while (!exit);
}
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 5 of 5 (206 Views)

Re: How to use dimension in custom ucs?

07-16-2005 12:04 AM in reply to: netcai
thanks very much . Now my dimension command works well.
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!