- UID
- 5537
- 积分
- 371
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-23
- 最后登录
- 1970-1-1
|
发表于 2002-10-20 00:39:49
|
显示全部楼层
一个区域填充的函数,希望能对你有点帮助
- [FONT=courier new]
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- //| 函数名: 区域填充
- //| FillInRegion()
- //|
- //| 输入参数: int No 区域点的个数
- //| ads_point pt[] 区域各点的坐标
- //| int color 颜色
- //| double Scale 比率
- //| char *lpszPatternName 样式
- //| char *strLayerName 层名
- //| struct resbuf *xData 附加扩展数据
- //|
- //| 返回: AcDbObjectId
- //| 说明: 指定层及区域的各点坐标,在区域中按指定样式和颜色填充
- //| 举例: 略
- //|
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- AcDbObjectId FillInRegion(int No, ads_point pt[],int color,double Scale,char *lpszPatternName,
- char *strLayerName,struct resbuf *xData)
- {
- AcGePoint2d temp;
- AcDbObjectId FillId;
- AcGePoint2dArray External;
- for (int j = 0; j < No; j++) {
- temp.set(pt[j][0],pt[j][1]);
- External.append(temp);
- } //填加区域点
- AcDbHatch * pHatch = new AcDbHatch;//创建图案填充对象
- AcDbBlockTable *pBlockTable;
- if (acdbHostApplicationServices()->workingDatabase()->
- getBlockTable(pBlockTable,AcDb::kForRead) != Acad::eOk) {
- ads_printf("\n错误:无法获取块表!\n");
- pHatch->close();
- return 0;
- }
- AcDbBlockTableRecord *pBlockTableRecord;
- if (pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
- AcDb::kForWrite) != Acad::eOk) {
- ads_printf("\n错误:无法获取符号表!\n");
- pBlockTable->close();
- return 0;
- }
- pBlockTable->close();
- AcGeVector3d normal(0.0,0.0,1.0);
- pHatch -> setNormal(normal); //设置法线适量
- pHatch -> setElevation(0.5); //设置绘图标高
- pHatch -> setAssociative(Adesk::kTrue);
- pHatch -> setPatternScale(Scale); //设置缩放比例
- pHatch -> setPattern(AcDbHatch::kPreDefined,lpszPatternName); //设置填充图案
- pHatch -> setHatchStyle(AcDbHatch::kNormal); //设置填充样式
- pHatch -> setColorIndex(color); //设置剖面线颜色
- pHatch -> setLayer(strLayerName); //设置所在图图层
- AcGeDoubleArray vertexBulges;
- vertexBulges.setPhysicalLength(0).setLogicalLength(No);
- for (int i = 0 ;i < No ;i++) vertexBulges[i] = 0.0; //清零
- //边界生成:外边界
- if (pHatch->appendLoop(AcDbHatch::kExternal, External, vertexBulges) != Acad::eOk) {
- ads_printf("\n错误:无法形成填充外边界!\n");
- pBlockTableRecord->close();
- pHatch->close();
- return 0;
- }
-
- if (pHatch -> evaluateHatch() != Acad::eOk) { //用设定的剖面线样式填充
- ads_printf("\n错误:无法用设定的剖面线样式填充!\n");
- pBlockTableRecord->close();
- pHatch->close();
- return 0;
- }
- if (pBlockTableRecord->appendAcDbEntity(FillId, pHatch) != Acad::eOk) {
- ads_printf("\n错误:无法将填充实体填加至数据库中!\n");
- pBlockTableRecord->close();
- pHatch->close();
- return 0;
- }
- pBlockTableRecord->close();
- //===========加扩展数据===========
- pHatch->upgradeOpen();
- if (pHatch->setXData(xData) != Acad::eOk){
- ads_printf("\n警告: 实体(填充对象 ID=%d)添加扩展数据时出错!\n",FillId);
- }
- //================================
- pHatch->close();
- return FillId;
- }
- [/font]
复制代码 |
|