May 23, 2017

ACA: Wall Rotation Property

I came across a request today from someone who wanted to be able to set up a Display Theme based on the rotation of Walls, to graphically call out any that were close to, but not quite orthogonal. Rotation is not one of the automatic property sources for Walls, but it is a property of a Wall and that data can be extracted using a Formula property. The raw data is in radians, but you can apply the appropriate factor to covert that to degrees in the Formula property. Here are the formulas I created to make the Wall rotation value available as a property that could then be the basis of a Display Theme:

Radians
On Error Resume Next
Set acadApp = GetObject(,"AutoCAD.Application")
Set wallObj = acadApp.ActiveDocument.ObjectIDToObject( [ObjectID] )
RESULT = CDbl( wallObj.Rotation )

Degrees
On Error Resume Next
Set acadApp = GetObject(,"AutoCAD.Application")
Set wallObj = acadApp.ActiveDocument.ObjectIDToObject( [ObjectID] )
pi = 4 * Atn( 1.0 )
RESULT = CDbl( (wallObj.Rotation * 180.0) / pi)

In both cases, the formulas above assume that, in the same Property Set Definition, an automatic property called ObjectID has been added, referencing the ObjectID automatic property source. The reference to this property in the formula needs to be made by double clicking on that property in the lower left pane of the Formula Property Definition dialog, when creating the Formula property.

Please note that I have had issues with Formula properties that use the Set acadApp = GetObject(,"AutoCAD.Application") line to get the AutoCAD application object, when multiple versions of AutoCAD are open at the same time. Something to keep in mind, should you see Formula properties failing, particularly ones that had worked before. (I am not certain whether the same effect occurs if you have multiple instances of the same version running simultaneously; I rarely do that, but often have multiple versions running at the same time.)

No comments: