Property Alteration Sample

AutoCAD Map 3D ObjectARX

 
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 Query
AcMapQuery *pCurrentQuery = NULL;
if (pProj->CreateQuery(
pCurrentQuery,
Adesk::kTrue
) == AcMap::kOk)
{
// Before we start, clear the current query
pCurrentQuery->Clear(Adesk::kTrue);
// clean up
delete pCurrentQuery;
}
}
}
// make the calls
DefineRangeLines()
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 library
AcMapRangeLibrary *pRangeLib = NULL;
if (pProj->GetRangeLibrary(pRangeLib) == Adesk::kTrue)
{
// Add a range table to the library
AcMapRangeTable *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 up
if (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 up
if (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 Query
AcMapQuery *pCurrentQuery = NULL;
if (pProj->CreateQuery(
pCurrentQuery,
Adesk::kTrue
) == AcMap::kOk)
{
// Get the Property alteration object from the query
AcMapPropertyAlterationDefinition *pPADef = NULL;
if (pCurrentQuery->GetPropertyAlteration(
pPADef
) == AcMap::kOk)
{
AcMapPropertyAlteration *pPropAltObj = NULL;
            
// Add a Text Alteration
if (pPADef->AddAlteration(
pPropAltObj,
AcMap::kAlterationTextEntity
) == AcMap::kOk)
{
// First we need to cast it
AcMapTextAlteration *pTextAlt = NULL;
pTextAlt = (AcMapTextAlteration*)pPropAltObj;
            
// set some attributes
pTextAlt->SetColor("Magenta");
pTextAlt->SetJustification("MIDDLE");
pTextAlt->SetRotation("45.0");
pTextAlt->SetHeight("0.5");
pTextAlt->SetExpression(
"(Range .TYPE MyTypeRangeTable)"
);
}
            
// clean up
if (pPropAltObj)
{
delete pPropAltObj;
pPropAltObj = NULL;
}
}
            
// enable property alterations for the query
pCurrentQuery->EnablePropertyAlteration(Adesk::kTrue);
            
// Create a query branch Entity Type = ALL
AcMapQueryBranch qBranch;
AcMapPropertyCondition propCond;
            
propCond.SetPropertyType(AcMap::kEntType);
propCond.SetConditionOperator(AcMap::kCondEq);
propCond.SetValue("*") ;
            
qBranch.AppendOperand(&propCond);
            
// define the query branch
pCurrentQuery->Define(&qBranch);
            
// set the query mode to draw
pCurrentQuery->SetMode(AcMap::kQueryDraw);
            
// run the query
pCurrentQuery->Run();
            
// clean up
delete 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 Query
AcMapQuery *pCurrentQuery = NULL;
if (pProj->CreateQuery(
pCurrentQuery,
Adesk::kTrue
) == AcMap::kOk)
{
// Get the Property alteration object from the query
AcMapPropertyAlterationDefinition *pPADef = NULL;
if (pCurrentQuery->GetPropertyAlteration(
pPADef
) == AcMap::kOk)
{
AcMapPropertyAlteration *pPropAltObj = NULL;
            
// Now add a Hatch Alteration
if (pPADef->AddAlteration(
pPropAltObj,
AcMap::kAlterationHatch
) == AcMap::kOk)
{
// First we need to cast it
AcMapHatchAlteration *pHatchAlt = NULL;
pHatchAlt = (AcMapHatchAlteration*)pPropAltObj;
            
// set some attributes
pHatchAlt->SetScale("2.0");
pHatchAlt->SetColor("Yellow");
pHatchAlt->SetRotation("45.0");
pHatchAlt->SetExpression(
"(Range .TYPE MyHatchRangeTable)"
);
}
            
// clean up
if (pPropAltObj)
{
delete pPropAltObj;
pPropAltObj = NULL;
}
}
// enable property alterations for the query
pCurrentQuery->EnablePropertyAlteration(Adesk::kTrue);
            
// Create a query branch Entity Type = ALL
AcMapQueryBranch qBranch;
AcMapPropertyCondition propCond;
            
propCond.SetPropertyType(AcMap::kEntType);
propCond.SetConditionOperator(AcMap::kCondEq);
propCond.SetValue("*") ;
            
qBranch.AppendOperand(&propCond);
            
// define the query branch
pCurrentQuery->Define(&qBranch);
            
// set the query mode to draw
pCurrentQuery->SetMode(AcMap::kQueryDraw);
            
// run the query
pCurrentQuery->Run();
            
// clean up
delete pCurrentQuery;
}
}
}
}
catch(...)
{
// do some error handling
}
}
// END