Property Alteration Sample
Property Alteration Sample
It also shows how to use them together with a query. It assumes there is a current project, a project drawing, and at least one active attached drawing with some drawing objects in it.
////////////////////////////////////////// MAIN LOOP//// Clears the current query and calls// DefineRangeLines(), TextAlt(), and// HatchAlt().//////////////////////////////////////////void doPropAlts(){AcMapSession *mapSession = NULL;mapSession = AcMapGetSession();if (mapSession){AcMapProject *pProj;if (mapSession->GetProject(pProj) == Adesk::kTrue){// Get the current QueryAcMapQuery *pCurrentQuery = NULL;if (pProj->CreateQuery(pCurrentQuery,Adesk::kTrue) == AcMap::kOk){// Before we start, clear the current querypCurrentQuery->Clear(Adesk::kTrue);// clean updelete pCurrentQuery;}}}// make the callsDefineRangeLines()TextAlt()HatchAlt()}////////////////////////////////////// DefineRangeLines()//// Creates two range tables and// adds them to the range library//////////////////////////////////////void DefineRangeLines(){AcMapSession *mapSession = NULL;try{mapSession = AcMapGetSession();if (mapSession){AcMapProject *pProj;if (mapSession->GetProject(pProj) == Adesk::kTrue){// Get the range libraryAcMapRangeLibrary *pRangeLib = NULL;if (pProj->GetRangeLibrary(pRangeLib) == Adesk::kTrue){// Add a range table to the libraryAcMapRangeTable *pTable = NULL;const char *pcName = "MyTypeRangeTable";const char *pcDsc = "Table for types";if (pRangeLib->AddRangeTable(pTable,pcName,pcDsc) = AcMap::kOk){// Add range lines that will add text next to// entites that match the input criteria.pTable->AddRangeLine(AcMap::kRangeEq,"circle","CIRCLE");pTable->AddRangeLine(AcMap::kRangeEq,"polygon","POLYGON");pTable->AddRangeLine(AcMap::kRangeEq,"polyline","PLINE");pTable->AddRangeLine(AcMap::kRangeEq,"line","LINE");pTable->AddRangeLine(AcMap::kRangeEq,"lwpolyline","LWPOLYLINE");pTable->AddRangeLine(AcMap::kRangeEq,"text","TEXT");pTable->AddRangeLine(AcMap::kRangeOtherwise,NULL,"Unknown Type");}// clean upif (NULL != pTable){delete pTable;pTable = NULL;}pcName = "MyHatchRangeTable";pcDsc = "Table for hatch ranges";if (pRangeLib->AddRangeTable(pTable,pcName,pcDsc) == AcMap::kOk){// Add range lines that will add hatch patterns// to entites that match the input criteria.pTable->AddRangeLine(AcMap::kRangeEq,"circle","ANSI31");pTable->AddRangeLine(AcMap::kRangeEq,"polygon","CROSS");pTable->AddRangeLine(AcMap::kRangeEq,"polyline","ANSI33");pTable->AddRangeLine(AcMap::kRangeEq,"lwpolyline","DASH");pTable->AddRangeLine(AcMap::kRangeOtherwise,NULL,"SOLID");}// clean upif (NULL != pTable){delete pTable;pTable = NULL;}}}}}catch(...){// do some error handling}}///////////////////////////////////////////////// TextAlt()//// Creates a Text Alteration and sets the// expression to the table, MyTypeRangeTable.// Defines and runs a query with property// alteration./////////////////////////////////////////////////void TextAlt(){AcMapSession *mapSession = NULL;try{mapSession = AcMapGetSession();if (mapSession){AcMapProject *pProj;if (mapSession->GetProject(pProj) == Adesk::kTrue){// Get the current QueryAcMapQuery *pCurrentQuery = NULL;if (pProj->CreateQuery(pCurrentQuery,Adesk::kTrue) == AcMap::kOk){// Get the Property alteration object from the queryAcMapPropertyAlterationDefinition *pPADef = NULL;if (pCurrentQuery->GetPropertyAlteration(pPADef) == AcMap::kOk){AcMapPropertyAlteration *pPropAltObj = NULL;// Add a Text Alterationif (pPADef->AddAlteration(pPropAltObj,AcMap::kAlterationTextEntity) == AcMap::kOk){// First we need to cast itAcMapTextAlteration *pTextAlt = NULL;pTextAlt = (AcMapTextAlteration*)pPropAltObj;// set some attributespTextAlt->SetColor("Magenta");pTextAlt->SetJustification("MIDDLE");pTextAlt->SetRotation("45.0");pTextAlt->SetHeight("0.5");pTextAlt->SetExpression("(Range .TYPE MyTypeRangeTable)");}// clean upif (pPropAltObj){delete pPropAltObj;pPropAltObj = NULL;}}// enable property alterations for the querypCurrentQuery->EnablePropertyAlteration(Adesk::kTrue);// Create a query branch Entity Type = ALLAcMapQueryBranch qBranch;AcMapPropertyCondition propCond;propCond.SetPropertyType(AcMap::kEntType);propCond.SetConditionOperator(AcMap::kCondEq);propCond.SetValue("*") ;qBranch.AppendOperand(&propCond);// define the query branchpCurrentQuery->Define(&qBranch);// set the query mode to drawpCurrentQuery->SetMode(AcMap::kQueryDraw);// run the querypCurrentQuery->Run();// clean updelete pCurrentQuery;}}}}catch(...){// do some error handling}}////////////////////////////////////////////////// HatchAlt()//// Creates a Hatch Alteration and sets the// expression to the table, MyHatchRangeTable.// Defines and runs a query with property// alteration.//////////////////////////////////////////////////void HatchAlt(){AcMapSession *mapSession = NULL;try{mapSession = AcMapGetSession();if (mapSession){AcMapProject *pProj;if (mapSession->GetProject(pProj) == Adesk::kTrue){// Get the current QueryAcMapQuery *pCurrentQuery = NULL;if (pProj->CreateQuery(pCurrentQuery,Adesk::kTrue) == AcMap::kOk){// Get the Property alteration object from the queryAcMapPropertyAlterationDefinition *pPADef = NULL;if (pCurrentQuery->GetPropertyAlteration(pPADef) == AcMap::kOk){AcMapPropertyAlteration *pPropAltObj = NULL;// Now add a Hatch Alterationif (pPADef->AddAlteration(pPropAltObj,AcMap::kAlterationHatch) == AcMap::kOk){// First we need to cast itAcMapHatchAlteration *pHatchAlt = NULL;pHatchAlt = (AcMapHatchAlteration*)pPropAltObj;// set some attributespHatchAlt->SetScale("2.0");pHatchAlt->SetColor("Yellow");pHatchAlt->SetRotation("45.0");pHatchAlt->SetExpression("(Range .TYPE MyHatchRangeTable)");}// clean upif (pPropAltObj){delete pPropAltObj;pPropAltObj = NULL;}}// enable property alterations for the querypCurrentQuery->EnablePropertyAlteration(Adesk::kTrue);// Create a query branch Entity Type = ALLAcMapQueryBranch qBranch;AcMapPropertyCondition propCond;propCond.SetPropertyType(AcMap::kEntType);propCond.SetConditionOperator(AcMap::kCondEq);propCond.SetValue("*") ;qBranch.AppendOperand(&propCond);// define the query branchpCurrentQuery->Define(&qBranch);// set the query mode to drawpCurrentQuery->SetMode(AcMap::kQueryDraw);// run the querypCurrentQuery->Run();// clean updelete pCurrentQuery;}}}}catch(...){// do some error handling}}// END