Skip to content

Commit

Permalink
Add GUI for 3D Rotation script
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilWaechter committed Mar 25, 2017
1 parent 3fd7cff commit 83ac2f1
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 27 deletions.
Empty file added __init__.py
Empty file.
@@ -0,0 +1,34 @@
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Set rotation angle:" Height="500" Width="500" ShowInTaskbar="False"
WindowStartupLocation="CenterScreen" ScrollViewer.VerticalScrollBarVisibility="Disabled" HorizontalContentAlignment="Center">
<StackPanel Margin="20" HorizontalAlignment="Stretch">
<DockPanel>
<GroupBox Header="Rotate on itself:" Margin="0,0,10,0">
<StackPanel Margin="10">
<Image x:Name="xyz_img" Width="100" Margin="0,10"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>

<TextBlock Text="X Axis" Grid.Column="0" HorizontalAlignment="Center" FontWeight="Bold" Foreground="#f00"/>
<TextBlock Text="Y Axis" Grid.Column="1" HorizontalAlignment="Center" FontWeight="Bold" Foreground="#0f0"/>
<TextBlock Text="Z Axis" Grid.Column="2" HorizontalAlignment="Center" FontWeight="Bold" Foreground="#00f"/>
<TextBox x:Name="x_axis" Text="0" Width="30" Height="30" Grid.Column="0" Margin="0,20,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<TextBox x:Name="y_axis" Text="0" Width="30" Height="30" Grid.Column="1" Margin="0,20,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<TextBox x:Name="z_axis" Text="0" Width="30" Height="30" Grid.Column="2" Margin="0,20,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
</Grid>
<TextBlock x:Name="warning" Text="" Width="150" HorizontalAlignment="Left" Foreground="#f00" TextWrapping="WrapWithOverflow" />
<Button Content="Go" Height="30" Margin="10,10" Click="around_itself_click"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Rotate around selected axis:">
<StackPanel Margin="20">
</StackPanel>
</GroupBox>
</DockPanel>
</StackPanel>
</Window>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 57 additions & 21 deletions pyRevitMEP.tab/Tools.panel/Element3DRotation.pushbutton/script.py
Expand Up @@ -3,7 +3,7 @@
Copyright (c) 2017 Cyril Waechter
Python scripts for Autodesk Revit
This file is part of pyRevitMEP repository at https://github.com/Nahouhak/pyRevitMEP
This file is part of pyRevitMEP repository at https://github.com/CyrilWaechter/pyRevitMEP
pyRevitMEP is an extension for pyRevit. It contain free set of scripts for Autodesk Revit:
you can redistribute it and/or modify it under the terms of the GNU General Public License
Expand All @@ -15,30 +15,66 @@
GNU General Public License for more details.
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/Nahouhak/pyRevitMEP/blob/master/LICENSE
https://github.com/CyrilWaechter/pyRevitMEP/blob/master/LICENSE
"""
from revitutils import doc, selection
from scriptutils.userinput import WPFWindow

from revitutils import doc, uidoc, selection
from math import pi

# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import Transaction, ElementTransformUtils, Line, XYZ, Location
from Autodesk.Revit.DB import Transaction, ElementTransformUtils, Line, XYZ, Location, UnitType, UnitUtils

__doc__ = "Rotate object in any direction"
__title__ = "3D Rotate"
__author__ = "Cyril Waechter"

getselection = uidoc.Selection.GetElementIds

try:
t = Transaction(doc, "Rotation axe x")
t.Start()
# Look for selected family origin and rotate it around x axis
for elid in selection.element_ids:
o = doc.GetElement(elid).Location.Point
z = XYZ(o.X + 1, o.Y, o.Z)
axis = Line.CreateBound(o, z)
ElementTransformUtils.RotateElement(doc, elid, axis, pi / 2)
t.Commit()
except:
raise
# Get project units for angles
angle_unit = doc.GetUnits().GetFormatOptions(UnitType.UT_Angle).DisplayUnits

def xyz_axis(element_id):
origin = doc.GetElement(element_id).Location.Point
xyz_direction = [XYZ(origin.X + 1, origin.Y, origin.Z),
XYZ(origin.X, origin.Y + 1, origin.Z),
XYZ(origin.X, origin.Y, origin.Z + 1)]
axis = []
for direction in xyz_direction:
axis.append(Line.CreateBound(origin, direction))
return axis


def rotate(element_id, axis, angle):
try:
ElementTransformUtils.RotateElement(doc, element_id, axis, angle)
except:
raise


class RotateOptions(WPFWindow):
"""
WPF form for rotation angle input
"""

def __init__(self, xaml_file_name):
WPFWindow.__init__(self, xaml_file_name)
self.set_image_source("xyz_img", "XYZ.png")

def around_itself_click(self, sender, e):
try:
angles = [self.x_axis.Text, self.y_axis.Text, self.z_axis.Text]
for i in range(3):
angles[i] = UnitUtils.ConvertToInternalUnits(float(angles[i]),angle_unit)
except ValueError:
self.warning.Text = "Incorrect angles, input format required '0.0'"
else:
self.DialogResult = True
self.Close()
t = Transaction(doc, "Rotate around itself")
t.Start()
for elid in selection.element_ids:
el_axis = xyz_axis(elid)
for i in range(3):
if angles[i] == 0:
pass
else:
rotate(elid,el_axis[i],angles[i])
t.Commit()

RotateOptions('RotateOptions.xaml').ShowDialog()
Expand Up @@ -2,7 +2,7 @@
Copyright (c) 2017 Cyril Waechter
Python scripts for Autodesk Revit
This file is part of pyRevitMEP repository at https://github.com/Nahouhak/pyRevitMEP
This file is part of pyRevitMEP repository at https://github.com/CyrilWaechter/pyRevitMEP
pyRevitMEP is an extension for pyRevit. It contain free set of scripts for Autodesk Revit:
you can redistribute it and/or modify it under the terms of the GNU General Public License
Expand All @@ -14,7 +14,7 @@
GNU General Public License for more details.
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/Nahouhak/pyRevitMEP/blob/master/LICENSE
https://github.com/CyrilWaechter/pyRevitMEP/blob/master/LICENSE
"""

# noinspection PyUnresolvedReferences
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions pyRevitMEP.tab/Tools.panel/FamilyDelete.pushbutton/script.py
@@ -0,0 +1,43 @@
"""
Copyright (c) 2017 Cyril Waechter
Python scripts for Autodesk Revit
This file is part of pyRevitMEP repository at https://github.com/CyrilWaechter/pyRevitMEP
pyRevitMEP is an extension for pyRevit. It contain free set of scripts for Autodesk Revit:
you can redistribute it and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/CyrilWaechter/pyRevitMEP/blob/master/LICENSE
"""
from revitutils import doc, selection

# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import Transaction, FamilySymbol

__doc__ = "Delete selected families from project"
__title__ = "Family delete"
__author__ = "Cyril Waechter"

t = Transaction(doc, "Delete families from project")
t.Start()

try:
# Find families of selected object and delete it
for el in selection.elements:
family_id = el.Symbol.Family.Id
doc.Delete(family_id)

except: # print a stack trace and error messages for debugging
import traceback
traceback.print_exc()
t.RollBack()

else:
t.Commit()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions pyRevitMEP.tab/Tools.panel/FamilyTypeDelete.pushbutton/script.py
@@ -0,0 +1,44 @@
"""
Copyright (c) 2017 Cyril Waechter
Python scripts for Autodesk Revit
This file is part of pyRevitMEP repository at https://github.com/CyrilWaechter/pyRevitMEP
pyRevitMEP is an extension for pyRevit. It contain free set of scripts for Autodesk Revit:
you can redistribute it and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/CyrilWaechter/pyRevitMEP/blob/master/LICENSE
"""

from revitutils import doc, selection

# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import Transaction, FamilySymbol

__doc__ = "Delete selected families from project"
__title__ = "Familytype delete"
__author__ = "Cyril Waechter"

t = Transaction(doc, "Delete families from project")
t.Start()

try:
# Find families of selected object and delete it
for el in selection.elements:
familytype_id = el.GetTypeId()
doc.Delete(familytype_id)

except: # print a stack trace and error messages for debugging
import traceback
traceback.print_exc()
t.RollBack()

else:
t.Commit()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions pyRevitMEP.tab/Tools.panel/ParameterDelete.pushbutton/script.py
@@ -0,0 +1,45 @@
"""
Copyright (c) 2017 Cyril Waechter
Python scripts for Autodesk Revit
This file is part of pyRevitMEP repository at https://github.com/CyrilWaechter/pyRevitMEP
pyRevitMEP is an extension for pyRevit. It contain free set of scripts for Autodesk Revit:
you can redistribute it and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/CyrilWaechter/pyRevitMEP/blob/master/LICENSE
"""

from revitutils import doc

# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import Transaction, FilteredElementCollector, ParameterElement

