Each
standard object, called a feature,
has a set of user-defined properties and data, called a feature class.
All feature class definitions are stored in a feature-definition file, or schema.
After setting up feature class definitions, you can use them to
create objects with a standard set of properties and data. You can change
property values, or the properties themselves, programmatically.
An organization that creates road maps, for example, might have
standard Primary Road and Secondary Road polyline objects in which
the Primary Road features are created with thick lineweight on the
Primary Roads layer, and Secondary Road features appear with thin
lineweight on the Secondary Roads layer. Each road feature has associated
object data, such as speed limit, number of lanes, and surface type.
See also
Creating and Managing Feature Class Definitions
Using Reactors with Feature Class Definition Events
Feature Classification Samples
Feature Classification Classes and Namespaces
Before you can Creating and Managing Feature Class Definitions, you must create a schema and attach it to the current drawing by using AcMapClassificationManager functions. However, before you create a new feature-definition file with CreateFeatureDefinitionFile(), use CanCurrentUserAlterSchema() to check whether the current user has sufficient privileges to create or change a schema. (Even though you don't check this first, CreateFeatureDefinitionFile() will catch an insufficient-privileges error.)
Alternatively, rather than creating a new schema, use the currently attached schema, indicated by GetFeatureDefinitionFileAttached(), or attach an existing schema with AttachFeatureDefinitionFile(). You can detach a schema explicitly with DetachCurrentFeatureDefinitionFile().
After creating or modifying a feature class definition in a schema, save the file withSaveCurrentFeatureDefinitionFile()or save a copy withSaveCurrentFeatureDefinitionFileAs(). You also can refresh the current schema withReloadCurrentFeatureDefinitionFile(), but doing so is risky because it might reload outdated data, depending on the user's actions.
For feature-classification source-code samples, seeFeature Classification Samples.
// Creates a new feature-definition file.
AcMapObjClass::EErrCode errCode;
const char* pszSchemaFileName = "mySchema.xml";
// Check whether current user can create or change schema.
if (CanCurrentUserAlterSchema())
{
// Create the schema file.
errCode = CreateFeatureDefinitionFile(pszSchemaFileName);
// Handle errors.
switch (errCode)
{
case AcMapObjClass::eNoUserPrivilegeToAlterSchema:
// Insufficient-privileges error.
break;
case AcMapObjClass::eFileAlreadyExists:
// Schema file already exists (and will be attached).
break;
case AcMapObjClass::eFileNameInvalid:
// Invalid file name.
break;
case AcMapObjClass::eFailed:
// Failed for some other reason.
break;
default:
break;
}
// Attach the schema file.
errCode = AttachFeatureDefinitionFile(pszSchemaFileName);
if (errCode == AcMapObjClass::eOk)
{
...
}
}
Creating and Managing Feature Class Definitions
After
you
It's prudent to run a few safety checks before you create a feature class definition. For example, you could do the following:
- Use GetFeatureClassDefinitionCount() to indicate whether any existing feature classes are defined in the current schema and use GetFeatureClassNames() to list their names.
- Use IsFeatureClassDefinitionPresent() to determine whether a specific class definition exists.
Create
a feature class definition by using CreateFeatureClassDefinition()
(twoforms).
Alternatively, you can use DuplicateFeatureClassDefinition()to copy
an existing feature class definition and then
After creating or modifying a feature class definition in a schema, save your changes withSaveCurrentFeatureDefinitionFile()orSaveCurrentFeatureDefinitionFileAs().
To rename or delete a feature class definition, useRenameFeatureClassDefinition()orDeleteFeatureClassDefinition().
For feature-classification source-code samples, seeFeature Classification Samples.
After
you
Use any of the following methods to check entities:
- To avoid redoing or overwriting previous classifications, check which entities already are classified and with which feature class definitions. GetClassifiedEntities() (two forms) lists all classified entities in the current drawing, and GetUnclassifiedEntities() lists the unclassified ones.
- Use GetUndefinedEntities() to list entities that are classified but whose feature class definitions are not in the attached feature-definition file.
- Use IsClassified() to determine whether a specific entity is classified.
Use any of the following methods to manage classified entities:
- To classify one or more entities, use Classify() (two forms).
- To inspect an entity's properties, use GetProperties() (two forms).
- To determine how an entity should be classified (or reclassified), use GetClassifiedProperties() (two forms).
- To fix out-of-range or missing values of classified properties, use Audit() (two forms).
- If an entity was classified multiple times by using different feature-definition files, use GetAllTags() to retrieve all the entity's feature class names and corresponding feature-definition files.
- To unclassify one or more entities, use Unclassify() (two forms) or ClearAllTags() (two forms).
For feature-classification source-code samples, seeFeature Classification Samples.
Managing Attributes of Feature Class Definitions
Use AcMapObjClassDefinition functions to manage the attributes of a feature class definition stored in the feature-definition file attached to the current drawing. You can retrieve and (in some cases) set the following attributes:
- Name - GetName()/SetName()
- Description -GetDescription()/SetDescription()
- Icon -GetIconName()/SetIconName()
- Visibility -IsVisibleInWorkspace()/SetVisibleInWorkspace()
- Feature definition file -GetFeatureDefinitionFile()
- Supported entity types - GetSupportedEntityTypes() (two forms)
// Print the name of this feature class definition and the
// pathname of the feature-definition file that it belongs to.
const char* pszFeatureClassDefinitionName = GetName();
const char* pszFeatureDefinitionFile = GetFeatureDefinitionFile();
acutPrintf("\nThe feature class definition name is %s", pszFeatureClassDefinitionName);
acutPrintf("\nThe feature-definition file pathname is %s", pszFeatureDefinitionFile);
Use the following functions to determine where a specific feature class exists in the feature-class hierarchy:GetDirectBaseClassName(),IsBaseClassOf(),IsBaseClassOnly(),IsDerivedClassOf(), and IsDirectBaseClassOf().
// Determine whether this feature class definition is a base class
// of the feature class "Parcels".
AcMapObjClass::EErrCode errCode;
bool bBaseClassOf; // Output.
errCode = IsBaseClassOf(&bBaseClassOf, "Parcels");
if (errCode == AcMapObjClass::eOk)
{
if (bBaseClassOf == true)
{
...
}
}
Use GetProperty() or GetProperties() to retrieve a specific property, or all properties, of a feature class definition. GetProperties() retrieves only properties that are classified, which you can determine with IsPropertyClassified(). You can add or delete a property with AddProperty() or DeleteProperty(). To change a property's attributes, see Managing Properties.
// Retrieve the Linetype property.
AcMapObjClass::EErrCode errCode;
AcMapObjClassProperty* pProperty = NULL;
AcMapStringArray aStrParentToSubCategoryNames;
aStrParentToSubCategoryNames.Append("General");
const char* pszPropertyName="Linetype";
errCode = GetProperty(pProperty, aStrParentToSubCategoryNames, pszPropertyName);
if (errCode == AcMapObjClass::eOk)
{
// Process the property.
}
For digitizing data, use SetCreateMethod() (twoforms),GetCreateMethod(), and GetCreateMethodName()to set or retrieve the AutoCAD entity type that a feature class definition uses when a digitize process runs.
For feature-classification source-code samples, seeFeature Classification Samples.
Use AcMapObjClassProperty functions to manage a property for a feature class definition. You can retrieve and (in some cases) set the following attributes of a property:
- Name - GetName()
- Direct category - GetCategory()
- Type - GetType()
- Default value -GetDefaultValue()/SetDefaultValue
- Range -GetRange()/SetRange()/IsInRange()
- Visibility -IsVisible()/SetVisible()
- Read-only -IsReadOnly()/SetReadOnly()
- String representation -FromString()/ToString()
For feature-classification source-code samples, seeFeature Classification Samples.
// Set the range of the Length property.
AcMapObjClass::EErrCode errCode;
AcMapObjClassProperty* pProperty = NULL;
AcMapStringArray aStrParentToSubCategoryNames;
aStrParentToSubCategoryNames.Append("Geometry");
const char* pszPropertyName = "Length";
errCode = GetProperty(pProperty, aStrParentToSubCategoryNames, pszPropertyName);
if (errCode == AcMapObjClass::eOk)
{
errCode = pProperty->SetRange("0.0,1.0,2.0,3.0");
if (errCode == AcMapObjClass::eOk)
{
...
}
}
Using Reactors with Feature Class Definition Events
The AcMapObjClassReactorclass provides callback functions that notify an application immediately of feature class definition events. You use this mechanism to monitor or control feature class definition operations by registering reactor instances. Functions are invoked automatically depending on the operation's type, as described in the following table:
Function | Invoked when a |
---|---|
FeatureClassDefinitionCreated() | Feature class definition is created |
FeatureClassDefinitionDeleted() | Feature class definition is deleted |
FeatureClassDefinitionModified() | Feature class definition is modified |
FeatureClassDefinitionRenamed() | Feature class definition is renamed |
FeatureDefinitionFileAttached() | Feature-definition file is attached to or detached from the current drawing |
FeatureDefinitionFileModified() | Feature-definition file is modified and saved |
Use AcMapObjClassSystem to register and unregister classification reactors with AddObjClassReactor() and RemoveObjClassReactor(). To use a reactor, perform the following steps, as shown in the sample code that follows:
- Derive a custom class from AcMapObjClassReactor.
- Implement events by overriding the virtual functions that you need.
- Create an instance of the custom reactor.
- Register the instance so that it becomes active.
- Write some classification reactor code.
- Remove the reactor from the list and delete it.
For
feature-classification source-code samples, see
// Derive a custom class from AcMapObjClassReactor.
class AcMapObjClassMyReactor : public AcMapObjClassReactor
{
// Override virtual functions for the desired events.
};
// Create an instance of the custom reactor.
AcMapObjClassMyReactor* pMyReactor = new AcMapObjClassMyReactor;
// Register the custom reactor.
AcMapObjClassSystem().AddObjClassReactor(pMyReactor);
// Insert classification reactor code here.
// Remove the reactor and delete it.
AcMapObjClassSystem().RemoveObjClassReactor(pMyReactor);
delete pMyReactor;
Many functions in the various feature-classification classes return an AcMapObjClass::EErrCode error code. When a particular function returns an error code, read that function's documentation for function-specific error conditions rather than relying on only the generic error descriptions in the AcMapObjClass::EErrCode documentation.
- For more information about feature classification in AutoCAD Map 3D, choose Help > AutoCAD Map 3D Help > Contents tab (or press F1), and then navigate to Using AutoCAD Map 3D (by feature) > Feature Classification.
- For a feature-classification tutorial in AutoCAD Map 3D, choose Help > Tutorials > Contents tab, and then choose "Using Feature Classification".
Feature Classification Samples
To view code samples of classification functions, open the Samples folder in your AutoCAD Map 3D ObjectARX installation and navigate to Map Samples\Classification.
Feature Classification Classes and Namespaces
To view the feature-classification classes and namespaces, click the following links: