Yesterday was the last day of the advanced Revit Structure API training at Steel & Graphics srl in Verona, Italy, with Gianni, Stefano, Michele, Paolo, and we started diving into deeper topics.
But first, here are some of the initial things we discussed in the previous days:
I already posted a description of the changes made to FrameBuilder to make the category comparison language independent. Notes on adding filtering may follow later. Here are some notes on the first of these issues:
Making use of AddCoping is pretty trivial. All we need to do is select two suitable beams, for instance a wide steel flange beam to cut a hole into, and a steel bar to define the hole, then feed these two instances into the AddCoping method. First of all, we implemented the following method to either extract a preselected element from the document selection set, or prompt the user to select a new one:
Element GetSelectedElement( Document doc, string description ) { Selection sel = doc.Selection; Element e = null; while( null == e ) { ElementSetIterator i = sel.Elements.ForwardIterator(); if( i.MoveNext() ) { e = i.Current as Element; sel.Elements.Remove( e ); } if( null == e ) { sel.Elements.Clear(); sel.StatusbarTip = "Please select " + description; if( !sel.PickOne() ) { return null; } } } return e; }
Then we can make use of that to select the two elements in the correct order and call the AddCoping method on the larger beam:
public IExternalCommand.Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ) { string s = "Please select a family instance for the "; IExternalCommand.Result rc = IExternalCommand.Result.Failed; Application app = commandData.Application; Document doc = app.ActiveDocument; Element e1 = GetSelectedElement( doc, "beam to cut" ); if( null != e1 ) { Element e2 = GetSelectedElement( doc, "bar to drill hole" ); if( null != e2 ) { FamilyInstance beam = e1 as FamilyInstance; FamilyInstance bar = e2 as FamilyInstance; if( null == beam ) { message = s + "beam"; } else if( null == bar ) { message = s + "bar"; } else { beam.AddCoping( bar ); rc = IExternalCommand.Result.Succeeded; } } } return rc; }
The result of executing this is the flange beam with a nice little hole in it:
Unfortunately, this cannot be used as a generic Boolean operation, because if the bar is erased from the project, the hole immediately and automatically seals up again.
I hope to be able to jot down some notes on the other topics listed above on the way back home.