__doc__ = "Delete project parameters including hidden ones"
__title__ = "Project Parameter delete"
__author__ = "Cyril Waechter"

#Retrieve all parameters in the document
params = FilteredElementCollector(doc).OfClass(ParameterElement)
filteredparams = []

#Store parameters which has a name starting with "magi" or "MC"
for param in params:
if param.Name.startswith(("magi", "MC")): #startswith method accept tuple
filteredparams.append(param)
print param.Name

#Delete all parameters in the list
t = Transaction(doc, "Delete parameters")
t.Start()
for param in filteredparams:
doc.Delete(param.Id)
t.Commit()

4 changes: 2 additions & 2 deletions pyRevitMEP.tab/Tools.panel/SystemDelete.pushbutton/script.py
Expand Up @@ -2,7 +2,7 @@
Copyright (c) 2017 Cyril Waechter
Python scripts for Autodesk Revit
This file is part of pyRevitMEP repository at https://github.com/Nahouhak/pyRevitMEP
This file is part of pyRevitMEP repository at https://github.com/CyrilWaechter/pyRevitMEP
pyRevitMEP is an extension for pyRevit. It contain free set of scripts for Autodesk Revit:
you can redistribute it and/or modify it under the terms of the GNU General Public License
Expand All @@ -14,7 +14,7 @@
GNU General Public License for more details.
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/Nahouhak/pyRevitMEP/blob/master/LICENSE
https://github.com/CyrilWaechter/pyRevitMEP/blob/master/LICENSE
"""

from revitutils import doc, selection
Expand Down
4 changes: 2 additions & 2 deletions pyRevitMEP.tab/Tools.panel/ViewRename.pushbutton/script.py
Expand Up @@ -2,7 +2,7 @@
Copyright (c) 2017 Cyril Waechter
Python scripts for Autodesk Revit
This file is part of pyRevitMEP repository at https://github.com/Nahouhak/pyRevitMEP
This file is part of pyRevitMEP repository at https://github.com/CyrilWaechter/pyRevitMEP
pyRevitMEP is an extension for pyRevit. It contain free set of scripts for Autodesk Revit:
you can redistribute it and/or modify it under the terms of the GNU General Public License
Expand All @@ -14,7 +14,7 @@
GNU General Public License for more details.
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/Nahouhak/pyRevitMEP/blob/master/LICENSE
https://github.com/CyrilWaechter/pyRevitMEP/blob/master/LICENSE
"""
from revitutils import doc, selection

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions pyRevitMEP.tab/Tools.panel/ViewTypeCopy.pushbutton/script.py
@@ -0,0 +1,65 @@
"""
Copyright (c) 2017 Cyril Waechter
Python scripts for Autodesk Revit
This file is part of pyRevitMEP repository at https://github.com/CyrilWaechter/pyRevitMEP
pyRevitMEP is an extension for pyRevit. It contain free set of scripts for Autodesk Revit:
you can redistribute it and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/CyrilWaechter/pyRevitMEP/blob/master/LICENSE
"""
from revitutils import doc, selection

# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import Transaction, Element, BuiltInParameter
# noinspection PyUnresolvedReferences
from Autodesk.Revit import Exceptions

__doc__ = "Copy view types"
__title__ = "Copy view type"
__author__ = "Cyril Waechter"

try:
t = Transaction(doc, "Rename views")
t.Start()
for view in selection.elements: # Loop trough selected views
view_typeid = doc.GetElement(view.GetTypeId()) # Get ViewFamilyType Id
view_typename = Element.Name.GetValue(view_typeid) # Get ViewFamilyType Name

# Get Scope Box name if it exist
try:
view_scopebox = view.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP)
view_scopebox_name = "" if view_scopebox.Value() is None else "_" + view_scopebox.AsValueString()
except AttributeError:
view_scopebox_name = ""

# Get view reference level if it exist
view_genlevel = "" if view.GenLevel is None else view.GenLevel.Name

# Future view name
view_name = "{c}_{a}{b}".format(a=view_genlevel, b=view_scopebox_name, c=view_typename, )

# Rename view
i = 0
while True:
try:
view.Name = view_name if i == 0 else view_name + str(i)
except Exceptions.ArgumentException:
i += 1
except:
raise
else:
break
t.Commit()
except: # print a stack trace and error messages for debugging
import traceback
traceback.print_exc()
t.RollBack()
Empty file.
Empty file added pyRevitMEP.tab/__init__.py
Empty file.

0 comments on commit 83ac2f1

Please sign in to comment.