![]() |
【转帖】acdbface面域问题??????
acdbface面域问题??????
acdbface面域问题?????? 我问过这个问题了,但是还不明白。请版主帮忙解释一下: 一下是我的做法,不知道为什么求不出面积。 acgepoint3d pa(0,0,0),pb(100,0,0),pc(100,100,0),pd(0,100,0); acdbface *pface=new acdbface(pa,pb,pc,pd); posttodatabase(pface,faceid); ads_point pt1,pt2,pt; acgepoint2darray point_array; int stat=1; stat=acedgetpoint(null,"选择点(esc结束)\n",pt1); if(stat==rtcan) return; point_array.append(aspnt2d(pt1)); while(1) { acdbpointset(pt1, pt2); stat=acedgetpoint(pt1,"选择点,(esc结束)\n",pt1); acedgrdraw(pt2, pt1, 1, 0); if(stat==rtcan) break; point_array.append(aspnt2d(pt1)); } acdbpolyline *closepolyline=new acdbpolyline(); for(int i=0;i<point_array.length();i++) { acgepoint2d ptmp=point_array.at(i); closepolyline->addvertexat(i,ptmp,0,-1,-1); } closepolyline->setcolorindex(1); closepolyline->setclosed(adesk::ktrue); posttodatabase(closepolyline,idobj); acdbopenacdbentity(pent,idobj,acdb::kforread); acdbpolyline *ppoly=acdbpolyline::cast(pent); acdbvoidptrarray entities,regions; entities.append(pface); entities.append(ppoly); acdbregion::createfromcurves(entities, regions); if (regions.length() < 1) { acutprintf("构造闭合区域错误\n"); } assert(pregion != null); acdbregion *pregion = new acdbregion; for ( i = 0; i < regions.length(); i++) { if(acad::eok!=preg->booleanoper(acdb::kboolintersect,(acdbregion*) regions[i])) acutprintf("有问题\n"); delete (acrxobject*)regions[i]; } double regarea; preg->getarea(regarea); preg->close(); acutprintf("area=%0.3f\n",regarea); 请高手指出错误。 回复 能贴出你完整的代码吗? 没做过,只能帮你调试一下了. change your life style. 上面基本的程序放到一个函数里面即可。 告诉我做法了,但是我没有求出结果。 基本思想。就是两个实体(闭合的)然后求出图形交集部分的面积 回复 这里 = acedgetpoint(pick, "选择下一点(esc-quit): ", pick); stat=acedgetpoint(pt1,"选择点,(esc结束)\n",pt1); 是什么? file:这一行需要吗? posttodatabase也是未声明的? 很多未声明的标识符! change your life style. 那是注释掉得语句。粘贴到帖子上就加了file。不要。 posttodatabase()是把该实体添加到图形数据库中 回复 没法调试, 这段代码中很多变量都是没有声明的. posttodatabase idobj pent pregion preg ... 因为我没做过,所以看不出应该怎么改. posttodatabase是个自定义的函数 acad::errorstatus posttodatabase(acdbentity* ent, acdbobjectid& objid) { // given an entity, this function will post it to the database // in model_space and then return the objectid; returns eok if // all went well. acad::errorstatus es; acdbblocktable* pblocktable; acdbblocktablerecord* pspacerecord; es = acdbhostapplicationservices()->workingdatabase() ->getsymboltable(pblocktable, acdb::kforread); assert(es == acad::eok); es = pblocktable->getat(acdb_model_space, pspacerecord, acdb::kforwrite); assert(es == acad::eok); es = pblocktable->close(); assert(es == acad::eok); es = pspacerecord->appendacdbentity(objid, ent); assert(es == acad::eok); es = ent->close(); assert(es == acad::eok); es = pspacerecord->close(); assert(es == acad::eok); return es; } change your life style. 不好意思。我再发一次 void appmytoolcloreg() { ads_point pt1,pt2,pt; acgepoint2darray point_array; acdbobjectid idobj,faceid; acdbentity *pent=null; acgepoint3d pa(0,0,0),pb(100,0,0),pc(100,100,0),pd(0,100,0); acdbface *pface=new acdbface(pa,pb,pc,pd); posttodatabase(pface,faceid); int stat=1; stat=acedgetpoint(null,"选择点(esc结束)\n",pt1); if(stat==rtcan) return; point_array.append(aspnt2d(pt1)); while(1) { acdbpointset(pt1, pt2); stat=acedgetpoint(pt1,"选择点,(esc结束)\n",pt1); acedgrdraw(pt2, pt1, 1, 0); if(stat==rtcan) break; point_array.append(aspnt2d(pt1)); } acdbpolyline *closepolyline=new acdbpolyline(); for(int i=0;i<point_array.length();i++) { acgepoint2d ptmp=point_array.at(i); closepolyline->addvertexat(i,ptmp,0,-1,-1); } closepolyline->setcolorindex(1); closepolyline->setclosed(adesk::ktrue); posttodatabase(closepolyline,idobj);//添加实体数据库中 acdbopenacdbentity(pent,idobj,acdb::kforread); acdbpolyline *ppoly=acdbpolyline::cast(pent); acdbvoidptrarray entities,regions; entities.append(pface); entities.append(ppoly); acdbregion::createfromcurves(entities, regions); if (regions.length() < 1) { acutprintf("构造闭合区域错误\n"); } assert(pregion != null); acdbregion *pregion = new acdbregion; for ( i = 0; i < regions.length(); i++) { if(acad::eok!=pregion->booleanoper(acdb::kboolintersect,(acdbregion*)regions[i])) acutprintf("有问题\n"); delete (acrxobject*)regions[i]; } double regarea; pregion->getarea(regarea); pregion->close(); pent->close(); acutprintf("area=%0.3f\n",regarea); } acad::errorstatus posttodatabase(/*[in]*/acdbentity* pent,/*[out]*/acdbobjectid& idobj) { acad::errorstatus es; acdbblocktable* pblocktable; acdbblocktablerecord* pspacerecord; if (acdbhostapplicationservices()->workingdatabase()==null) return acad::enodatabase; if ((es = acdbhostapplicationservices()->workingdatabase()->getblocktable(pblocktable, acdb::kforread))==acad::eok){ if ((es = pblocktable->getat(acdb_model_space, pspacerecord, acdb::kforwrite))==acad::eok){ if ((es = pspacerecord->appendacdbentity(idobj, pent))==acad::eok) pent->close(); pspacerecord->close(); } pblocktable->close(); } return es; } 先求交点,再创建一个新的面或多线段,面积就出来了 |
所有的时间均为北京时间。 现在的时间是 06:15 PM. |