|
使用 ObjectARX 了解尺寸的公差和限制
使用 AutoCAD 尺寸时,用户可以将这些样式应用于尺寸图元:"无"、"偏差"、"对称"、"限制"和"基本"。可能不容易看出哪些维度系统变量适用于这些样式覆盖。虽然存在"dimlim"维度变量,但"dimnone","dimdev","dimsym"或"dimbas"维度变量并不存在。
在解释尺寸的公差和限值时,首先解释了公差和限值的背景。此过程涉及四个维度变量:
DIMTOL
DIMLIM
DIMTM
DIMTP
DIMTOL = 尺寸公差可以是开或关。如果 DIMTP = DIMTM,则尺寸将显示一个值,后跟带有"+"、"-"符号和数字的公差,或者维度值后跟两个相互堆叠的值,一个值带有"+"号(DIMTP - 尺寸公差加号),另一个值带有"-"符号(DIMTM - 尺寸公差减值)。
DIMLIM = 尺寸限制可以是开/关,尺寸将显示堆叠值,表示尺寸的上限(上)和下限(下)的值。如果 DIMTP = DIMTM,则显示的值将彼此相等。
维度是复杂的实体,由 AcDbDimension 表示,并驻留在模型空间块表或许多"图纸空间布局块表"之一中。每个维度都与一个匿名块相关,该块是 AcDbBlockTableRecord 的一个实例,与任何其他块一样,它包含表示维度块的实体。维度实体还引用 AcDbDimStyleTableRecord,该记录控制维度实体的整体外观(维度样式)。
维度可能包含覆盖(请参见 DIMOVERRIDE 命令)。将替代应用于维度时,替代信息将存储为扩展实体数据 (Xdata)。有关覆盖信息的讨论,请参阅 ObjectARX 文档:"维度样式覆盖"。
在 ObjectARX 中,您可以直接操作此 Xdata,也可以直接覆盖相应的维度变量。
在以"偏差"样式显示尺寸时,似乎存在一个悖论(请参见 AutoCAD 的"修改尺寸样式"对话框)。如果尺寸变量 DIMTP 和 DIMTM 的值均为 0.00,并且"偏差"选项应用于尺寸,则该尺寸将显示尺寸值和一组堆叠公差,一个为"+0.000",另一个为"-0.000"。这似乎是一个矛盾,因为前面提到的如果 DIMTP = DIMTM 且 DIMTOL = ON,则维度将显示为对称。为了使AutoCAD以"偏差"方式显示尺寸,AutoCAD将DIMITM的值更改为1x10-9,这确实是一个非常小的值。话虽如此,如果"DIMTP"不等于"DIMTM"(无论大小)并且"DIMTOL"设置为"ON",则尺寸将显示为"偏差"样式。
下面是一个函数的示例,该函数根据其 Xdata 结果缓冲区操作所选维度:
[code]static void selectDim(AcDbDimension *&pDim)
{
ads_name ent;
ads_point pt;
if (RTNORM != acedEntSel(L"\nSelect a Dimension",ent,pt))
{
acutPrintf(L"\nFailed to select an entity");
return;
}
AcDbObjectId objId = NULL;
Acad::ErrorStatus es;
acdbGetObjectId (objId , ent);
AcDbObject *oObj = NULL;
es = acdbOpenObject (oObj,
objId,
AcDb::kForRead);
if(Acad::eOk == es)
{
if(oObj->isKindOf(AcDbDimension::desc()))
{
pDim = (AcDbDimension*)oObj;
}
else
{
acutPrintf(_T("\nSorry that is \
not a dimension entity."));
oObj->close();
}
}
}
static void dimTest()
{
AcDbDimension* pDim = NULL;
selectDim(pDim);
if(!pDim) return;
struct resbuf* pRb;
pDim->upgradeOpen();
//Refer to the ObjectARX help -
// 'Dimension Style Overrides'
// for the appropriate DXF group code values.
pRb = acutBuildList(
AcDb::kDxfRegAppName,
_T("ACAD"),
AcDb::kDxfXdAsciiString,
_T("DSTYLE"),
AcDb::kDxfXdControlString,
_T("{"),
AcDb::kDxfXdInteger16,
48,
AcDb::kDxfXdReal,
0.0000000000000001,
AcDb::kDxfXdInteger16,
71,
AcDb::kDxfXdInteger16,
1,
AcDb::kDxfXdControlString,
_T("}"),
RTNONE);
pDim->setXData(pRb);
acutRelRb(pRb);
pDim->close();
}
Here is an example of a function that manipulates a selected dimension in terms of it's dimension variables, please note that the dimension variable method is a wrapper for manipulating the underlying Xdata:
static void dimLimVar()
{
AcDbDimension* pDim = NULL;
selectDim(pDim);
if(!pDim) return;
pDim->upgradeOpen();
pDim->setDimlim(Adesk::kTrue);
pDim->setDimtol(Adesk::kFalse);
pDim->close();
}
Here are more examples:
static void dimNone()
{
AcDbDimension* pDim = NULL;
selectDim(pDim);
if(!pDim) return;
struct resbuf* pRb;
pDim->upgradeOpen();
pRb = acutBuildList(
AcDb::kDxfRegAppName,
_T("ACAD"),
AcDb::kDxfXdAsciiString,
_T("DSTYLE"),
AcDb::kDxfXdControlString,
_T("{"),
AcDb::kDxfXdInteger16,
48,
AcDb::kDxfXdReal,
0.0,
AcDb::kDxfXdControlString,
_T("}"),
RTNONE);
pDim->setXData(pRb);
acutRelRb(pRb);
pDim->close();
}
// This is command 'DIMSYM'
static void dimSym()
{
AcDbDimension* pDim = NULL;
selectDim(pDim);
if(!pDim) return;
struct resbuf* pRb;
pDim->upgradeOpen();
pRb = acutBuildList(
AcDb::kDxfRegAppName,
_T("ACAD"),
AcDb::kDxfXdAsciiString,
_T("DSTYLE"),
AcDb::kDxfXdControlString,
_T("{"),
AcDb::kDxfXdInteger16,
71,
AcDb::kDxfXdInteger16,
1,
AcDb::kDxfXdControlString,
_T("}"),
RTNONE);
pDim->setXData(pRb);
acutRelRb(pRb);
pDim->close();
}
// This is command 'DIMLIMIT'
static void dimLimit()
{
AcDbDimension* pDim = NULL;
selectDim(pDim);
if(!pDim) return;
struct resbuf* pRb;
pDim->upgradeOpen();
pRb = acutBuildList(
AcDb::kDxfRegAppName,
_T("ACAD"),
AcDb::kDxfXdAsciiString,
_T("DSTYLE"),
AcDb::kDxfXdControlString,
_T("{"),
AcDb::kDxfXdInteger16,
72,
AcDb::kDxfXdInteger16, 1,
AcDb::kDxfXdControlString
, _T("}"),
RTNONE);
pDim->setXData(pRb);
acutRelRb(pRb);
pDim->close();
}
// This is command 'DIMBAS'
static void dimBas()
{
AcDbDimension* pDim = NULL;
selectDim(pDim);
if(!pDim) return;
struct resbuf* pRb;
pDim->upgradeOpen();
pRb = acutBuildList(
AcDb::kDxfRegAppName,
_T("ACAD"),
AcDb::kDxfXdAsciiString,
_T("DSTYLE"),
AcDb::kDxfXdControlString,
_T("{"),
AcDb::kDxfXdInteger16,
147,
AcDb::kDxfXdReal,
-0.09,
AcDb::kDxfXdControlString,
_T("}"),
RTNONE);
pDim->setXData(pRb);
acutRelRb(pRb);
pDim->close();
}
// This is command 'DIMTOLVAR'
static void dimTolVar()
{
AcDbDimension* pDim = NULL;
selectDim(pDim);
if(!pDim) return;
pDim->upgradeOpen();
pDim->setDimtol(Adesk::kTrue);
pDim->setDimlim(Adesk::kFalse);
pDim->close();
}
// This is command 'DIMTPVAR'
static void dimTPVar()
{
AcDbDimension* pDim = NULL;
selectDim(pDim);
if(!pDim) return;
double curval = 0.0;
ads_real newval;
curval = pDim->dimtp();
acutPrintf(_T("\nCurrent value of DIMTP = %lf"),
curval);
acedInitGet(RSG_NONULL + RSG_NONEG, NULL);
acedGetReal(_T("\nNew value for DIMTP: "),
&newval);
pDim->upgradeOpen();
pDim->setDimtp((double)newval);
pDim->close();
}
// This is command 'DIMTMVAR'
static void dimTMVar()
{
AcDbDimension* pDim = NULL;
selectDim(pDim);
if(!pDim) return;
double curval = 0.0;
ads_real newval;
curval = pDim->dimtm();
acutPrintf(_T("\nCurrent value of DIMTM = %lf"), curval);
acedInitGet(RSG_NONULL + RSG_NONEG, NULL);
acedGetReal(_T("\nNew value for DIMTM: "), &newval);
pDim->upgradeOpen();
pDim->setDimtm((double)newval);
pDim->close();
}[/code] |
|