Results 1 to 7 of 7

Thread: (Structural) How to read/change a parameter

  1. #1
    100 Club
    Join Date
    2006-07
    Posts
    130
    Login to Give a bone
    0

    Default (Structural) How to read/change a parameter

    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.

  2. #2
    Active Member
    Join Date
    2015-10
    Location
    Escondido, CA
    Posts
    91
    Login to Give a bone
    0

    Default Re: (Structural) How to read/change a parameter

    You should be able to access the structural usage parameter directly. Try something like this:

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

  3. #3
    100 Club
    Join Date
    2006-07
    Posts
    130
    Login to Give a bone
    0

    Default Re: (Structural) How to read/change a parameter

    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?

  4. #4
    Active Member
    Join Date
    2015-10
    Location
    Escondido, CA
    Posts
    91
    Login to Give a bone
    0

    Default Re: (Structural) How to read/change a parameter

    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.

    Code:
    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!

  5. #5
    100 Club
    Join Date
    2006-07
    Posts
    130
    Login to Give a bone
    0

    Default Re: (Structural) How to read/change a parameter

    Quote Originally Posted by Elizabeth Shulok View Post
    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.

  6. #6
    Active Member
    Join Date
    2015-10
    Location
    Escondido, CA
    Posts
    91
    Login to Give a bone
    0

    Default Re: (Structural) How to read/change a parameter

    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):
    Code:
    FamilyInstance inst = elem as FamilyInstance;
    Once you cast it to a FamilyInstance object, you can access that StructuralUsage parameter.

    Hope that helps.

  7. #7
    100 Club
    Join Date
    2006-07
    Posts
    130
    Login to Give a bone
    0

    Default Re: (Structural) How to read/change a parameter

    Elisabeth! Once again you've shown me the light. Many thanks.

Similar Threads

  1. Replies: 4
    Last Post: 2010-07-07, 06:52 PM
  2. Read a Value of Revit family parameter from Excel
    By hhajian in forum Revit - Student Support
    Replies: 0
    Last Post: 2010-02-06, 02:10 AM
  3. Change Project Parameter to Shared Parameter?
    By kgodfrey in forum Revit Structure - General
    Replies: 0
    Last Post: 2008-11-12, 04:43 PM
  4. AutoCAD 2006 DWG files suddenly change to Read Only
    By UFO in forum AutoCAD General
    Replies: 6
    Last Post: 2007-03-26, 11:34 AM
  5. How can I change the variable PSTYLEMODE (read only)
    By JMonrex Gadgude in forum AutoCAD Plotting
    Replies: 5
    Last Post: 2005-07-13, 07:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •