Message 1 of 5
Can anyone offset a line??? Please help a beginner!
Not applicable
11-14-2001
11:30 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hello,
I'm new to objectarx, and and have a little
problem:
problem:
I try to offset a AcDbLine.
First I create a line, after this I want to
offset this line in objectarx about 10cm to the right,
like the command
'offset' in autocad do.
offset this line in objectarx about 10cm to the right,
like the command
'offset' in autocad do.
How do I figure out the new points of the new
line?
The code below, that's how far I came.
Is that the the right way or
is there a better way of doing this?
line?
The code below, that's how far I came.
Is that the the right way or
is there a better way of doing this?
thanks for help
chris
ads_point pt1, pt2;
int
retval;
Acad::ErrorStatus es;
int
retval;
Acad::ErrorStatus es;
try
{
// get the first point
from the user. Do not specify a base point.
//...
if
((retval = acedGetPoint(NULL, LoadMyResourceString(IDS_STRING101), pt1)) !=
RTNORM)
throw retval;
// get the second point from the
user, using the first point as a base point.
//...
if ((retval
= acedGetPoint(pt1, LoadMyResourceString(IDS_STRING102), pt2)) !=
RTNORM)
throw retval;
}
catch (int
e)
{
if (e == RTCAN)
return
Acad::eUserBreak;
if (e == RTERROR)
return
Acad::eInvalidInput;
}
{
// get the first point
from the user. Do not specify a base point.
//...
if
((retval = acedGetPoint(NULL, LoadMyResourceString(IDS_STRING101), pt1)) !=
RTNORM)
throw retval;
// get the second point from the
user, using the first point as a base point.
//...
if ((retval
= acedGetPoint(pt1, LoadMyResourceString(IDS_STRING102), pt2)) !=
RTNORM)
throw retval;
}
catch (int
e)
{
if (e == RTCAN)
return
Acad::eUserBreak;
if (e == RTERROR)
return
Acad::eInvalidInput;
}
// Instantiate an AcDbLine pointer. Use the
two user-chosen
// points as endpoints.
// Since AcDbLine's constructor
uses AcGePoint2d, but acedGetPoint returns ads_point,
// you must find a way
to translate old style to new style. This can be done either by
//
assigning each array member individually, or by calling asPnt3d() from
geassign.h
two user-chosen
// points as endpoints.
// Since AcDbLine's constructor
uses AcGePoint2d, but acedGetPoint returns ads_point,
// you must find a way
to translate old style to new style. This can be done either by
//
assigning each array member individually, or by calling asPnt3d() from
geassign.h
AcDbLine* pLine = new AcDbLine(asPnt3d(pt1),
asPnt3d(pt2));
// Make sure you created the line...
if
(!pLine)
{
acedAlert(LoadMyResourceString(IDS_STRING103));
return
Acad::eOutOfMemory;
}
// change the color property of the new line
to this value.
int color = 2;
pLine->setColorIndex(color);
asPnt3d(pt2));
// Make sure you created the line...
if
(!pLine)
{
acedAlert(LoadMyResourceString(IDS_STRING103));
return
Acad::eOutOfMemory;
}
// change the color property of the new line
to this value.
int color = 2;
pLine->setColorIndex(color);
// Post the new entity to the
database
AcDbObjectId id;
postToDb(pLine, id);
database
AcDbObjectId id;
postToDb(pLine, id);
pLine->close();
//Get the new coordinates of the new
points
AcGeMatrix3d xform;
AcDbEntity* pEnt;
AcGeVector3d
axis;
points
AcGeMatrix3d xform;
AcDbEntity* pEnt;
AcGeVector3d
axis;
if (acdbOpenObject(pEnt, id, AcDb::kForRead) !=
Acad::eOk)
{
id->close();
return
Acad::eNullEntityPointer;
}
id->close();
Acad::eOk)
{
id->close();
return
Acad::eNullEntityPointer;
}
id->close();
AcGeMatrix3d
ecsMat;
pEnt->getEcs(ecsMat);
AcGePoint3d origin;
AcGeVector3d
xAxis;
AcGeVector3d yAxis;
ecsMat.getCoordSystem(origin, xAxis, yAxis,
axis);
ecsMat;
pEnt->getEcs(ecsMat);
AcGePoint3d origin;
AcGeVector3d
xAxis;
AcGeVector3d yAxis;
ecsMat.getCoordSystem(origin, xAxis, yAxis,
axis);
xform.setToRotation(-90.0, axis, ucsToWcs(asPnt3d(pt1)));
es =
pEnt->upgradeOpen();
if (es ==
Acad::eOk)
{
es =
pEnt->transformBy(xform);
if (es !=
Acad::eOk)
return Acad::eNotApplicable;
}
pEnt->close();
pEnt->close();