Skip to content

Commit

Permalink
004.Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
symonkipkemei committed Sep 19, 2023
1 parent 279d44b commit 4e3c77a
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 111 deletions.
4 changes: 4 additions & 0 deletions lib/_create/_errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ class RevealNotSelectedError(Exception):
# catch elements that are Null in value
class NoneError(Exception):
pass

# catches walls that are non-othogonal
class TransactionError(Exception):
pass
22 changes: 20 additions & 2 deletions lib/_create/_openings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from _create import _parts as g
from _create import _coordinate as c


from pyrevit import forms

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> VARIABLES
Expand All @@ -33,6 +32,25 @@
active_level = doc.ActiveView.GenLevel


# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GET WIDTH
def get_fenestration_width(fenestration_id):
"""
Establish the width of the window
:param fenestration_id: window/door id
:return: the width
"""
# establish the width of the window
fenestration = doc.GetElement(fenestration_id)
fenestration_type = fenestration.Symbol
width = fenestration_type.get_Parameter(BuiltInParameter.DOOR_WIDTH).AsDouble()

# interchangeably the width can be 0 but rough width has dimensions
if width == 0:
width = fenestration_type.get_Parameter(BuiltInParameter.FAMILY_ROUGH_WIDTH_PARAM).AsDouble()

return width


# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GET COORDINATES

def get_fenestration_xyz_centre(fenestration_id):
Expand Down Expand Up @@ -130,7 +148,7 @@ def get_fenestration_out_range(fenestration_left_index, fenestration_right_index

# window width
fenestration_width = fenestration_left_index - fenestration_right_index
displacement = cc.check_displacement_distance(displacement, fenestration_width)
displacement = check_displacement_distance(displacement, fenestration_width)

# window left edge
left_box_range_1 = fenestration_left_index - displacement
Expand Down
46 changes: 45 additions & 1 deletion lib/_create/_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def sort_parts_by_side(parts):
host_wall_id = get_host_wall_id(part)
host_wall_type_id = get_host_wall_type_id(host_wall_id)
layer_index = get_layer_index(part)
lap_type_id, side_of_wall, exterior = get_wallsweep_parameters(layer_index, host_wall_type_id)
lap_type_id, side_of_wall, exterior = get_wall_sweep_parameters(layer_index, host_wall_type_id)

if exterior == True:
exterior_parts.append(part)
Expand Down Expand Up @@ -446,3 +446,47 @@ def switch_directions(exterior, switch_direction=False):
exterior = exterior

return exterior


# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> HIGHLIGHT FUNCTIONS

def highlight_unpanelized_underpanelized_parts(__title__):
"""Color code unpanelized parts and underpanleized parts for ease of identification
:param __title__:
:return: graphics_settings_unpanelized, graphics_settings_underpanelized
"""

# select all parts
parts = select_all_parts()
exterior_parts, interior_parts = sort_parts_by_side(parts)
filtered_parts = exterior_parts + interior_parts
underpanalized, panelized, unpanelized = sort_parts_by_length(filtered_parts)

solid_fill_id = ElementId(20)

# color codes - unpanelized
graphics_settings_unpanelized = OverrideGraphicSettings()
graphics_settings_unpanelized.SetSurfaceForegroundPatternId(solid_fill_id)
clr_bytes_a = [255, 99, 71]
color_unpanelized_a = Color(clr_bytes_a[0], clr_bytes_a[1], clr_bytes_a[2])
graphics_settings_unpanelized.SetSurfaceForegroundPatternColor(color_unpanelized_a)

# color codes - underpanelized
graphics_settings_underpanelized = OverrideGraphicSettings()
graphics_settings_underpanelized.SetSurfaceForegroundPatternId(solid_fill_id)
clr_bytes_b = [251, 191, 0]
color_underpanelized_b = Color(clr_bytes_b[0], clr_bytes_b[1], clr_bytes_b[2])
graphics_settings_underpanelized.SetSurfaceForegroundPatternColor(color_underpanelized_b)

with Transaction(doc, __title__) as t:
t.Start()
if len(unpanelized) != 0:
for part in unpanelized:
active_view.SetElementOverrides(part.Id, graphics_settings_unpanelized)
if len(underpanalized) != 0:
for part in underpanalized:
active_view.SetElementOverrides(part.Id, graphics_settings_underpanelized)

t.Commit()

return graphics_settings_unpanelized, graphics_settings_underpanelized
29 changes: 16 additions & 13 deletions panelization.tab/panelize.panel/AutoParts.pushbutton/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
clr.AddReference("System")
from _create import _transactions as a
from _create import _parts as g
from _create import _checks as cc
from _create import _forms as f
from _create import _errorhandler as eh
from _create import _forms as f
from _create import _errorhandler as eh
from pyrevit import forms
# VARIABLES
################################################################################################################################

Expand All @@ -44,19 +44,22 @@ def main():

exterior_parts, interior_parts = g.sort_parts_by_side(selected_parts)
all_parts = exterior_parts + interior_parts
#all_parts = cc.check_if_host_wall_edited(all_parts)
underpanelized, panalized, non_panelized_parts = g.sort_parts_by_length(all_parts)
switch_option = f.switch_option()
displacement_distance = f.displacement_distance_form()
for part in non_panelized_parts:
try:
a.auto_parts(__title__, part, displacement_distance, switch_option, multiple=True)
except Exception:
pass

g.highlight_unpanelized_underpanelized_parts(__title__)
if len(non_panelized_parts) != 0:
switch_option = f.switch_option()
displacement_distance = f.displacement_distance_form()
for part in non_panelized_parts:
try:
a.auto_parts(__title__, part, displacement_distance, switch_option, multiple=True)
except Exception:
pass

g.highlight_unpanelized_underpanelized_parts(__title__)

else:
forms.alert("There are no non-panelized parts")


if __name__ == "__main__":
# print(get_part_length(496067))
main()
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def main():
forms.alert("Centre Index could not be established")
except eh.VariableDistanceNotFoundError:
forms.alert("The variable distance could not be established")
except eh.TransactionError:
forms.alert("Transaction Error occurred")

except Exception:
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ def main():
except eh.VariableDistanceNotFoundError:
forms.alert("The variable distance could not be established")

#except Exception:
#forms.alert("Error occurred.Could not panelize")
except eh.TransactionError:
forms.alert("Transaction Error occurred")

except Exception:
forms.alert("Error occurred.Could not panelize selected Part.")



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def main():
lap_type_id, side_of_wall, exterior = p.get_wall_sweep_parameters(layer_index, host_wall_type_id)

reveal_plane_coordinate_0 = t.get_reveal_coordinate_at_0(__title__, part)
distance = p.get_part_centre_index(part, reveal_plane_coordinate_0)
centre_index = p.get_part_centre_index(part, reveal_plane_coordinate_0)

t.auto_place_reveal(__title__, host_wall_id, lap_type_id, distance, side_of_wall)
t.auto_place_reveal(__title__, host_wall_id, lap_type_id, centre_index, side_of_wall)

except eh.VariableDistanceNotFoundError:
forms.alert("The variable distance could not be established")
Expand Down
26 changes: 26 additions & 0 deletions panelization.tab/select.panel/Reveals.pushbutton/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def AllowReference(self, refer, point):

# select a reveal
def select_reveal():
"""
Selects a reveal
:return:
"""
reveal_filter = RevealSelectionFilter()
reference = uidoc.Selection.PickObject(ObjectType.Element, reveal_filter)
reveal = uidoc.Document.GetElement(reference)
Expand All @@ -70,12 +74,22 @@ def select_reveal():


def get_wall_side(reveal):
"""
Determine the wall side of the reveal
:param reveal: reveal
:return: wall side
"""
wall_sweep_info = reveal.GetWallSweepInfo()
wall_side = wall_sweep_info.WallSide
return wall_side


def get_host_wall_id(reveal):
"""
Abstract the host wall id of a selected reveal
:param reveal: Reveal
:return: host wall Element Id
"""
host_ids = reveal.GetHostIds()
host_id = host_ids[0]

Expand All @@ -86,13 +100,24 @@ def get_host_wall_id(reveal):


def select_all_reveals():
"""
Select all reveals in a project
:return:
"""
all_reveals = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Reveals). \
WhereElementIsNotElementType().ToElements()

return all_reveals


def get_filtered_reveals(reference_host_id, reference_wall_side, all_reveals):
"""
Filter reveals based on the host wall and the wall side
:param reference_host_id:
:param reference_wall_side:
:param all_reveals:
:return:
"""
filtered_reveals = []
for reveal in all_reveals:
wall_side = get_wall_side(reveal)
Expand All @@ -105,6 +130,7 @@ def get_filtered_reveals(reference_host_id, reference_wall_side, all_reveals):


