Accelerator, Dash Pattern Fix, Rotation and Phase

I am participating in the Forge Accelerator in Barcelona this week.

We are hosting a large number of participants, split up into separate manufacturing and AEC related groups:

Forge Accelerator in Barcelona

I arrived good and early, spending the weekend visiting my sister, who moved here last summer:

Barcelona view

My brother came too, and we went climbing, right in the middle of town, in Las Foixardas in the Parc Montju%C3%AFc:

El tunel de las Foixardas

Let me mention some pending Revit API issues before diving into any accelerator topics:

AddMaterials Enhancements

The AddMaterials add-in originally just added materials to the Revit model from a list of properties defined in Excel.

It has since been enhanced to also visualise them in WPF.

I recently added a couple of enhancements to the it that have not been mentioned here yet:

In the pull request, John @ridespirals Varga points out an important hint to handle errors caused by real number imprecision in dash or hash pattern definitions:

We are using similar code in a project of ours, and we ran into an issue where some fill patterns had blank preview images. Some of the patterns had very small negative values (such as -5.9211894646675012E-16), and DashPatterns must be greater than 0. Using float.Epsilon produces previews that actually look correct.

Example preview we got by filtering out segments that were <= 0 (Third Bond - Emporer Brick - partial fix):

Segments almost zero

Example using the fix in this pull request, using float.Epsilon (Third Bond - Emporer Brick - fixed):

Segments fixed using float.Epsilon

Retrieving Element Rotation

Question: How can I retrieve the rotation angle of an element that has been rotated, e.g., using the rotation tool or the RotateElement method?

Answer: RotateElement takes an angle parameter, but that angle is not necessarily stored in an element.

It depends on how the element's location is stored.

For many elements, Element.Location can be cast to a LocationPoint, and its Rotation property read.

Elements that inherit from Instance inherit a GetTransform method whose result can be parsed to read the rotation.

For elements that don't align with either of these options, the rotation is more implicit with other element properties.

For instance, a wall that is driven by endpoints and a curve, after rotating, is still driven by endpoints and a curve, just in different locations.

Changing the Phase Created Parameter

From the Revit API discussion forum thread on changing an element's phase created parameter and setting an element's phase:

Question: How can I set the 'Phase Created' or the 'Phase Demolished' of an element?

I know I can retrieve the 'Phase Created' like this:

  phaseCreated = element.Document.GetElement( 
    element.CreatedPhaseId ) as Phase;

However, I can't figure out how to change it to set the phase.

Answer: You can use two built-in parameters:

  element.get_Parameter( 
    BuiltInParameter.PHASE_CREATED )
      .Set( phaseCrea​ted.Id );

  element.get_Parameter( 
    BuiltInParameter.PHASE_DEMOLISHED )
      .Set( phaseC​reated.Id );