一起学ObjectARX[ARX读取数据展Cass一般高程点]
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;
CString str("height");
strncpy(strTag,(LPCTSTR)str,sizeof(strTag));
int rc, i;
ads_point pt1;
FILE *FP;
char height;
double r;
TCHAR *fName;
struct resbuf *rb;
rb = acutNewRb(RTSTR);
intstat = 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, &pt1, &pt1);
AcGePoint3d blkbasePt (pt1, pt1, pt1);
AcGePoint3d textPt (pt1 + 0.0012 * blc, pt1 - 0.001 * blc, 0.0);
AcGePoint3d AlimPt (pt1 + 0.0012 * blc, pt1, 0.0);
r = pt1;
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);测试文件
本帖最后由 zjsmlzp 于 2014-5-15 07:02 编辑
CAD2005可以加载试用能展高程点(不能自动建GCD图层),但需要名为“GC200”的图块支持(在CASS里找到再往CAD2005里插入一下),CAD2007里不能加载。 老大,如何根据图面三角网查询任意点坐标高程,怎么样将三维多段线生成点表的啊? 根据图面高程内插的不足之处,黄色点为错误的 路过学习!支持楼主! 看来简单的东西 还是lsp来的方便啊 萝卜各有所爱,趁不老,学多点不怕 请教:在vb中如实现已有块添加属性?
我参照帮助文档创建属性块的方法
1.定义块
2.给块定义属性
3.插入这个带属性的块
始终做不出cass这种格式(插入后是属性块且能在对象特征管理里能看到属性,但是双击却提示:不是属性块)
求解惑! 本帖最后由 wmz 于 2014-11-12 09:20 编辑
yuanziyou 发表于 2014-11-11 23:42 static/image/common/back.gif
请教:在vb中如实现已有块添加属性?
我参照帮助文档创建属性块的方法
1.定义块
这个已经有人用LISP解决了,我就是照此写了一个与南方CASS完全一样的展绘地形点的。而且运行速度超快,可与南方的PK!
wmz 发表于 2014-11-12 09:18 static/image/common/back.gif
这个已经有人用LISP解决了,我就是照此写了一个与南方CASS完全一样的展绘地形点的。而且运行速度超快 ...
lisp的方法我已经会了,用vb是因为希望和excel协作,且方便多文档处理
页:
[1]
2