Increment Parameter Value
next previous home

In this lab, we will increment the invisible parameter value by the following steps

#region Lab4_4_2_IncrementPerDocParameters
  /// <summary>
  /// Command to increment the invisible per-doc param
  /// </summary>
  public class Lab4_4_2_PerDocParams : IExternalCommand
  {
    public IExternalCommand.Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements )
    {
      Application app = commandData.Application;
      // Get the singleton Project Info Element
      Element projInfoElem = LabUtils.GetProjectInfoElem( app );
      if( null == projInfoElem )
      {
        LabUtils.ErrorMsg( "No project info elem found. Aborting command..." );
        return IExternalCommand.Result.Failed;
      }
      // For simplicity, access invisible param by name rather than by GUID:
      try
      {
        Parameter param = projInfoElem.get_Parameter( LabConstants.sParamNameInvisible );
        // report OLD value
        int iOldValue = param.AsInteger();
        LabUtils.ErrorMsg( "OLD value = " + iOldValue.ToString() );
        // set and report NEW value
        param.Set( iOldValue + 1 );
        LabUtils.ErrorMsg( "NEW value = " + param.AsInteger().ToString() );
      }
      catch( System.Exception e )
      {
        LabUtils.ErrorMsg( "Failed: " + e.Message );
        return IExternalCommand.Result.Failed;
      }
      return IExternalCommand.Result.Succeeded;
    }
  }
  #endregion // Lab4_4_2_IncrementPerDocParameters
#Region "Lab4_4_2_IncrementPerDocParameters"
''' <summary>
''' Command to increment the invisible per-doc param
''' </summary>
''' <remarks></remarks>
Public Class Lab4_4_2_PerDocParams
    Implements IExternalCommand
        Public Function Execute( _
            ByVal commandData As ExternalCommandData, _
            ByRef message As String, _
            ByVal elements As ElementSet) _
        As IExternalCommand.Result _
        Implements IExternalCommand.Execute

        Dim app As Revit.Application = commandData.Application
        Dim doc As Revit.Document = app.ActiveDocument

        ' Get the singleton Project Info Element
        Dim projInfoElem As Revit.Element = LabUtils.GetProjectInfoElem(doc, app)
        If projInfoElem Is Nothing Then
            MsgBox("NO project Info Elem found !? Aborting command...")
            Return IExternalCommand.Result.Failed
        End If

        ' For simplicity, access invisible param by name rather than by GUID:
        Try
            Dim param As Parameter = projInfoElem.Parameter(LabConstants.sParamNameInvisible)
            ' report OLD value
            Dim iOldValue As Integer = param.AsInteger
            MsgBox("OLD value = " & iOldValue)
            ' set and report NEW value
            param.Set(iOldValue + 1)
            MsgBox("NEW value = " & param.AsInteger)

        Catch e As Exception
            MsgBox("Failed!? : " & e.Message)
            Return IExternalCommand.Result.Failed
        End Try

        Return IExternalCommand.Result.Succeeded
    End Function
End Class
#End Region

next previous home copyright © 2007-2009 jeremy tammik, autodesk inc. all rights reserved.