def display_selected_reveals(filtered_reveals):
"""Display all selected reveals"""
uidoc.Selection.SetElementIds(filtered_reveals)


Expand Down
15 changes: 14 additions & 1 deletion panelization.tab/takeoff.panel/Panelized.pushbutton/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@


def get_parts_data(filtered_parts):
"""Abstract parts data : height,length, thickness, volume, base level and area"""
parts_data = {}

for part in filtered_parts:
Expand All @@ -66,6 +67,11 @@ def get_parts_data(filtered_parts):


def get_parts_type_data(parts_data):
"""Aggregate parts data of similar length and height
:param parts_data:
:return:
"""

data = {}
for part_data in parts_data.values(): # the default type
default_part_type = part_data[0]
Expand All @@ -82,6 +88,7 @@ def get_parts_type_data(parts_data):


def get_summary_data(parts_data, parts_type_data, cost_per_sf):
"""Sum up parts data into total panels, area and cost"""
final_data = []
sum_panels = 0
sum_area = 0
Expand All @@ -108,6 +115,12 @@ def get_summary_data(parts_data, parts_type_data, cost_per_sf):


def user_filters_part_type(exterior_parts,interior_parts):
"""
Alllow user to select which parts to be filtered.
:param exterior_parts: interior parts
:param interior_parts: exterior parts
:return: selected parts , user choice
"""
# user selects which parts for take off

ops = ['External Parts', 'Internal Parts', 'External and Internal Parts']
Expand Down Expand Up @@ -158,7 +171,7 @@ def main():
forms.alert("Highlighted parts (red) have not been panelized")

else:
forms.alert("Congratualtions! All parts have been panelized")
forms.alert("CongratuLations! All parts have been panelized")


else:
Expand Down
30 changes: 20 additions & 10 deletions panelization.tab/takeoff.panel/Unpanelized.pushbutton/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
from Autodesk.Revit.DB import View
from _create import _transactions as a
from _create import _parts as g

from _create import _forms as f
from _create import _checks as c
from pyrevit import forms
import clr

Expand All @@ -47,6 +45,10 @@
# check if a panel is less than 4' and filtered, remove filter

def get_unpanelized_parts():
"""
Select all parts and filter to unpanelized parts
:return: unpanelized parts
"""
# select interior and exterior parts
parts = g.select_all_parts()
exterior_parts, interior_parts = g.sort_parts_by_side(parts)
Expand All @@ -62,33 +64,41 @@ def get_unpanelized_parts():


def get_unpanalized_parts_data(unpanelized_parts):
"""Abstract unpanelized parts data from the model"""
parts_data = []
count = 0

for part in unpanelized_parts:
count += 1
part_id = part.Id
height = part.get_Parameter(BuiltInParameter.DPART_HEIGHT_COMPUTED).AsValueString()
length = part.get_Parameter(BuiltInParameter.DPART_LENGTH_COMPUTED).AsValueString()
base_level = part.get_Parameter(BuiltInParameter.DPART_BASE_LEVEL).AsDouble()

data = [part_id, height, length, base_level]
data = [count, part_id, height, length, base_level]

parts_data.append(data)
return parts_data





def main():
parts = get_unpanelized_parts()
parts_data = get_unpanalized_parts_data(parts)
if len(parts) != 0:
parts_data = get_unpanalized_parts_data(parts)

g.highlight_unpanelized_underpanelized_parts(__title__)

# display panels data
header = ["COUNT", "PART ID", "HEIGHT(F)", "LENGTH(F)", "BASE LEVEL"]

f.display_form(parts_data, header, "Unpanelized parts", last_line_color='color:blue;')

g.highlight_unpanelized_underpanelized_parts(__title__)
else:
forms.alert("Congratulations! All parts have been panelized")

# display panels data
header = ["PART ID", "HEIGHT(F)", "LENGTH(F)", "BASE LEVEL"]

f.display_form(parts_data, header, "Unpanelized parts", last_line_color='color:blue;')



if __name__ == "__main__":
Expand Down
Binary file removed panelization.tab/test.panel/test.pushbutton/icon.png
Binary file not shown.
Loading

0 comments on commit 4e3c77a

Please sign in to comment.