-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1880 from thumDer/feature/directcontext3d
dc3d server implementation with example
- Loading branch information
Showing
7 changed files
with
779 additions
and
1 deletion.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
....extension/pyRevitDev.tab/Developer Examples.panel/DirectContext3D.pushbutton/bundle.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
title: "Test DirectContext3D" | ||
tooltip: | ||
author: Tamás Déri | ||
engine: | ||
clean: false | ||
full_frame: false | ||
persistent: true |
91 changes: 91 additions & 0 deletions
91
...ion/pyRevitDev.tab/Developer Examples.panel/DirectContext3D.pushbutton/dc3dtest_script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
from __future__ import print_function | ||
|
||
import traceback | ||
from pyrevit import script, forms, revit, DB | ||
|
||
doc = revit.doc | ||
uidoc = revit.uidoc | ||
|
||
logger = script.get_logger() | ||
output = script.get_output() | ||
|
||
class UI(forms.WPFWindow): | ||
def __init__(self, xaml_file_name): | ||
forms.WPFWindow.__init__(self, xaml_file_name, handle_esc=False) | ||
|
||
self.server = revit.dc3dserver.Server() | ||
if not self.server: | ||
script.exit() | ||
|
||
self.Closed += self.form_closed | ||
|
||
def form_closed(self, sender, args): | ||
try: | ||
self.server.remove_server() | ||
uidoc.RefreshActiveView() | ||
except: | ||
print(traceback.format_exc()) | ||
|
||
def button_apply(self, sender, args): | ||
try: | ||
x = float(self.txtCoordX.Text) | ||
y = float(self.txtCoordY.Text) | ||
z = float(self.txtCoordZ.Text) | ||
width = float(self.txtWidth.Text) | ||
height = float(self.txtHeight.Text) | ||
length = float(self.txtLength.Text) | ||
color = DB.ColorWithTransparency( | ||
int(self.txtRed.Text), | ||
int(self.txtGreen.Text), | ||
int(self.txtBlue.Text), | ||
int(self.txtTransp.Text) | ||
) | ||
|
||
except ValueError: | ||
forms.alert("Input value invalid!", sub_msg=traceback.format_exc()) | ||
return | ||
|
||
bb = DB.BoundingBoxXYZ() | ||
bb.Min = DB.XYZ( | ||
- width / 2, | ||
- length / 2, | ||
- height / 2, | ||
) | ||
bb.Max = DB.XYZ( | ||
width / 2, | ||
length / 2, | ||
height / 2, | ||
) | ||
|
||
bb.Transform = DB.Transform.CreateTranslation( | ||
DB.XYZ(x, y, z) | ||
) | ||
|
||
mesh = revit.dc3dserver.Mesh.from_boundingbox( | ||
bb, | ||
color | ||
) | ||
|
||
self.server.meshes = [mesh] | ||
uidoc.RefreshActiveView() | ||
|
||
def button_select(self, sender, args): | ||
element = revit.pick_element() | ||
geometry = revit.query.get_geometry(element) | ||
|
||
mesh = [] | ||
for geo in geometry: | ||
if not isinstance(geo, DB.Solid) or geo.Volume == 0: | ||
continue | ||
solid_mesh = revit.dc3dserver.Mesh.from_solid(doc, geo) | ||
if not solid_mesh: | ||
continue | ||
mesh.append(solid_mesh) | ||
|
||
self.server.meshes = mesh | ||
uidoc.RefreshActiveView() | ||
|
||
ui = UI("ui.xaml") | ||
ui.show(modal=False) |
49 changes: 49 additions & 0 deletions
49
...ools.extension/pyRevitDev.tab/Developer Examples.panel/DirectContext3D.pushbutton/ui.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
ShowInTaskbar="False" | ||
WindowStartupLocation="CenterScreen" | ||
HorizontalContentAlignment="Center" | ||
SizeToContent="WidthAndHeight"> | ||
<StackPanel Margin="5"> | ||
<Grid Margin="10"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="50"/> | ||
</Grid.ColumnDefinitions> | ||
<TextBlock Margin="5" Grid.Row="0" Grid.Column="0">X Coordinate</TextBlock> | ||
<TextBox Margin="5" Grid.Row="0" Grid.Column="1" Name="txtCoordX" Text="0" /> | ||
<TextBlock Margin="5" Grid.Row="1" Grid.Column="0">Y Coordinate</TextBlock> | ||
<TextBox Margin="5" Grid.Row="1" Grid.Column="1" Name="txtCoordY" Text="0" /> | ||
<TextBlock Margin="5" Grid.Row="2" Grid.Column="0">Z Coordinate</TextBlock> | ||
<TextBox Margin="5" Grid.Row="2" Grid.Column="1" Name="txtCoordZ" Text="0" /> | ||
<TextBlock Margin="5" Grid.Row="3" Grid.Column="0">Width</TextBlock> | ||
<TextBox Margin="5" Grid.Row="3" Grid.Column="1" Name="txtWidth" Text="1" /> | ||
<TextBlock Margin="5" Grid.Row="4" Grid.Column="0">Length</TextBlock> | ||
<TextBox Margin="5" Grid.Row="4" Grid.Column="1" Name="txtLength" Text="1" /> | ||
<TextBlock Margin="5" Grid.Row="5" Grid.Column="0">Height</TextBlock> | ||
<TextBox Margin="5" Grid.Row="5" Grid.Column="1" Name="txtHeight" Text="1" /> | ||
<TextBlock Margin="5" Grid.Row="6" Grid.Column="0">Red</TextBlock> | ||
<TextBox Margin="5" Grid.Row="6" Grid.Column="1" Name="txtRed" Text="255" /> | ||
<TextBlock Margin="5" Grid.Row="7" Grid.Column="0">Green</TextBlock> | ||
<TextBox Margin="5" Grid.Row="7" Grid.Column="1" Name="txtGreen" Text="0" /> | ||
<TextBlock Margin="5" Grid.Row="8" Grid.Column="0">Blue</TextBlock> | ||
<TextBox Margin="5" Grid.Row="8" Grid.Column="1" Name="txtBlue" Text="0" /> | ||
<TextBlock Margin="5" Grid.Row="9" Grid.Column="0">Transparency</TextBlock> | ||
<TextBox Margin="5" Grid.Row="9" Grid.Column="1" Name="txtTransp" Text="0" /> | ||
</Grid> | ||
<Button x:Name="btnApply" Click="button_apply" Content="Create Box" /> | ||
<Button x:Name="btnSelect" Margin="0,5,0,0" Click="button_select" Content="Pick Source Element" /> | ||
</StackPanel> | ||
</Window> |
3 changes: 2 additions & 1 deletion
3
extensions/pyRevitDevTools.extension/pyRevitDev.tab/Developer Examples.panel/bundle.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
title: Developer Examples | ||
layout: | ||
- CLR | ||
- Inspect IExporter | ||
- Inspect IExporter | ||
- DirectContext3D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.