PDA

View Full Version : How to get the object type?



sfaust
2007-11-07, 08:52 PM
Ok, I am just messing with the API to try and learn it. Learning programming (and dusting off VERY old and outdated programming knowledge and trying to update it) so i have what is probably a pretty simple question.

I would like for now to be able to have Revit tell me how many of which object types I have selected. I know GuyR has made the NumElements program and I've looked at that but it's in C and all I know anything about is VB so I couldn't really figure out how it was working.

I got it so that it will tell me how many total objects are selected (that I was able to get from GuyR's posts) and will tell me the name of the object by using Autodesk.Revit.Element.Name, but when I tried to change it to Element.ObjectType it returns the error "Argument 'Prompt' cannot be converted to type 'String'". That tells me that ObjectType is not a string, but then I don't understand how to get it to tell me if I've selected a wall or a window or what...

Here is my code:

PublicFunction Execute(ByVal commandData As Autodesk.Revit.ExternalCommandData, _
ByRef message AsString, ByVal elements As Autodesk.Revit.ElementSet) _
As Autodesk.Revit.IExternalCommand.Result Implements Autodesk.Revit.IExternalCommand.Execute
Try
Dim numsel AsInteger = commandData.Application.ActiveDocument.Selection.Elements.Size
Dim selset As Autodesk.Revit.ElementSet = commandData.Application.ActiveDocument.Selection.Elements
Dim elem As Autodesk.Revit.Element
MsgBox("You Selected " & numsel & " Elements")
ForEach elem In selset
MsgBox(elem.ObjectType)
Next
Return Autodesk.Revit.IExternalCommand.Result.Succeeded
Catch ex As Exception
message = ex.Message
Return IExternalCommand.Result.Failed
EndTry
EndFunction

Can anyone point me in the right direction? Any help for a beginner would be appreciated :)

Thanks,
Steve

GuyR
2007-11-07, 09:51 PM
Ok, I am just messing with the API to try and learn it. Learning programming (and dusting off VERY old and outdated programming knowledge and trying to update it) so i have what is probably a pretty simple question.

Here is my code:


Thanks,
Steve

You know I look at that code and I can't grok VB.NET ;-) If you want to convert between VB.NET and c# then use this page http://codeconverter.sharpdevelop.net/Convert.aspx . Every element(object) in Revit has a type. eg: Walls are a type (class) Autodesk.Revit.Elements.Walls which is the namespace of the underlying class. To see the string representation ObjectType.ToString() will return a plain text description of Revit elements that have an exposed class Not all elements do however. You have to be a little careful not all elements have 'first class' equivalents like walls. The most obvious is families which are type Autodesk.Revit.Elements.FamilyInstance or Autodesk.Revit.Elements.FamilySymbol for the family type. So to find all fwindows you need to find all family instances and check the element category which involves a little more work.

I would suggest converting my code , if you use sharpdevelop you can do that in project or use the online tool, that should clarify things.

HTH,

Guy

sfaust
2007-11-07, 10:19 PM
cool. I was wondering if it was possible to convert between languages. THanks so much for the tips. I'll check it out and see if I can't come up with it...

thanks again