|
[code]struct resbuf oSysRb, iSysRb;
ads_real blc, blc1;
acedGetVar("USERR1", &oSysRb);
iSysRb.restype = RTREAL;
iSysRb.resval.rreal = 500;
blc = oSysRb.resval.rreal;
if (blc == 0)
{
if (acedGetReal("\n请输入比例尺<1:500>", &blc1) != RTNORM)
{
iSysRb.resval.rreal = 500;
acedSetVar("USERR1", &iSysRb);
}
acedSetVar("USERR1", &iSysRb);
blc = iSysRb.resval.rreal;
}
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForWrite);
CString blkName;
blkName.Format("%s", "GC200");
if (!pBlkTbl->has(blkName))
{
acutPrintf("\n当前图形中未包含GC200的块定义!");
pBlkTbl->close();
return;
}
double xyzScale = blc * 0.001;
double textH = blc * 0.002; // 设置文字高度
CString strH;
strH.Format("%.3lf", textH);
char strTag[100];
CString str("height");
strncpy(strTag,(LPCTSTR)str,sizeof(strTag));
int rc, i;
ads_point pt1;
FILE *FP;
char height[80];
double r;
TCHAR *fName;
struct resbuf *rb;
rb = acutNewRb(RTSTR);
int stat = acedGetFileD("选择txt文件", NULL, "txt;dat", 0, rb);
if ((stat != RTNORM) || (rb == NULL))
{
acutRelRb(rb);
return;
}
const size_t nSize = _tcslen(rb->resval.rstring) + 1;
fName = (TCHAR*)acad_malloc(nSize * sizeof(TCHAR));
strcpy(fName, rb->resval.rstring);
acutRelRb(rb);
CString filename;
filename.Format("%s", fName);
FP = fopen(filename, "r"); //以只读形式打开文件
do
{
fscanf(FP, "%d, %lf, %lf, %lf", &i, &pt1[X], &pt1[Y], &pt1[Z]);
AcGePoint3d blkbasePt (pt1[X], pt1[Y], pt1[Z]);
AcGePoint3d textPt (pt1[X] + 0.0012 * blc, pt1[Y] - 0.001 * blc, 0.0);
AcGePoint3d AlimPt (pt1[X] + 0.0012 * blc, pt1[Y], 0.0);
r = pt1[Z];
acdbRToS(r, 2, 2, height);
AcDbObjectId blkDefId;
pBlkTbl->getAt(blkName, blkDefId);
AcDbBlockReference *pBlkRef = new AcDbBlockReference(blkbasePt, blkDefId);
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);
pBlkTbl->close();
// 块比例系数
pBlkRef->setScaleFactors(xyzScale);
// 扩展数据
struct resbuf *pRb;
CString appName = "SOUTH";
CString typeName = "202101";
pRb = acutBuildList(AcDb::kDxfRegAppName, appName, AcDb::kDxfXdAsciiString, typeName, RTNONE);
pBlkRef->setXData(pRb);
acutRelRb(pRb);
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId, pBlkRef);
// 插入属性
AcDbEntity *pEnt;
acdbOpenObject(pEnt, entId, AcDb::kForWrite);
AcDbBlockTableRecord *pBlkDefRcd;
acdbOpenObject(pBlkDefRcd, blkDefId, AcDb::kForRead);
AcDbBlockTableRecordIterator *pItr;
pBlkDefRcd->newIterator(pItr);
for (pItr->start(); !pItr->done(); pItr->step())
{
pItr->getEntity(pEnt, AcDb::kForRead);
AcDbAttributeDefinition *pAttDef = new AcDbAttributeDefinition;
pAttDef = AcDbAttributeDefinition::cast(pEnt);
AcDbAttribute *pAttr = new AcDbAttribute;
pAttr->setPropertiesFrom(pAttDef);
pAttr->setHorizontalMode(AcDb::kTextLeft); // 左对齐
pAttr->setVerticalMode(AcDb::kTextVertMid); // 左中
pAttr->setPosition(textPt); // 文本的位置点
pAttr->setAlignmentPoint(AlimPt); // 对齐点
pAttr->setWidthFactor(0.8); // 宽度比例
pAttr->setHeight(textH); // 高度
pAttr->setTag(strTag); // 属性标签
pAttr->setTextString(height); // 属性值
// 扩展数据
struct resbuf *pRb;
CString appName = "SOUTH";
CString typeName = "202111";
pRb = acutBuildList(AcDb::kDxfRegAppName, appName, AcDb::kDxfXdAsciiString, typeName, RTNONE);
pAttr->setXData(pRb);
acutRelRb(pRb);
// 追加属性
pBlkRef->appendAttribute(pAttr);
pAttr->close();
}
pBlkRef->setLayer("GCD");
delete pItr;
pBlkDefRcd->close();
pEnt->close();
pBlkRef->close();
pBlkTblRcd->close();
rc = feof(FP);
}
while (rc == 0);
fclose(FP); //关闭文件
acedCommand(RTSTR, "ZOOM", RTSTR, "E", 0);[/code] |
|