Skip to content

Commit

Permalink
Update Options and Assets
Browse files Browse the repository at this point in the history
- Add `Options` in `PreviewWindow` to control `get_Geometry`.
- Add `Assets` with base image.
  • Loading branch information
ricaun committed Aug 24, 2023
1 parent 44e4829 commit bf23d1d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
Binary file added Assets/PreviewWindow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Features
- First Release
- `PreviewWindow` with simple `Revit` geometry viewer.
- Add `Options` in `PreviewWindow` to control `get_Geometry`.
- Add `Assets` with base image.
- Update `ricaun.HelixToolkit.Wpf` - `2.20.2`

[vNext]: ../../compare/1.0.0...HEAD
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
[![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Build](https://github.com/ricaun-io/ricaun.HelixToolkit.Wpf.Revit/actions/workflows/Build.yml/badge.svg)](https://github.com/ricaun-io/ricaun.HelixToolkit.Wpf.Revit/actions)

`PreviewWindow` for Revit `GeometryObjects` using `HelixToolkit` and `WPF`.

<a href="https://github.com/ricaun-io/ricaun.HelixToolkit.Wpf.Revit/blob/master/ricaun.HelixToolkit.Wpf.Revit/Revit/Commands/Command.cs"><image src="Assets/PreviewWindow.png" alt="PreviewWindow"></image></a>

## Install

Install the package from [ricaun.HelixToolkit.Wpf.Revit](https://www.nuget.org/packages/ricaun.HelixToolkit.Wpf.Revit/).
Expand Down Expand Up @@ -40,15 +44,15 @@ previewWindow.ZoomExtents();

### Revit

The `Element` could be used and the Material or GraphicsStyle will be used to render the geometry.
The `Element` could be used and the `Material` or `GraphicsStyle` will be used to render the geometry.

```C#
new PreviewWindow()
.Add(element)
.ShowDialog();
```

The `Document` is used to get the Material or GraphicsStyle color for `GeometryObject`.
The `Document` is used to get the `Material` or `GraphicsStyle` color for `GeometryObject`.

```C#
new PreviewWindow()
Expand All @@ -59,6 +63,7 @@ new PreviewWindow()

The `PreviewWindowRevitUtils` has some utils methods to use with `PreviewWindow`.
```C#
previewWindow.SetOptions(options)
previewWindow.SetDocument(document);
previewWindow.Add(element);
previewWindow.Add(elements);
Expand Down
15 changes: 14 additions & 1 deletion ricaun.HelixToolkit.Wpf.Revit/PreviewWindowRevitUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ricaun.HelixToolkit.Wpf.Revit
/// </summary>
public static class PreviewWindowRevitUtils
{
static Options Options;
/// <summary>
/// GetVisual3D
/// </summary>
Expand All @@ -20,13 +21,25 @@ public static class PreviewWindowRevitUtils
public static Visual3D GetVisual3D(Element element)
{
DocumentUtils.Document = element.Document;
Options options = new Options()
Options options = Options ?? new Options()
{
DetailLevel = ViewDetailLevel.Fine
};
return element.get_Geometry(options).ToVisual3D();
}

/// <summary>
/// SetOptions to use when Element <see cref="Autodesk.Revit.DB.Element.get_Geometry(Autodesk.Revit.DB.Options)"/>
/// </summary>
/// <param name="previewWindow"></param>
/// <param name="options"></param>
/// <returns></returns>
public static PreviewWindow SetOptions(this PreviewWindow previewWindow, Options options)
{
Options = options;
return previewWindow;
}

/// <summary>
/// SetDocument
/// </summary>
Expand Down
27 changes: 6 additions & 21 deletions ricaun.HelixToolkit.Wpf.Revit/Revit/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
previewWindow.Closed += (s, e) => previewWindow = null;
}

previewWindow.Clear().Add(elements).Camera(view).ZoomExtents();
var options = new Options()
{
View = view,
};

previewWindow.Clear().SetOptions(options).Add(elements).Camera(view).ZoomExtents();
previewWindow?.Show();
previewWindow?.Activate();

Expand Down Expand Up @@ -68,24 +73,4 @@ private IEnumerable<FamilyInstance> GetSubElements(FamilyInstance familyInstance
return instances;
}
}


[Transaction(TransactionMode.Manual)]
public class CommandExample : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;

new PreviewWindow()
.Add(Line.CreateBound(XYZ.Zero, XYZ.BasisX))
.Add(Line.CreateBound(XYZ.Zero, XYZ.BasisY))
.Add(Line.CreateBound(XYZ.Zero, XYZ.BasisZ))
.ShowDialog();

return Result.Succeeded;
}
}


}
25 changes: 25 additions & 0 deletions ricaun.HelixToolkit.Wpf.Revit/Revit/Commands/CommandExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace ricaun.HelixToolkit.Wpf.Revit.Revit.Commands
{
[Transaction(TransactionMode.Manual)]
public class CommandExample : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;

new PreviewWindow()
.Add(Line.CreateBound(XYZ.Zero, XYZ.BasisX))
.Add(Line.CreateBound(XYZ.Zero, XYZ.BasisY))
.Add(Line.CreateBound(XYZ.Zero, XYZ.BasisZ))
.ShowDialog();

return Result.Succeeded;
}
}


}

0 comments on commit bf23d1d

Please sign in to comment.