PDA

View Full Version : BuiltInParameters


fwp
2006-12-19, 03:55 AM
All,

New to the API and working in VB. Is it possible to pull in the BuiltInParameter for both project_name and project_number. What type of object do I need to construct to read and set these values? Thanks in advance.

Frank

GuyR
2006-12-19, 08:02 AM
To get the parameters you first need to get the appropriate element. The clue is at the top of the project information form. Project Information is a system family therefore you need to walk the element tree to get this family. In this case Search the symbols looking for a element with category "project Information". This will give you the parameterset.

One for the wishlist. Would be nice if these system families didn't require walking the tree. Unfortunately the PI element Id changes from project to project so you can't just grab the elementID although you could parse once and store.

HTH,

Guy

fwp
2006-12-19, 05:46 PM
Thanks! Got it working. It would be nice if there was a more direct route.

awhite343
2007-01-03, 04:44 PM
Guy and others:

Like Frank, I got this working as well, so thank you.

Is it also possible to access custom information in the Project Information? We have added some project parameters in our default template (for example, one is called "Detail Order"). They show up fine under Project Information, but since it's not a Built In Parameter, I can't seem to access it. It seems as though the second option for parameter ought to allow for this as it appears in the .chm file -- parameter(definition as autodesk.revit.parameters.definition). However, this type of code doesn't work:

Do While ElementIter.MoveNext
Dim objElement As Autodesk.Revit.Element = ElementIter.Current
Dim Category As Autodesk.Revit.Category = objElement.Category
If Not (Category Is Nothing) Then
If Category.Name = "Project Information" Then
MsgBox("Project Information found")
objElement.Parameter("Detail Order").Set(1)
End If
End If
Loop

Any ideas on accessing custom project parameters in Project Information?

Thanks in advance,
Aaron

GuyR
2007-01-07, 09:25 PM
Aaron,

Almost right. The easiest way to process a mixture of builtin and custom parameters is to loop through all the parameters and process as you go.

To use element.parameter(...) requires the parameter definition or GUID for custom parameters.If it's not a shared parameter then you need to loop through all parameters for one element to get the definitions.... Because project information is only one element there isn't much point doing this so just use a foreach loop on the ParameterSet and a switch statement to process each parameter as required.

HTH,

Guy

awhite343
2007-01-08, 10:19 PM
Excellent, Guy...

Once again, you're the man. After taking your suggestion, it took about 2 minutes to code it and get it working. I'll keep this in mind for the rest of my API life: "When in doubt, walk the tree.".

Thanks again,
Aaron

GuyR
2007-01-08, 10:45 PM
I'll keep this in mind for the rest of my API life: "When in doubt, walk the tree."

Actually it depends... Walking the parameter tree is OK. Walking the element tree is to be avoided if possible.

Glad it helped.

Guy

sfaust
2008-02-22, 11:57 PM
Ok, help. I am trying to get read some custom project parameters from rooms. Just to get the idea I'm trying to first get Revit to walk the parameters of a single object and give me a message box with their value. It's working to start, but it gives me probably 8 or 10 parameters (some blank, but with no errors) and then gives me an "object reference not set to an instance of an object" error. My code is as follows:


Dim item As Room = rmset(1)
Dim param As String = ""
Dim pset As ParameterSet = item.Parameters
Try
For Each p As Parameter In pset
If Not p Is Nothing Then
Dim storageType As Parameters.StorageType = p.StorageType
Dim prompt As String = ""
Select Case storageType
Case storageType.[Integer]
Dim iVal As Integer = p.AsInteger()
prompt = iVal.ToString()
Exit Select
Case storageType.[String]
prompt = p.AsString()
Exit Select
Case storageType.[Double]
prompt = p.AsValueString()
Exit Select
Case storageType.ElementId
Dim elemId As Autodesk.Revit.ElementId = p.AsElementId()
Dim elem2 As Autodesk.Revit.Element = m_Revit.ActiveDocument.Element(elemId)
prompt = elem2.Name
Exit Select
Case Else
prompt = p.AsString()
Exit Select
End Select

MsgBox(prompt)

End If
Next
Catch ex As Exception
MsgBox(ex.ToString)
Return IExternalCommand.Result.Failed
End Try

Can anyone help?

sfaust
2008-02-23, 12:08 AM
Ok, well actually I took out the case statements and it seems to work now. I just made it say

MsgBox(p.AsString())

I got the case statement from the SDK room schedule sample so I figured I needed it. It doesn't seem that I do, or am I missing something? I will experiment further and post back...

thanks and if anyone has any suggestions please feel free.

mmason.65315
2008-02-23, 02:52 PM
Steve,

I'd say it's almost certainly because of how you handled the ElementId case...

While a parameter may exist that has an ElementId type, that doesn't mean that it's actually set to an actual element.

Off the top of my head, I think in that case, the ElementId.Value comes back as zero (or -1, I can't recall off hand). You're turning and trying to get the Element object from that ElementId - which I suspect is NULL. Then when you try to use Elem2.Name, you're getting your error.

In short, you need to test either the ElementId.Value > 0 or the Elem2 <> Null, and handle that case differently.

-Matt

sfaust
2008-02-25, 03:15 PM
hmm. Ok, thank you I will look at that. I'm still new to this programming stuff, thanks for the help :)