lhb.nj 发表于 2002-8-15 02:11:00

如何直接生成"LWPOLYLINE"?[求助]

如何直接生成"LWPOLYLINE"?

zhangsan 发表于 2002-8-15 08:47:00

From ARX help

void
createPolyline()
{
    // Set four vertex locations for the pline.
    //
    AcGePoint3dArray ptArr;
    ptArr.setLogicalLength(4);
    for (int i = 0; i < 4; i++) {
      ptArr.set((double)(i/2), (double)(i%2), 0.0);
    }

    // Dynamically allocate an AcDb2dPolyline object,
    // given four vertex elements whose locations are supplied
    // in ptArr.The polyline has no elevation, and is
    // explicitly set as closed.The polyline is simple;
    // that is, not curve fit or a spline.By default, the
    // widths are all 0.0 and there are no bulge factors.
    //
    AcDb2dPolyline *pNewPline = new AcDb2dPolyline(
      AcDb::k2dSimplePoly, ptArr, 0.0, Adesk::kTrue);
    pNewPline->setColorIndex(3);

    // Get a pointer to a Block Table object.
    //
    AcDbBlockTable *pBlockTable;
    acdbHostApplicationServices()->workingDatabase()
      ->getSymbolTable(pBlockTable, AcDb::kForRead);

    // Get a pointer to the MODEL_SPACE BlockTableRecord.
    //
    AcDbBlockTableRecord *pBlockTableRecord;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
      AcDb::kForWrite);
    pBlockTable->close();

    // Append the pline object to the database and
    // obtain its object ID.
    //
    AcDbObjectId plineObjId;
    pBlockTableRecord->appendAcDbEntity(plineObjId,
      pNewPline);
    pBlockTableRecord->close();

    // Make the pline object reside on layer "0".
    //
    pNewPline->setLayer("0");
    pNewPline->close();
}

lhb.nj 发表于 2002-8-15 15:43:00

createPolyline()生成的是 "POLYLINE"而非"LWPOLYLINE"

createPolyline()生成的是 "POLYLINE"而非"LWPOLYLINE"
其DXF组码是:
(-1.<Entity name: >)
(   0.<string: POLYLINE>)
(   5.<string: 2B>)
( 100.<string: AcDbEntity>)
(67.<short: 0>)
(   8.<string: 0>)
(62.<short: 3>)
( 100.<string: AcDb2dPolyline>)
(66.<short: 1>)
(10.<3dpoint:   0.0000,    0.0000,    0.0000>)
(70.<short: 1>)
(40.<real:    0.000000000000000>)
(41.<real:    0.000000000000000>)
( 210.<3dpoint:   0.0000,    0.0000,    1.0000>)
(71.<short: 0>)
(72.<short: 0>)
(73.<short: 0>)
(74.<short: 0>)
(75.<short: 0>)
而不是:
(-1.<Entity name: >)
(   0.<string: LWPOLYLINE>)
(   5.<string: 38>)
( 100.<string: AcDbEntity>)
(67.<short: 0>)
(   8.<string: 0>)
( 100.<string: AcDbPolyline>)
(90.<long: 4>)
(70.<short: 1>)
(43.<real:    0.000000000000000>)
(38.<real:    0.000000000000000>)
(39.<real:    0.000000000000000>)
(10.<3dpoint:    -0.5210,   -0.0031,    0.0000>)
(40.<real:    0.000000000000000>)
(41.<real:    0.000000000000000>)
(42.<real:    0.000000000000000>)
(10.<3dpoint:    -0.5210,    0.9969,    0.0000>)
(40.<real:    0.000000000000000>)
(41.<real:    0.000000000000000>)
(42.<real:    0.000000000000000>)
(10.<3dpoint:   0.4790,   -0.0031,    0.0000>)
(40.<real:    0.000000000000000>)
(41.<real:    0.000000000000000>)
(42.<real:    0.000000000000000>)
(10.<3dpoint:   0.4790,    0.9969,    0.0000>)
(40.<real:    0.000000000000000>)
(41.<real:    0.000000000000000>)
(42.<real:    0.000000000000000>)
( 210.<3dpoint:   0.0000,    0.0000,    1.0000>)

zhangsan 发表于 2002-8-16 08:39:00

系统变量PLINETYPE=1?2?

它影响pline的输出,大概也影响。。。

lhb.nj 发表于 2002-8-17 23:15:00

系统变量PLINETYPE=1,2只影响PLINE命令,而不能影响直接生成实体!

