RevitObjectsHelper 1.2.0

Simple library for work with Revit objects in ORM style

Install-Package RevitObjectsHelper -Version 1.2.0
dotnet add package RevitObjectsHelper --version 1.2.0
<PackageReference Include="RevitObjectsHelper" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RevitObjectsHelper --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Revit object helper

Simple library for work with Revit objects in ORM style.

Instalation

PM> Install-Package RevitObjectsHelper

Usage

  //Create class representing Revit element
  [Instance] //Get all instaces of elements, if you want to get types set [Symbol]
  [Class(typeof(Wall))] //Get only walls, also you can set [Category(BuiltInCategory.Walls)]
  public class MyWall : DbObject
  {
    [BuiltInParameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)] //Bind Revit builtin parameter "Comments" to property Comments
    public string Comments { get; set; }

    [ParameterName("Length")] //Bind Revit parameter "Length" to property Length
    public double Length { get; set; }
  }

  // Create DbContext class
  public class MyContext : DbContext
  {
    //Create property what represents all walls
    public DbObjectSet<MyWall> Walls { get; set; }
  }

  //Use context in your command
  [Transaction(TransactionMode.Manual)]
  [Regeneration(RegenerationOption.Manual)]
  public class CmdCommand : IExternalCommand
  {
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
      var uiApp = commandData.Application;
      var doc = uiApp.ActiveUIDocument.Document; //Get current document

      var context = DbContext.Create<MyContext>(doc); //Create context

      //Iterate walls
      foreach (var wall in context.Walls)
      {
        wall.Comments = "Hello!!!"; //Change comment
        wall.Save(); //Save it! It's generate transaction on each wall
      }

      //Or iterate walls
      foreach (var wall in context.Walls)
      {
        wall.Comments = "Hello!!!"; //Change comment
      }
      context.Walls.Save(); //Save all walls by one transaction

      return Result.Succeeded;
    }
  }

Revit object helper

Simple library for work with Revit objects in ORM style.

Instalation

PM> Install-Package RevitObjectsHelper

Usage

  //Create class representing Revit element
  [Instance] //Get all instaces of elements, if you want to get types set [Symbol]
  [Class(typeof(Wall))] //Get only walls, also you can set [Category(BuiltInCategory.Walls)]
  public class MyWall : DbObject
  {
    [BuiltInParameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)] //Bind Revit builtin parameter "Comments" to property Comments
    public string Comments { get; set; }

    [ParameterName("Length")] //Bind Revit parameter "Length" to property Length
    public double Length { get; set; }
  }

  // Create DbContext class
  public class MyContext : DbContext
  {
    //Create property what represents all walls
    public DbObjectSet<MyWall> Walls { get; set; }
  }

  //Use context in your command
  [Transaction(TransactionMode.Manual)]
  [Regeneration(RegenerationOption.Manual)]
  public class CmdCommand : IExternalCommand
  {
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
      var uiApp = commandData.Application;
      var doc = uiApp.ActiveUIDocument.Document; //Get current document

      var context = DbContext.Create<MyContext>(doc); //Create context

      //Iterate walls
      foreach (var wall in context.Walls)
      {
        wall.Comments = "Hello!!!"; //Change comment
        wall.Save(); //Save it! It's generate transaction on each wall
      }

      //Or iterate walls
      foreach (var wall in context.Walls)
      {
        wall.Comments = "Hello!!!"; //Change comment
      }
      context.Walls.Save(); //Save all walls by one transaction

      return Result.Succeeded;
    }
  }

Release Notes

Fix throwing exceptions. Added BuiltInParameter attribute for binding properties to builtin Revit parameters.

Dependencies

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.2.0 523 4/28/2018
1.1.1 370 3/15/2018
1.0.0 346 3/8/2018