PDA

View Full Version : (Structural) How to read/change a parameter



ppirtle
2008-04-16, 03:06 PM
I'm trying to read (and ultimately, to change) the "structural usage" parameter for a beam. In going through the SDK examples, as well as the handouts from AU07, here are a couple of code snippets I've tried.

1. First, I tried simply listing ALL of the parameters:

.......... If TypeOf elem Is FamilyInstance Then
.......... If elem.Category.Name.Equals("Structural Framing") Then

.................... 'Print the element ID
.................... sMsg = "ID=" + elem.Id.Value.ToString()
.................... 'MsgBox(sMsg, MsgBoxStyle.Exclamation, "Selection Info")
.................... frm.Text = sMsg

.................... 'Print out all of the available parameters
.................... sMsg = ""
.................... For Each param In elem.Parameters

.............................. sMsg = param.Definition.Name + " = "

.............................. Select Case param.StorageType
........................................ Case StorageType.Double
........................................ sMsg += param.AsDouble.ToString '+ vbCrLf
........................................ Case StorageType.Integer
.................................................. sMsg += param.AsInteger.ToString '+ vbCrLf
........................................ Case StorageType.String
.................................................. sMsg += param.AsString '+ vbCrLf
........................................ Case StorageType.ElementId
.................................................. sMsg += param.AsElementId.Value.ToString '+ vbCrLf
........................................ Case StorageType.None
.................................................. sMsg += "?NONE?" '+ vbCrLf
........................................ Case Else
.................................................. sMsg += "?ELSE?" '+ vbCrLf
.............................. End Select
.............................. frm.lstParams.Items.Add(sMsg)
.................... Next
.................... MsgBox(sMsg)

Although it did, in fact, print out a bunch of parameter names, only a few of them seemed to have values.




2. Then, I tried this:

.......... Try
.................... param = elem.Parameter(BuiltInParameter.INSTANCE_STRUCT_USAGE_PARAM)
.................... If Not param Is Nothing Then
.............................. Dim parInBuiltName As String = param.Definition.Name
.............................. Dim parInBuiltType As String = GetParamStorageType(param).ToString
.............................. Dim parInBuiltValue As String = GetParamAsString(param)

.............................. MsgBox("INSTANCE_STRUCT_USAGE_PARAM: Name=" & parInBuiltName & "; Type=" & parInBuiltType & "; Value=" & parInBuiltValue)
.................... Else
.............................. MsgBox("?ELSE?")
.................... End If
.......... Catch
.................... MsgBox("?CATCH?")
.......... End Try

This always gives me the "?ELSE?" message box.



So, can anyone offer me some direction? TIA for your help.

Elizabeth Shulok
2008-04-16, 05:21 PM
You should be able to access the structural usage parameter directly. Try something like this:

elem.StructuralUsage = Autodesk.Revit.Structural.Enums.InstanceUsage.Girder

ppirtle
2008-04-16, 06:28 PM
Elizabeth -
Thanks for your reply. When I try this:

Dim usage as Integer
usage = elem.StructuralUsage


I get the message that:

'StructuralUsage' is not a member of 'Autodesk.Revit.Element'

Am I misunderstanding?

Elizabeth Shulok
2008-04-16, 09:53 PM
Sorry, I assumed your elem was of type FamilyInstance. I'm not a VB developer, but here is the C# code to filter your elements to just get the FamilyInstances and then access the structural usage parameter. You should be able to do something similar in VB.



Document oRevitDoc = m_oRvtCommandData.Application.ActiveDocument;
// get just the FamilyInstance elements (beams, columns, braces, foundation)
ElementFilterIterator itrFamilyInstance = oRevitDoc.get_Elements(typeof(FamilyInstance));
itrFamilyInstance.Reset();
bool bMoreElements = itrFamilyInstance.MoveNext();
while (bMoreElements)
{
FamilyInstance oRvtElement = itrFamilyInstance.Current asFamilyInstance;
if (null == oRvtElement)
{
bMoreElements = itrFamilyInstance.MoveNext();
continue;
}

oRvtElement.StructuralUsage = Autodesk.Revit.Structural.Enums.InstanceUsage.Girder;
}


Let me know if that works!

ppirtle
2008-04-16, 10:27 PM
Sorry, I assumed your elem was of type FamilyInstance.

OK, now I'm REALLY confused (an improvement on my usual state!). Here's the code I was using immediately before trying to get the parameter:

..........For Each elem In doc.Selection.Elements
....................If TypeOf elem Is FamilyInstance Then
..............................If elem.Category.Name.Equals("Structural Framing") Then

So, I thought it was a FamilyInstance, too. I'm only selecting a single element, so the For Each will ultimately get rewritten to insure only a single element is chosen.

As always, thanks for your help and suggestions.

Elizabeth Shulok
2008-04-17, 05:09 AM
Ah, OK. Your element is a FamilyInstance, but you need to cast it to a family instance. I'm not sure how you do that in VB, but in C# you'd do something like this (once you know it is a FamilyInstance):


FamilyInstance inst = elem as FamilyInstance;

Once you cast it to a FamilyInstance object, you can access that StructuralUsage parameter.

Hope that helps.

ppirtle
2008-04-18, 03:27 PM
Elisabeth! Once again you've shown me the light. Many thanks.