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
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