PDA

View Full Version : Elements parameter



Danny Polkinhorn
2005-10-18, 11:35 PM
I'm setting the elements parameter at the end of my Execute function to highlight some items. However, they're not showing as highlighted. There are no errors in the code and the elements object is populated at the end with an ElementSet.

Has anyone else been successful using this?

Danny Polkinhorn
2005-10-19, 12:17 AM
Here's a sample that should highlight walls:


Public Function Execute(ByVal application As Autodesk.Revit.Application, ByRef message As String, ByVal elements As Autodesk.Revit.ElementSet) As Autodesk.Revit.IExternalCommand.Result Implements Autodesk.Revit.IExternalCommand.Execute
Try
Dim iter As IEnumerator
Dim objElementSet As Autodesk.Revit.ElementSet = application.Create.NewElementSet
iter = application.ActiveDocument.Elements
Do While (iter.MoveNext())
Dim element As Autodesk.Revit.Element
element = iter.Current
If Not (TypeOf element Is Autodesk.Revit.Symbol) Then
Dim category As Autodesk.Revit.Category
category = element.Category
If Not (category Is Nothing) Then
If category.Name = "Walls" Then
objElementSet.Insert(element)
End If
End If
End If
Loop
elements = objElementSet
MsgBox(elements.Size)
Return IExternalCommand.Result.Succeeded
Catch ex As Exception
message = ex.Message
Return IExternalCommand.Result.Failed
End Try
End Function
</FONT>

GuyR
2005-10-19, 12:46 AM
From your question you seem to want to highlight elements when successful. However from help:


A set of elements that can be displayed if an error occurs

So they'll only highlight if it fails... Is this want you want?

Guy

Danny Polkinhorn
2005-10-19, 12:53 AM
Thanks Guy. Yes, I tried all the different return values and none of them cause the highlight to occur. At least that's what I'm seeing. Have you tried it?

Danny Polkinhorn
2005-10-19, 01:18 AM
Seems like the parameter should be declared ByRef instead of ByVal. Otherwise it's scope ends when the function ends.

GuyR
2005-10-19, 01:57 AM
Looks like you found the problem? will update my binding.

For reference here's the python version with a quick true/false test added:


def testreturn(RvtApp,activeDocument,elementSet,allElements):
PF = 1
NewElementSet = RvtApp.Create.NewElementSet()
iter = allElements
while (iter.MoveNext()):
element = iter.Current
if element.GetType() != ofType("Autodesk.Revit.Elements.Instance"):
if hasattr(element.Category,"Name"):
category = element.Category.Name
if category == "Walls":
NewElementSet.Insert(element)
winForms.MessageBox.Show("Number of walls %d" %NewElementSet.Size)
if PF == 0:
pyRevit.Message = "Not successful"
pyRevit.Success = False
elif PF == 1:
pyRevit.Message = "successful"
pyRevit.Success = True
return elementSet

BTW: On a total blank project file created from a blank template this tells me I've created 2 walls. On my project template it tells me I've created 4 walls? A wall schedule is correct so goodness only knows what these walls are? Update: DUH!! I was counting symbols

Danny Polkinhorn
2005-10-19, 03:26 AM
No, I'm not able to change it from ByVal to ByRef, that's built into the API.

I don't speak Python, but it doesn't look like you're filtering out Symbols, you're filtering out Instances. :confused:

hand471037
2005-10-19, 05:16 AM
Here's a sample that should highlight walls:[PHP]

Whoa! you're using PHP? This doesn't look like PHP to me, but I don't know much about it. I thought you were using VBA. Does PHP work? That would rock if it does... I guess any .Net language can, 'theoretically'...

GuyR
2005-10-19, 05:58 AM
Whoa! you're using PHP?

The code quotes when editing posts are set to quote php code. This should really just be "code" then it doesn't refer to any language.

Danny,

You were right I was excluding instances. FWIW I don't think you need to exclude symbols and then test for wall categories. This is as direct as I could get it:


NewElementSet = RvtApp.Create.NewElementSet()
iter = allElements
while (iter.MoveNext()):
element = iter.Current
if element.GetType() == ofType("Autodesk.Revit.Elements.Wall"):
NewElementSet.Insert(element)
return NewElementSet

or in VB.NET


Do While (iter.MoveNext())
Dim element As Autodesk.Revit.Element
element = iter.Current
If (TypeOf element Is Autodesk.Revit.Elements.Wall) Then
objElementSet.Insert(element)
End If
Loop

And it doesn't highlight elements if Failed so looks like a bug. Or change the documentation:-)

Guy

Danny Polkinhorn
2005-10-19, 06:50 AM
Guy,

True, you don't need to exclude symbols. I just pulled that section of code from one of the samples. I think though that not all elements have a category, specifically some symbols. So, if you're testing for Category.Name, you might get an error. I'll check on this tomorrow.

Thanks for confirming that it's not working. I found another document in the SDK on the installation CD that confirms highlighting only works on Failed returns (or it's supposed to).

So, I'll add a wish list item: Have the elements parameter work for all return values (and work).

Thanks for all your assistance,

Steve_Stafford
2005-10-19, 07:08 AM
The code quotes when editing posts are set to quote php code. This should really just be "code" then it doesn't refer to any language.Just using "code" inplace of php will work too, but lose the color formatting of the code though, right?

Danny Polkinhorn
2005-10-19, 07:11 AM
lose the color formatting of the code though, right?Yes, it looks horrible.

Danny Polkinhorn
2005-12-02, 04:45 AM
I received confirmation that this is a known issue.

GuyR
2005-12-08, 07:59 PM
I received confirmation that this is a known issue.

Danny,

Was there any indication of there being a fix in any builds before V9?

Guy

Danny Polkinhorn
2005-12-08, 08:01 PM
No indication, sorry.