admin 发表于 2024-3-14 19:38:45

[每日一码] 如何通过程序创建一个多线样式(AcDbMlineStyle)

// minimal error checking for code brevity
void createMlineStyle()
{
    AcDbLinetypeTable* pTable = NULL;
AcDbObjectId id;   
AcDbDatabase* pDb = curDoc()->database();
// open ByLayer linetypetablerecord for use in MLineStyle later
pDb->getLinetypeTable(pTable, AcDb::kForRead);
if((pTable->getAt(L"ByLayer", id)) != Acad::eOk)
{
    acutPrintf(L"\nlinetype ByLayer not found.");   
    return;   
}
pTable->close();

    AcDbDictionary* pDict = NULL;
// open MLStyleDictionary (its sored in the NOD)
Acad::ErrorStatus es = pDb->getMLStyleDictionary(pDict, AcDb::kForRead);
if(es != Acad::eOk)   
{   
acutPrintf(L"\nCan't open mline style dictionary for read.");
return;   
}
const ACHAR mlineStyleName[] = L"test";
AcDbMlineStyle* ps = NULL;
// does MLStyle "test" already exist?
es = pDict->getAt(mlineStyleName, (AcDbObject*&)ps, AcDb::kForWrite);
// If it doesn't exist, create it
if(es != Acad::eOk)
{      
ps = new AcDbMlineStyle;      
AcDbObjectId mId;
ps->initMlineStyle();
pDict->upgradeOpen();   
pDict->setAt(mlineStyleName, ps, mId);
}   
pDict->close();
    // set MLStyle attributes and elements   
es = ps->setName(mlineStyleName);
AcCmColor cm;   cm.setColorIndex(256);
    int a=0, b=0;   
es = ps->addElement(a, -0.25, cm, id);
assert(es == Acad::eOk);
es = ps->addElement(b, 0.25, cm, id);
    assert(es == Acad::eOk);
ps->close();
acutPrintf(L"\nMline style: %s created.", mlineStyleName);
}
页: [1]
查看完整版本: [每日一码] 如何通过程序创建一个多线样式(AcDbMlineStyle)