- UID
- 5043
- 积分
- 1347
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-13
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Set oblique angle of aligned dimensions to a certain angle relative to an axis in the current UCS
Consider this: You want to set the oblique angle of an aligned dimension to an arbitrary value (for example, 30 degrees from the X-axis of the current UCS to one of the extension line within which the dimension is constructed).
To do this, you need to realize that that the Oblique angles are calculated relative to the line containing the two start points of the two extension lines of the dimension. Let's call this the base line of aligned dimensions. With this in mind, if the angle from the baseline to X axis is angBaselineToX, and the oblique angle relative to X axis will be angRelOblique, then (- angBaselineToX + angRelOblique) should be sent to AcDbAlignedDimension::oblique() as the input parameter. The following code does this:
- void setDimTxtOblique()
- {
- AcGePoint3d pt1, pt2;
- double baseAng, oblAng;
- AcGePoint3d ptDim;
- AcGeMatrix3d m;
- Acad::ErrorStatus es;
- int ret;
- AcDbDatabase *pDb =
- acdbHostApplicationServices()->workingDatabase();
- // get start and end points
- if(acedGetPoint(NULL, L"\nFirst point: ",
- asDblArray(pt1))!= RTNORM)
- return;
- if( acedGetPoint(asDblArray(pt1), L"\nSecond point: ",
- asDblArray(pt2) ) != RTNORM)
- return;
- // get text position
- AcGePoint3d ptMid( 0.5*(pt1.x + pt2.x), 0.5*(pt1.y + pt2.y),
- 0.5*(pt1.z + pt2.z));
- if(acedGetPoint(asDblArray(ptMid), L"\nDim Line position:",
- asDblArray(ptDim) ) != RTNORM)
- return;
- // get the oblique angle from users
- // please note it's relative to the X axis of current UCS
- ret = acedGetAngle(NULL, L"Oblique angle: <0.0>", &oblAng);
- if( ret == RTNONE ) oblAng = 0.0;
- else if ( ret != RTNORM ) return;
- // calculate the dimension baseline angle
- baseAng = acutAngle(asDblArray(pt1), asDblArray(pt2));
- // create aligned dimension
- AcDbAlignedDimension* pDim = new AcDbAlignedDimension;
- es = pDim->setXLine1Point(pt1); assert(es==Acad::eOk);
- es = pDim->setXLine2Point(pt2); assert(es==Acad::eOk);
- // get transform matrix
- if( !acdbUcsMatrix(m, pDb) ) return;
- // set line points and text position as default
- es=pDim->setDimLinePoint(ptDim); assert(es==Acad::eOk);
- es=pDim->useDefaultTextPosition(); assert(es==Acad::eOk);
- es=pDim->setOblique(oblAng-baseAng); assert(es==Acad::eOk);
- // set default database and transform it to WCS
- pDim->setDatabaseDefaults();
- es = pDim->transformBy(m); assert(es==Acad::eOk);
- // append it to AutoCAD database
- AcDbBlockTableRecord *pBlkRec;
- AcDbObjectId objID;
- es = acdbOpenObject(pBlkRec, pDb->currentSpaceId(),
- AcDb::kForWrite);
- assert(es==Acad::eOk);
- es =pBlkRec->appendAcDbEntity (objID, pDim) ;
- assert(es==Acad::eOk);
- // close it
- pDim->close();
- pBlkRec->close();
- return;
- }
|
|