Can anyone offset a line??? Please help a beginner!

Can anyone offset a line??? Please help a beginner!

Anonymous
Not applicable
829 Views
4 Replies
Message 1 of 5

Can anyone offset a line??? Please help a beginner!

Anonymous
Not applicable

hello,

 

I'm new to objectarx, and and have a little
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.

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?

 

thanks for help

 

chris

 

 

 

ads_point pt1, pt2;
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;
 }

 

// 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

 

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);

 

// Post the new entity to the
database
AcDbObjectId id;
postToDb(pLine, id);

 

pLine->close();

 

//Get the new coordinates of the new
points
AcGeMatrix3d xform;
AcDbEntity* pEnt;
AcGeVector3d
axis;

 

if (acdbOpenObject(pEnt, id, AcDb::kForRead) !=
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);

 


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();
0 Likes
830 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
How about this (just add error checking...):

Once you have created the line, let AutoCAD do the work for you!

{...}
double dist = 10.0;
AcDbVoidPtrArray ents;
pLine->getOffsetCurves(dist, ents);

// There should only be one, but call me superstitious...
for (int i=0; i < ents.length(); i++)
{
AcDbEntity *pEnt = ((AcRxObject*)(ents));
if (i=0)
{
postToDb(pEnt, id);
pEnt->close();
}
else
delete pEnt;
}
{...}

"C. Marx" wrote in message
news:[email protected]...
hello,

I'm new to objectarx, and and have a little 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.
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?

thanks for help

chris



ads_point pt1, pt2;
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;
}

// 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

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);

// Post the new entity to the database
AcDbObjectId id;
postToDb(pLine, id);

pLine->close();

//Get the new coordinates of the new points
AcGeMatrix3d xform;
AcDbEntity* pEnt;
AcGeVector3d axis;

if (acdbOpenObject(pEnt, id, AcDb::kForRead) != 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);


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();
0 Likes
Message 3 of 5

Anonymous
Not applicable
Ack! That's terrible....I should be shot.

the first line of the for loop should look like this:
AcDbEntity *pEnt = ((AcDbEntity*)(ents));

Hopefully that is safe 😉 If you're superstitious, you may want to use
this instead
AcDbEntity *pEnt = AcDbEntity::cast((AcRxObject*)(ents));

and then verify that pEnt != NULL before you use it.


Jon
0 Likes
Message 4 of 5

Anonymous
Not applicable
Thanks for answering me!

I check it out and tell you if I succeed.

Chris
0 Likes
Message 5 of 5

Anonymous
Not applicable
Okay, this solution is not ARX, but ads. However, it's simple. Try to run
acedCommand() with appropriate string parameters. That should do the trick.
C. Marx wrote in message
news:[email protected]...
hello,

I'm new to objectarx, and and have a little 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.
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?

thanks for help

chris



ads_point pt1, pt2;
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;
}

// 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

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);

// Post the new entity to the database
AcDbObjectId id;
postToDb(pLine, id);

pLine->close();

//Get the new coordinates of the new points
AcGeMatrix3d xform;
AcDbEntity* pEnt;
AcGeVector3d axis;

if (acdbOpenObject(pEnt, id, AcDb::kForRead) != 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);


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();
0 Likes