I already had one look at loading an Inventor ADSK component using the OpenBuildingComponentDocument method.
Ishwar Nagwani of Autodesk Consulting now revisited this topic from a different perspective and explains:
I came across another tricky issue while developing Revit add-in to import an ADSK file. I looked at your previous post on this when I started looking for way to open ADSK file in Revit and it helped me lot.
The ADSK file is created in Inventor and then processed in Revit to create an RFA file. This is part of a bigger project which does lots of other stuff like adding shared parameters etc.
The ADSK file after importing contains two ImportInstances. One of these is the bounding box, the other is the main solid itself. The outer bounding box hides the geometry in elevation views. Here the bounding box which would be deleted is displayed in red:
These are the selected bounding box details displayed using RevitLookup:
I open the ADSK file using the OpenBuildingComponentDocument method and then delete the bounding box in a separate transaction.
The following method retrieves the ImportInstances and deletes the one representing the bounding box, identified by the fact that it only has exactly six faces:
/// <summary> /// This method deletes the outer bounding box /// of an imported ADSK file in Revit. If this /// bounding box is not deleted, the elevation /// views cannot be seen. After importing an /// ADSK file the two ImportInstance objects /// are created in Revit, one for outer /// bounding box and the other for main solid. /// </summary> void DeleteOuterBox( Document doc ) { // Instantiate this once only: Options opt = doc.Application.Create .NewGeometryOptions(); // This is probably not needed: //opt.ComputeReferences = true; // Search the elements of type ImportInstance; // there will be two in case of ADSK import: FilteredElementCollector collector = new FilteredElementCollector( doc ) .OfClass( typeof( ImportInstance ) ); ElementId idToDelete = null; foreach( Element e in collector ) { ImportInstance inst = e as ImportInstance; if( inst != null ) { // Get the Solid from ImportInstance GeometryElement geomElem = inst.get_Geometry( opt ); // GeometryElement.Objects is obsolete, // so use LINQ extension methods instead. //GeometryObjectArray geomObjArray // = geomElem.Objects; int n = geomElem.Count<GeometryObject>(); if( 1 == n ) { Solid solid = geomElem .First<GeometryObject>() as Solid; if( null != solid ) { // The outer bounding box // has just 6 faces. if( solid.Faces.Size == 6 ) { // Do not delete during iteration;// remember the id instead. //doc.Delete( e.Id ); idToDelete = e.Id; break; } } } if( null != idToDelete ) { doc.Delete( idToDelete ); } } } }
Many thanks to Ishwar for this nice example!
Determining the Phase of a Room
Here is another issue brought up and solved by Håkon Clausen, whose RevitRubyShell I recently waxed so enthusiastic about:
Question: How do I find which phase a room is in?
From the UI, the phase is uneditable and is the same phase as the view you created it in. Unfortunately, the room CreatedPhaseId and DemolishedPhaseId properties are not valid (-1, InvalidElementId) and the Room class provides no explicit phase access. I looked through your posts regarding phases, on phase dependent room properties and the family instance room phase. They do not help, as they only describe how to determine the phases on family instances, not on the room itself.
Answer: I solved it by reading the built-in parameter value for ROOM_PHASE_ID on the room element.
On an interesting side note, I needed the same information for Mechanical.Space objects, and this also worked by accessing the same built-in parameter ROOM_PHASE_ID, which is a little obscure, I think...
Thank you, Håkon, for raising and clarifying this.
The same credit also goes to Martino, who posted a comment to the same effect on the view and phase filtering discussion.
From a content perspective it would be better to make the bound box visible at Course Level of detail, and detailed geometry not visible at Course and then vice versus, bounding box invisible at Medium and Fine, and detailed geometry visible. This makes for useful content for the end user, a bit off topic but I thought it was worth mentioning.
Of course, once you've found the bounding box it would not be so hard to change its properties.
Posted by: Robert Manna | August 22, 2012 at 20:47
hi! i wasnt able to find a tutorial on how to add a GUI to a add-in! a hello world example with a button and a dropdown would be cool! thank you
igor
Posted by: igor | August 23, 2012 at 04:19
Dear Igor,
The Revit API does not provide anything specific in that direction. You simply use the standard .NET framework functionality, above all the stuff provided in the System.Windows.Forms namespace. There are numerous samples making use of this functionality to create their own forms, buttons and dropdowns in the Revit SDK and the ADN sample material. Please examine that. You might want to start by looking at the getting started category:
http://thebuildingcoder.typepad.com/blog/getting_started
Here is the last update on this subject:
http://thebuildingcoder.typepad.com/blog/2012/07/obj-model-exporter-with-transparency-support.html#4
Here is a sample making more hardcore use of System.Windows.Forms functionality to create its own form completely programmatically on the fly:
http://thebuildingcoder.typepad.com/blog/2012/05/the-schedule-api-and-access-to-schedule-data.html
You can create buttons and drop down combo boxes analogously.
Cheers, Jeremy.
Posted by: Jeremy Tammik | August 23, 2012 at 05:04