Quick Links - Also see the menu above and more choices on the right side of the blog (too much, but all good stuff)

\/ ...and now BIMbuilder.com Blog Posts... \/

Wednesday, March 17, 2010

The Building Coder: Object Relationships in VB

Finally...something that makes Revit look as complicated as AutoCAD, LISP routines and all that other junk.
Here you can see the brains behind the BIM. Yeah, this stuff is for the propeller heads, but you can at least see what you have to look forward to.

Source: http://thebuildingcoder.typepad.com/blog/2010/03/object-relationships-in-vb.html

We recently presented Saikat Bhattacharya's neat little object relationship analyser and displayer, implemented in C#. Yesterday I received a very friendly submission from Jose Guia saying "Thought I would share my code as well, ... I converted the project to VB for sharing."

I compiled his solution and it works fine for me. I did run into two little issues which were easy to solve, both of them involving namespaces:

  • Different access to imported namespaces.
  • Different namespace when exporting the external command.

Jose initially used explicit import statements in the VB source code to access the Revit API functionality:

Imports Autodesk
Imports Autodesk.Revit
Imports Autodesk.Revit.Elements

I much prefer that approach, since it is similar to the syntax used in C#. However, when I tried to compile the code like that, it caused a number of errors like these (copy to an editor to see the full truncated lines):

'Element' is not accessible in this context because it is 'Friend'.
'Symbol' is not accessible in this context because it is 'Friend'.
'FamilyBase' is not accessible in this context because it is 'Friend'.
'ElementId' is not accessible in this context because it is 'Friend'.

The only way I found to resolve this was to remove the explicit import statements from the code and add global namespace importing requests to the project settings instead:

VB project  references settings

The global imports are defined at the bottom:

VB project  global import settings

The second issue has to do with the exported namespace containing the external command. The VB code specifies the same export namespace as the C# version in the source code, ObjRel:

Namespace ObjRel
Public Class Command
Implements IExternalCommand

In spite of this, the Visual Studio environment surreptitiously prepends another namespace specified in the global project settings, the so-called root namespace, in this case ObjRelationsVB:

VB project  root namespace settings

Therefore, the class name entry in Revit.ini needs to be different for the C# and VB versions:

ECName2=Object Relationship
ECDescription2=Object Relationship Sample by Saikat

ECName3=Object Relationship VB
ECDescription3=Object Relationship Sample by Jose

Alternatively, of course, you can set the VB root namespace to an empty string, I hope. Or, alternatively, of course, you can use the Add-In Manager to load the application as suggested by Joe, and avoid dealing with Revit.ini at all. Once loaded, the VB port obviously presents the same functionality as Saikat's original C# version.

Here is Jose's complete ObjRelationsVB source code and Visual Studio solution.

Very many thanks to Jose for sharing this code!

Source: The Building Coder: Object Relationships in VB


Jose Guia March 18, 2010 at 6:22 AM  

Propeller heads. ;-) .. I resemble that remark.

Not sure if you remember me, we sat next to each other in Joseph Josephs BIM Class at AU .. How have you been?

  © Blogger template ProBlogger Template by Ourblogtemplates.com 2008

Back to TOP  

[Valid Atom 1.0]