系统变量PLINETYPE=1,2只影响PLINE命令,而不能影响直接生成实体!
而命令CONVERT可以转换2DPOLYLINE为LWPOLYLINE!不知它是如何做的?

hothua 发表于 2002-8-18 11:19:00

回复

首先我要说明的是LWPOLYLINE是Lisp语言的DXF慨念,在ARX中就是AcDbPolyline,而LISP中的POLYLINE是3D线,好久没写这些东西了,有的地方我也忘了。县列出ARX程序和LISP程序如下:
//ptArray,坐标点集
bool makePolyline(AcGePoint3dArray &ptArray)
{
        unsigned int ptNum;
        ptNum=ptArray.length();
        if(ptNum>2)
        {       
        AcDbPolyline *newEnt;
        newEnt=new AcDbPolyline(ptNum);
        for(unsigned int num=0;num<ptNum;++num)
        {
                AcGePoint2d pt;
                pt=ptArray;
                pt=ptArray;
                if(newEnt->addVertexAt(num,pt,0.0)!=Acad::eOk)
                {
                        newEnt->close();
                        return false;
                }
        }
      if(appendToPaperOrModelSpace((AcDbEntity *)newEnt,0)!= Acad::eOk)
        {
                newEnt->close();
                return false;
        }       
        newEnt->close();
        return true;
}

Acad::ErrorStatus appendToPaperOrModelSpace (AcDbEntity* parEntity, Adesk::Boolean parbToPaperSpace)
{
       
        Acad::ErrorStatus        ErrorStatus;
        AcDbDatabase*                        pDataBase;
        AcDbBlockTable*                        pBlockTable;
        AcDbBlockTableRecord*        pBlockTableRecord;

       
    pDataBase        = acdbCurDwg();
       
        if (pDataBase == NULL)                
                        return Acad::eNoDatabase;
        ErrorStatus = pDataBase->getBlockTable(pBlockTable, AcDb::kForRead);       
        if (ErrorStatus != Acad::eOk)        
                        return ErrorStatus;
        if (parbToPaperSpace)       
                ErrorStatus = pBlockTable->getAt(ACDB_PAPER_SPACE, pBlockTableRecord, AcDb::kForWrite);
        else       
                ErrorStatus = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);               
        if (ErrorStatus != Acad::eOk)
        {
                pBlockTable->close();
                return ErrorStatus;
        }       
        ErrorStatus = pBlockTableRecord->appendAcDbEntity (parEntity);
    pBlockTableRecord->close();
    pBlockTable->close();
        return ErrorStatus;
}       
;LISP 具体参数就不用我说了吧
(defun make_pl(points layer ltype color wid code / n flag m_elist ele xy_l kk xy)
(setq n (length points))
(if (>= n 2)
    (if (equal (nth 0 points) (nth (1- n) points) 0.001)
      (setq flag '(70 . 1) n (1- n) kk 1)
      (setq flag '(70 . 0) kk 0)
    )
)
(if (not layer)
    (setq layer (getvar "clayer"))
)
(if (not wid)
    (setq wid (getvar "plinewid"))
)
(if (not code)
    (setq code (getvar "thickness"))
)
(if (>= n 2)
    (progn
      (entmake)
      (if (nth 2 (car points))
      (setq ele (nth 2 (car points)))
      (setq ele 0)
      )
      (setq m_elist (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") (cons 8 layer)))
      (if (and color (/= color "BYLAYER") (/= color 256))
      (setq m_elist (append m_elist (list (cons 62 color))))
      )
      (if (and ltype (/= ltype "BYLAYER"))
      (setq m_elist (append m_elist (list (cons 6 ltype))))
      )
      (setq m_elist (append m_elist (list '(100 . "AcDbPolyline")) (list (cons 90 n))
                            (list flag) (list (cons 38 ele))
                  )
            xy_l '()      
      )
      (setq m_elist (append m_elist (list (cons 39 code))))
      (repeat n
      (setq xy (nth kk points)
            xy (list (car xy) (cadr xy))
            xy_l (append xy_l (list (list 10 (car xy) (cadr xy)) (cons 40 wid) (cons 41 wid) '(42 . 0.0)))
            kk (1+ kk)
      )
      )
      (setq m_elist (append m_elist xy_l (list '(210 0.0 0.0 1.0))))   
      (entmake m_elist)
    )
)
)
页: [1]
查看完整版本: 如何直接生成"LWPOLYLINE"?[求助]