马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
) \& W( q" A4 c% B1 q
这是比较简单的部分了,可以参考现有书籍。在网上下载两个画线的函数: 直线: void LineCreate(AcGePoint3d ptStart,AcGePoint3d ptEnd)" A4 f5 o( S/ i; K. W) [ X3 L
{
/ D( U$ Z4 [) A, |* x, BAcDbLine * pLine = new AcDbLine( ptStart , ptEnd );) ~7 k! _) G; T9 X. @/ y' J5 }3 q$ S
// 获得指向块表的指针& N [. W( f4 y+ p' V W6 @
AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase()( r& M7 Z3 R; q, u# A0 M
->getBlockTable(pBlockTable, AcDb::kForRead);
; |( b+ D; ~+ M// 获得指向特定的块表记录(模型空间)的指针% Q& o! f! V$ w1 K2 t
AcDbBlockTableRecord *pBlockTableRecord;. ~/ Q9 P' j& g+ \: [: M3 d" Y
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);9 q/ w2 O) X9 |8 n0 @. Y1 Y8 C
// 将AcDbLine类的对象添加到块表记录中
( w/ A; ?+ T' z3 ~9 @' M; }AcDbObjectId lineId;7 c* T1 B9 x( h1 B% Y
pBlockTableRecord->appendAcDbEntity(lineId, pLine);1 Q3 q1 i. Z- [. |- r
// 关闭图形数据库的各种对象6 r9 \" A$ ]9 a: j# |: q& {
pBlockTable->close();
5 s7 y" G ?& ?; l- H# V7 Q+ IpBlockTableRecord->close();
& l5 r$ V! D2 S( e( ?( L( YpLine->close();& d1 i( d1 a. F9 L8 ~) | r# Q( _
}
9 `9 f! F8 K$ z, C6 o5 T# D多线段:7 D& Y" d, |8 {/ z8 f
void CreatePolyline(AcGePoint2dArray points ,double width)1 M, B, ~2 `# w4 B$ n ^% n% e
{
( f, K( D% |2 S1 Z, W) {9 sint numVertices = points.length();* C! O1 @' n" j$ D+ }, d& K
AcDbPolyline *pPoly = new AcDbPolyline(numVertices);! g; g' b* r# h$ m
for (int i = 0; i < numVertices; i++)
9 q3 Z6 H: \7 w" ^6 @# \{
: y) k$ k7 d, p! A" v0 hpPoly->addVertexAt(i, points.at(i), 0, width, width);; p0 p2 x3 o! U/ ^% \4 t0 p4 t
}* Q( w9 s/ D/ o) @8 H! Y
AcDbObjectId polyId;( s: J: z( N; ^* {
polyId = PostToModelSpace(pPoly);
. ^6 D- \3 |, T. r7 @4 c// return polyId;/ {7 v- A/ k" D' a6 [) \
}
- A# j; Z$ Y& l. u0 Dstatic AcDbObjectId PostToModelSpace(AcDbEntity* pEnt) Z9 ^% g" t4 r% q
{1 _/ s1 c2 u5 G2 }
AcDbBlockTable *pBlockTable;6 y ?4 Z7 k& l. U! _8 X) v
acdbHostApplicationServices()->workingDatabase() ->getBlockTable(pBlockTable, AcDb::kForRead);. V5 P5 o- ^% l$ K
AcDbBlockTableRecord *pBlockTableRecord;
5 l6 a' F1 k* MpBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
$ N1 C9 C2 H( NAcDbObjectId entId;5 l! r% q8 [' ]& z
pBlockTableRecord->appendAcDbEntity(entId, pEnt);
1 s) x% J% }2 h) V: `9 N1 epBlockTable->close();6 T$ {9 ?5 ]6 d' p7 x% l! a3 V* b
pBlockTableRecord->close();7 V: N0 w- E$ b, P/ e
pEnt->close();! ^0 {2 H8 v3 {* g
return entId; } ' \ _2 d L5 [) I
需要注意的是:创建线段与显示线段需要不同的代码。 参考:http://www.colinchou.com/archives/242
H/ S1 `, m* _" D( }2 }6 T2 w) p( I7 y$ w6 X+ ~8 ]
* r+ _3 `$ X7 f: A
% d/ U* K6 [ o) E" b
$ a0 A$ u6 n1 u% w! F' \2 H, z( ~' u
. q! J- b$ k2 h' b
http://www.3dportal.cn/discuz/source/plugin/sina_xweibo_x3/xwb/images/bgimg/icon_logo.png 该贴已经同步到 colinzhoucn的微博 |