[求助]如何获取用insert插入的属性块的各属性值(块名已知)
如何获取用insert插入的属性块的各属性值(块名已知) <P>这是一本书中的例子,每一行代码的例子我还不太懂,你自己看看吧.其中包括插入块的代码.</P><P>void insrtBlk()<BR>{<BR> char blkName;<BR> AcDbDatabase *pCurDb;<BR> AcDbBlockTable *pBlkTable;<BR> AcDbBlockTableRecord *pBlkTableRecord;<BR> AcDbBlockTableRecord *pBlkDefRecord;<BR> AcDbBlockReference *pInsrtObj;<BR> AcDbEntity *pEnt;<BR> AcDbBlockTableRecordIterator *pIterator;<BR> AcDbAttributeDefinition *pAttDef;<BR> AcDbAttribute *pAtt;<BR> AcDbObjectId blkId;<BR> AcDbObjectId insrtId;</P>
<P> char *pTagPrompt;</P>
<P> AcGePoint3d insPt;<BR> AcGePoint3d basePt;</P>
<P> int retCode;</P>
<P> retCode = acedGetString(0, "\nEnter Block Name: ", blkName);<BR> if(retCode != RTNORM || blkName == '\0')<BR> {<BR> acutPrintf("\nInvalid block name.");<BR> return;<BR> }</P>
<P> pCurDb = acdbHostApplicationServices()->workingDatabase();</P>
<P> // Check to see if the block table<BR> // has blkName</P>
<P> pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);<BR> if(!pBlkTable->has(blkName))<BR> {<BR> acutPrintf("\nBlock definition %s not found. ", blkName);<BR> pBlkTable->close();<BR> return;<BR> }</P>
<P> // Get the AcDbObjectId of the block<BR> // definition.<BR> pBlkTable->getAt(blkName, blkId);</P>
<P> pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRecord, AcDb::kForWrite);<BR> pBlkTable->close();<BR> <BR> acedInitGet(RSG_NONULL, NULL);<BR> acedGetPoint(NULL, "\nPick insertion point: ", asDblArray(insPt));</P>
<P> pInsrtObj = new AcDbBlockReference(insPt, blkId);</P>
<P> // Here is where you can set scale, rotation and other<BR> // properties to the block entity. If you want to<BR> // see the AcDbBlockReference class for more details.<BR> pBlkTableRecord->appendAcDbEntity(insrtId, pInsrtObj);</P>
<P><BR> acdbOpenObject(pBlkDefRecord, blkId, AcDb::kForRead);<BR> // Now check to see if the Block Definition<BR> // has attributes. If it does we will add<BR> // a Block Table Record Iterator to step through<BR> // the entities and find the Attribute Definitions.</P>
<P> if(pBlkDefRecord->hasAttributeDefinitions())<BR> {<BR> pBlkDefRecord->newIterator(pIterator);</P>
<P> for(pIterator->start(); !pIterator->done(); pIterator->step())<BR> {<BR> pIterator->getEntity(pEnt, AcDb::kForRead);<BR> // Check to see if the entity is an<BR> // attribute definition.<BR> pAttDef = AcDbAttributeDefinition::cast(pEnt);<BR> if(pAttDef != NULL && !pAttDef->isConstant())<BR> {<BR> // If it is and its not constant<BR> // create a new attribute<BR> pAtt = new AcDbAttribute();<BR> // setPropertiesFrom will copy<BR> // Color, Layer, Linetype,Linetype scale and<BR> // Visibility.<BR> pAtt->setPropertiesFrom(pAttDef);<BR> // setup more properties from the attribute<BR> // definition<BR> pAtt->setInvisible(pAttDef->isInvisible());<BR> basePt = pAttDef->position();<BR> basePt += pInsrtObj->position().asVector();<BR> pAtt->setPosition(basePt);<BR> pAtt->setHeight(pAttDef->height());<BR> pAtt->setRotation(pAttDef->rotation());</P>
<P> // Take note how we get the tag.<BR> pTagPrompt = pAttDef->tag();<BR> pAtt->setTag(pTagPrompt);<BR> free(pTagPrompt);</P>
<P> // Normally you would prompt the user<BR> // and ask for input values.<BR> pTagPrompt = pAttDef->prompt();<BR> acutPrintf("%s%s", "\n", pTagPrompt);<BR> free(pTagPrompt);<BR> <BR> // The setFieldLength is not required<BR> // even though it is listed in the<BR> // documentation.<BR> pAtt->setFieldLength(25);<BR> // setTextString is the value the<BR> // attribute receives which would<BR> // normally be a user input value.<BR> pAtt->setTextString("This is a test");</P>
<P> pInsrtObj->appendAttribute(pAtt);<BR> pAtt->close();<BR> }<BR> pEnt->close();<BR> }// for<BR> delete pIterator;</P>
<P>}// if has attribute definitions</P>
<P> // Note that we close the Model Space<BR> // block table record after we have added<BR> // our attributes.<BR> pBlkTableRecord->close();<BR> pInsrtObj->close();<BR>}</P>
页:
[1]