コード例 #1
0
ファイル: ZhfPalette.cpp プロジェクト: luosin/cad-2004-lzx
//0,不显示属性,1,显示属性,2,显示属性默认值
void CZhfPalette::FilterDb(AcDbDatabase* pDb, int iFilterMode)
{
	if (iFilterMode==1)
	{
		return ;
	}
	Acad::ErrorStatus es ;
	AcDbBlockTable* pBT = NULL ;
	pDb->getBlockTable(pBT, AcDb::kForRead);
	AcDbBlockTableRecord* pBTR = NULL;
	es = pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite);
	pBT->close();

	AcDbBlockTableRecordIterator* pIT;
	es = pBTR->newIterator(pIT) ;
	for (; !pIT->done(); pIT->step()) 
	{
		AcDbEntity* pEnt = NULL ;
		if (Acad::eOk==pIT->getEntity(pEnt, AcDb::kForWrite))
		{
			if (pEnt->isKindOf(AcDbAttributeDefinition::desc()))
			{
				AcDbAttributeDefinition *pAttDef = AcDbAttributeDefinition::cast(pEnt);

				if (iFilterMode==0)
				{
					pEnt->erase() ;
				}
				else if (iFilterMode>1)
				{
					if (pAttDef != NULL && !pAttDef->isConstant())
					{
						// We have a non-constant attribute definition,
						// so build an attribute entity.
						CString strShowVal ;

						if (iFilterMode==2)
						{
							strShowVal = pAttDef->textString() ;
						}
						else if (iFilterMode==3)
						{
							strShowVal = pAttDef->prompt() ; //显示中文为乱码
						}
						pAttDef->setTag(strShowVal) ;
					}
				}
			}
			pEnt->close() ;
		}
	}

	delete pIT;
	pBTR->close();
}
コード例 #2
0
ファイル: complex.cpp プロジェクト: kevinzhwl/ObjectARXMod
void
defineBlockWithAttributes(
    AcDbObjectId& blockId, // This is a returned value.
    const AcGePoint3d& basePoint,
    double textHeight,
    double textAngle)
{
    int retCode = 0;
    AcDbBlockTable *pBlockTable = NULL;
    AcDbBlockTableRecord* pBlockRecord
       = new AcDbBlockTableRecord;
    AcDbObjectId entityId;

    // Step 1: Set the block name and base point of the block definition
    //
    pBlockRecord->setName("ASDK-BLOCK-WITH-ATTR");
    pBlockRecord->setOrigin(basePoint);

    // Open the block table for write.
    //
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForWrite);

    // Step 2: Add the block table record to block table.
    //
    pBlockTable->add(blockId, pBlockRecord);

    // Step 3: Create a circle entity.
    //
    AcDbCircle *pCircle = new AcDbCircle;
    pCircle->setCenter(basePoint);
    pCircle->setRadius(textHeight * 4.0);
    pCircle->setColorIndex(3);

    // Append the circle entity to the block record.
    //
    pBlockRecord->appendAcDbEntity(entityId, pCircle);
    pCircle->close();

    // Step 4: Create an attribute definition entity.
    //
    AcDbAttributeDefinition *pAttdef
        = new AcDbAttributeDefinition;

    // Set the attribute definition values.
    //
    pAttdef->setPosition(basePoint);
    pAttdef->setHeight(textHeight);
    pAttdef->setRotation(textAngle);
    pAttdef->setHorizontalMode(AcDb::kTextLeft);
    pAttdef->setVerticalMode(AcDb::kTextBase);
    pAttdef->setPrompt("Prompt");
    pAttdef->setTextString("DEFAULT");
    pAttdef->setTag("Tag");
    pAttdef->setInvisible(Adesk::kFalse);
    pAttdef->setVerifiable(Adesk::kFalse);
    pAttdef->setPreset(Adesk::kFalse);
    pAttdef->setConstant(Adesk::kFalse);
    pAttdef->setFieldLength(25);

    // Append the attribute definition to the block.
    //
    pBlockRecord->appendAcDbEntity(entityId, pAttdef);

    // The second attribute definition is a little easier
    // because we are cloning the first one.
    //
    AcDbAttributeDefinition *pAttdef2
        = AcDbAttributeDefinition::cast(pAttdef->clone());

    // Set the values which are specific to the
    // second attribute definition.
    //
    AcGePoint3d tempPt(basePoint);
    tempPt.y -= pAttdef2->height();
    pAttdef2->setPosition(tempPt);
    pAttdef2->setColorIndex(1); // Red
    pAttdef2->setConstant(Adesk::kTrue);

    // Append the second attribute definition to the block.
    //
    pBlockRecord->appendAcDbEntity(entityId, pAttdef2);

    pAttdef->close();
    pAttdef2->close();
    pBlockRecord->close();
    pBlockTable->close();
    return;
}