天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 8|回复: 0

插入匿名块

[复制链接]
  • TA的每日心情
    开心
    昨天 15:23
  • 签到天数: 69 天

    [LV.6]常住居民II

    410

    主题

    167

    回帖

    2704

    积分

    管理员

    积分
    2704
    发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
    class BlockDrawCar
    {
    public:
            void DrawBlock(AcDbBlockTableRecord *btr)
            {
                    Acad::ErrorStatus es;

                    // Draw a rectangle polyline
                    AcDbPolyline *pline = new AcDbPolyline();
                    AcGePoint2d p0(0.0, 0.0), p1(m_Length, 0.0);
                    AcGePoint2d p2(m_Length, m_Width), p3(0.0, m_Width);
                    pline->addVertexAt(0, p0);
                    pline->addVertexAt(1, p1);
                    pline->addVertexAt(2, p2);
                    pline->addVertexAt(3, p3);
                    pline->setClosed(true);
                    pline->setDatabaseDefaults();
                    pline->setColorIndex(m_Color);
                    es = btr->appendAcDbEntity(pline);
                    if (!es)
                            pline->close();
                    else
                            delete pline;

                    // Draw a circle
                    AcDbCircle *circle = new AcDbCircle();
                    AcGePoint3d center(m_Width / 2, m_Width / 2, 0.0);
                    double radius = m_Width * 0.4;
                    circle->setCenter(center);
                    circle->setRadius(radius);
                    circle->setDatabaseDefaults();
                    circle->setColorIndex(m_Color);
                    es = btr->appendAcDbEntity(circle);
                    if (!es)
                            circle->close();
                    else
                            delete circle;
            }

    public:
            int m_Color=7;
            double m_Width=200;
            double m_Length=340;
    };


    AcDbObjectId CreateCarBlock(AcDbDatabase *db, LPCWSTR blockname)
    {
            Acad::ErrorStatus es;
            AcDbBlockTableRecord *btr = new AcDbBlockTableRecord;
            BlockDrawCar *car = new BlockDrawCar;
            car->DrawBlock(btr);
            btr->setName(blockname);

            // Add the BTR to the Blocktable of the current drawing
            AcDbObjectId BtrID;
            AcDbBlockTable *blocktable;
            es = db->getBlockTable(blocktable, AcDb::kForWrite);
            if (!es)
            {
                    es = blocktable->add(BtrID, btr);
                    if (!es)
                            btr->close();
                    else
                            delete btr;
                    blocktable->close();
            }

            return BtrID;
    }

    AcDbObjectId FindBlock(AcDbDatabase *db, LPCWSTR blockname)
    {
            AcDbObjectId BlockID;
            Acad::ErrorStatus es;
            AcDbBlockTable *blocktable;
            es = db->getBlockTable(blocktable, AcDb::kForRead);
            if (!es)
            {
                    es = blocktable->getAt(blockname, BlockID);
                    blocktable->close();
            }
            return BlockID;
    }

    Acad::ErrorStatus PostToDb(AcDbDatabase *db, AcDbObjectId& objId, AcDbEntity* pEnt)
    {
            Acad::ErrorStatus      es;
            AcDbBlockTable*        blocktable = 0;
            AcDbBlockTableRecord*  modelspace = 0;

            if ((es = db->getBlockTable(blocktable, AcDb::kForRead)) != Acad::eOk)
                    return es;

            if ((es = blocktable->getAt(ACDB_MODEL_SPACE, modelspace, AcDb::kForWrite)) == Acad::eOk)
            {
                    es = modelspace->appendAcDbEntity(objId, pEnt);
                    modelspace->close();
            }
            blocktable->close();

            return es;
    }

    void cmdDrawCar()
    {
            Acad::ErrorStatus es;
            LPCWSTR blockname = L"*U"; // Blockname. This is for an unnamed block.
            blockname = L"car"; // And this for a named block

            AcDbDatabase *db = acdbHostApplicationServices()->workingDatabase();
            AcDbObjectId BtrID;
            if (blockname[0]!=L'*') // '*' as first char means: Unnamed block. Don't search for it.
                    BtrID = FindBlock(db, blockname); // Search for an existing named block

            if (BtrID.isNull())
                    BtrID = CreateCarBlock(db, blockname); // For "*U" AutoCAD will create unique names like "*U1", "*U2", ...

            if (BtrID.isNull())
            {
                    acutPrintf(L"\nFailed.");
                    return;
            }

            // Now create a block reference
            AcDbBlockReference *bref = new AcDbBlockReference;
            bref->setDatabaseDefaults();
            bref->setBlockTableRecord(BtrID);

            AcGeVector3d insertionPoint;
            acedGetPoint(nullptr, L"\nInsertion point: ", asDblArray(insertionPoint));
            AcGeMatrix3d trans; // the transformation matrix
            trans.setToTranslation(insertionPoint);
            bref->setBlockTransform(trans);

            // Append it to modelspace
            AcDbObjectId BrefID;
            es = PostToDb(db, BrefID, bref);
            if (!es)
                    bref->close();
            else
                    delete bref;
    }

     

     

     

     

    插入匿名块
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|

    GMT+8, 2024-7-1 05:34 , Processed in 0.059557 second(s), 22 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表