Alignment Definitions for Custom Entities

Dynamic blocks support alignment parameters that automatically align block instances to adjacent objects. For instance, if a wall is drawn at an angle to the X axis, a door block instance that is dragged by its alignment grip can rotate itself to be flush with the angle of the wall.

AutoCAD entities enable this behavior by providing alignment information to dynamic block instances. Custom entity applications can provide their own alignment data by implementing the AcDbAlignment protocol extension and associating it with their custom AcRx classes. When a user drags a block instance by its alignment grip to the custom entity, the AcRx framework queries for registered AcDbAlignment implementations. On each implementation found, the AcDbAlignment::getAlignment() function is called.

The getAlignment() function must return an alignment point and an alignment vector that satisfy the custom entity's requirements. The implementing application is responsible for testing the entity passed to the getAlignment() function to determine whether it should process the entity. If so, the application provides the alignment point and vector to the framework, and the framework uses this information to rotate the dragged block to the indicated angle.

For instance, assume that the previously mentioned wall is a custom entity that implements an AcDbAlignment extension. If the user drags a door block to a wall object, the framework iterates through existing AcDbAlignment implementations and calls getAlignment() on each one. When the wall application's version is called, it first checks the entity argument to see if it is an instance of its wall object. If it is, the application inspects the argument that describes the door's normal vector. If the normal vector indicates that the door is not in the same plane as the wall, the wall application returns control to the framework.

On the other hand, if the door and the wall lie in the same plane, the wall application inspects the cursor location argument and calculates which point in the wall's geometry serves as the most suitable “snap” location. It then returns that point, as well as a vector reflecting the WCS angle of the wall geometry at that point. The door block object receives this information and offers to snap to the angle of the wall.