Skip to content

Commit

Permalink
Merge pull request #1872 from thumDer/feature/get-centroid
Browse files Browse the repository at this point in the history
config mode for Get Centroid
  • Loading branch information
jmcouffin authored Jul 18, 2023
2 parents 0e417ca + f8fd083 commit eec4276
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ title: Get Centroid
tooltip: >
Calculates the centroid of the selected elements geometry
and places three model lines intersecting at the centroid.
Config mode can be used to specify a Line Style that will
be used in the future as a default.
author: Tamás Déri
context: selection
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
from pyrevit import script, revit, DB, forms
from pyrevit import script, revit, DB, forms, EXEC_PARAMS
from Autodesk.Revit.Exceptions import InvalidOperationException

doc = revit.doc
Expand Down Expand Up @@ -46,6 +46,36 @@ def merge_solids(solids):
)
return union

cfg = script.get_config()
logger.debug('loaded config {}'.format(cfg))
line_category = doc.Settings.Categories.get_Item(DB.BuiltInCategory.OST_Lines)
line_subcategories = line_category.SubCategories
line_styles = [
lsc.GetGraphicsStyle(DB.GraphicsStyleType.Projection)
for lsc in line_subcategories
]
line_styles.sort(key=lambda x: x.Name)
logger.debug('got linestyles: {}'.format([ls.Name for ls in line_styles]))
try:
logger.debug('searching for line style {}'.format(cfg.line_style))
line_style = next(
(ls for ls in line_styles if ls.Name == cfg.line_style),
None
)
logger.debug('line style found')
except AttributeError:
logger.debug('no line style in config')
line_style = None
if EXEC_PARAMS.config_mode:
line_style = forms.SelectFromList.show(
line_styles,
name_attr='Name',
title='Select Line Style to be used'
)
if line_style:
cfg.line_style = line_style.Name
script.save_config()
logger.debug('saved selected line style to config')

selection = revit.get_selection()
if not selection:
Expand Down Expand Up @@ -97,12 +127,16 @@ def merge_solids(solids):
centroid + DB.XYZ.BasisZ
)

doc.Create.NewModelCurve(
l1 = doc.Create.NewModelCurve(
c1, sp1
)
doc.Create.NewModelCurve(
l2 = doc.Create.NewModelCurve(
c2, sp1
)
doc.Create.NewModelCurve(
l3 = doc.Create.NewModelCurve(
c3, sp2
)

if line_style:
for l in [l1, l2, l3]:
l.LineStyle = line_style

0 comments on commit eec4276

Please sign in to comment.