Skip to content

Commit

Permalink
Merge pull request #1880 from thumDer/feature/directcontext3d
Browse files Browse the repository at this point in the history
dc3d server implementation with example
  • Loading branch information
jmcouffin authored Aug 7, 2023
2 parents eec4276 + 8fd9f1e commit c9b09c4
Show file tree
Hide file tree
Showing 7 changed files with 779 additions and 1 deletion.
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
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)
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>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
title: Developer Examples
layout:
- CLR
- Inspect IExporter
- Inspect IExporter
- DirectContext3D
2 changes: 2 additions & 0 deletions pyrevitlib/pyrevit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from Autodesk.Revit import ApplicationServices
from Autodesk.Revit import DB
from Autodesk.Revit import UI
from Autodesk.Revit.DB import ExternalService
from Autodesk.Revit.DB import DirectContext3D


def get_product_serial_number():
Expand Down
1 change: 1 addition & 0 deletions pyrevitlib/pyrevit/revit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from pyrevit.revit import units
from pyrevit.revit import features
from pyrevit.revit import bim360
from pyrevit.revit import dc3dserver


#pylint: disable=W0703,C0302,C0103
Expand Down
Loading

0 comments on commit c9b09c4

Please sign in to comment.