Skip to content

Commit 74360b2

Browse files
authored
Merge pull request #4 from romangolev/dev
fix: convert double value when filling data back in double fix 'Section for Wall' button and show remote version in info
2 parents 1e893d5 + db3bde9 commit 74360b2

File tree

6 files changed

+42
-63
lines changed

6 files changed

+42
-63
lines changed

lib/core/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
# extension library file
22

3-
import os
4-
import sys
53
import os.path as op
64
import urllib2
7-
import selectionhelpers
85

96
from pyrevit import EXEC_PARAMS
107
from pyrevit import script
11-
from pyrevit import forms
128
from pyrevit.loader import sessionmgr
139
from pyrevit.loader import sessioninfo
1410

15-
class Core :
11+
class Core(object):
1612
"""
1713
Extension Coreclass
1814
"""
@@ -22,8 +18,6 @@ def return_ext_dir():
2218
return A_EXT_DIR
2319

2420

25-
26-
2721
def get_local_version():
2822
with open(op.join(op.dirname(__file__), 'version'), 'r') as version_file:
2923
version = version_file.read()

lib/core/unitsconverter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class UnitConverter:
1111

1212
@staticmethod
13-
def convertDouble(uiapp, doubleValue,units):
13+
def convertDouble(uiapp, doubleValue, units):
1414

1515
versionNumber = uiapp.Application.VersionNumber
1616
value_converted = ''

lib/core/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.2
1+
1.1.3

pyArchitect.tab/Main.panel/Info.pushbutton/info-script.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@
1212

1313
__context__ = 'zero-doc'
1414

15+
try:
16+
remote_version = core.get_git_version()
17+
except:
18+
remote_version = 'Not available'
19+
1520
# Handle Language versions
1621
if HOST_APP.language == LanguageType.Russian:
1722
user = "Имя пользователя"
1823
Rvers = "Версия Ревит"
19-
Bvers = "Версия расширения"
24+
Bvers = "Версия установленного расширения"
25+
Bvers_remote = "Последняя доступная версия"
2026
lang = "RU"
2127
else:
2228
user = "Username"
2329
Rvers = "Revit Version"
2430
Bvers = "Extension version"
31+
Bvers_remote = "Latest available version"
2532
lang = "EN"
2633
dir_path = op.dirname(op.realpath(__file__))
2734
style = 'img {max-width: 589px; padding: 25px 0} span {display: block; text-align: center;}'
@@ -36,6 +43,7 @@
3643
print(str(Rvers) + ' : {}'.format(HOST_APP.version_name + HOST_APP.build))
3744
print(str(Rvers) + ' : {}'.format(HOST_APP.subversion))
3845
print(str(Bvers) + ' : {}'.format(core.get_local_version()))
46+
print(str(Bvers_remote) + ' : {}'.format(remote_version))
3947

40-
out.print_html('<a href="https://github.com/romangolev/pyArchitect">pyArchitect repository</a>')
41-
out.print_html('<a href="https://www.romangolev.com">Roman Golev</a>')
48+
out.print_html('<a href="https://github.com/romangolev/pyArchitect">pyArchitect GitHub repository</a>')
49+
out.print_html('<a href="https://www.romangolev.com">Roman Golev</a><a> </a><a href="https://www.linkedin.com/in/romangolev/">LinkedIn</a><a>, 2024</a>')

pyArchitect.tab/Tools.panel/CopyParameterValues.pushbutton/script.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,16 @@ def runLogic(self):
213213
return "Error"
214214
elif storageTypeFrom == StorageType.Double:
215215
if self.param_to.StorageType == StorageType.Integer:
216-
try:
216+
try:
217217
value_converted = UnitConverter.convertDouble(uiapp, value, units)
218218
self.setValueTo(round(value_converted))
219219
return "Success"
220220
except:
221221
return "Skipped"
222222
elif self.param_to.StorageType == StorageType.Double:
223223
try:
224-
self.setValueTo(value)
224+
value_converted = UnitConverter.convertDouble(uiapp, value, units)
225+
self.setValueTo(round(value_converted))
225226
return "Success"
226227
except:
227228
return "Skipped"

pyArchitect.tab/Tools.panel/tools1.stack/CreateSectionBasedOnWall.pushbutton/script.py

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,20 @@
22
# pylint: skip-file
33
# by Roman Golev
44

5-
6-
7-
#Load Revit API
8-
import clr
9-
clr.AddReference("RevitAPI")
10-
import Autodesk
11-
from Autodesk.Revit.DB import *
12-
from Autodesk.Revit.UI import *
13-
145
import sys
6+
import Autodesk.Revit.DB as DB
7+
from Autodesk.Revit.DB import BuiltInParameter, XYZ, Transform, BoundingBoxXYZ, \
8+
ViewSection, ViewFamilyType, FilteredElementCollector, \
9+
ViewFamily
1510

16-
import pyrevit
1711
from pyrevit import forms
1812
from core.selectionhelpers import CustomISelectionFilterByIdInclude, ID_WALLS
1913
from Autodesk.Revit.UI.Selection import ObjectType
2014

21-
doc = __revit__.ActiveUIDocument.Document
22-
uidoc = __revit__.ActiveUIDocument
23-
uiapp = __revit__
24-
app = uiapp.Application
25-
t = Autodesk.Revit.DB.Transaction(doc)
26-
tg = Autodesk.Revit.DB.TransactionGroup(doc)
27-
28-
15+
doc = __revit__.ActiveUIDocument.Document # type: ignore
16+
uidoc = __revit__.ActiveUIDocument # type: ignore
17+
transaction = DB.Transaction(doc)
18+
transaction_group = DB.TransactionGroup(doc)
2919

3020
# Get unput: selected by user elements
3121
def get_selection():
@@ -40,8 +30,8 @@ def get_selection():
4030
return selection
4131

4232

43-
def create_section_by_wall(el, doc, viewFamilyTypeId, t, flip):
44-
offset = units(100)
33+
def create_section_by_wall(el, doc, viewFamilyTypeId, transaction, flip):
34+
offset = 100/304.8 # 100mm offset as Double
4535
wall = doc.GetElement(el)
4636
# Determine section box
4737
lc = wall.Location
@@ -61,11 +51,8 @@ def create_section_by_wall(el, doc, viewFamilyTypeId, t, flip):
6151
w = v.GetLength()
6252
h = maxZ - minZ
6353
d = wall.WallType.Width
64-
# wallBaseOffset = units(float(wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsString()))
65-
# wallUnconnectedHeight = units(float(wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsString()))
66-
wallBaseOffset = builtInParam(wall, BuiltInParameter.WALL_BASE_OFFSET)
67-
wallUnconnectedHeight = builtInParam(wall, BuiltInParameter.WALL_USER_HEIGHT_PARAM)
68-
54+
wallBaseOffset = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble()
55+
wallUnconnectedHeight = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble()
6956

7057
# XYZ(min/max section line length, min/max height of the section box, min/max far clip)
7158
min = XYZ(-0.5*w - offset, wallBaseOffset - offset, - offset - 0.5*d)
@@ -95,35 +82,25 @@ def create_section_by_wall(el, doc, viewFamilyTypeId, t, flip):
9582
sectionBox.Min = min # scope box bottom
9683
sectionBox.Max = max # scope box top
9784

98-
t.Start('Create Section')
9985
# Create wall section view
100-
newSection = ViewSection.CreateSection(doc, viewFamilyTypeId, sectionBox)
101-
t.Commit()
102-
return newSection
103-
104-
105-
def units(mmToFeets):
86+
transaction.Start('Create Section')
10687
try:
107-
# R19, R20, R21
108-
dut = DisplayUnitType.DUT_MILLIMETERS
109-
return UnitUtils.ConvertToInternalUnits(mmToFeets, dut)
110-
except:
111-
# R22, R22, R23 and later
112-
return mmToFeets/304.8
113-
88+
newSection = ViewSection.CreateSection(doc, viewFamilyTypeId, sectionBox)
89+
transaction.Commit()
90+
return newSection
91+
except Exception as e:
92+
transaction.RollBack()
93+
transaction.Dispose()
94+
print(e)
11495

11596

116-
def builtInParam(wall, wallParam):
117-
return units(float(wall.get_Parameter(wallParam).AsValueString()))
118-
11997
def main():
12098
# Get selection
121-
# sel = uidoc.Selection.GetElementIds()
12299
sel = get_selection()
123100

124101
# Check selected elements
125102
if not sel:
126-
forms.alert("Please, select wall","Section For Wall")
103+
forms.alert("Please, select wall", "Section For Wall")
127104
sys.exit()
128105
for element in sel:
129106
if doc.GetElement(element).Category.Id.ToString() != "-2000011":
@@ -157,13 +134,12 @@ def main():
157134

158135
#Make section(s)
159136
if len(sel) == 1:
160-
create_section_by_wall(sel[0], doc, viewFamilyTypeId, t, sw["Flip section"])
137+
create_section_by_wall(sel[0], doc, viewFamilyTypeId, transaction, sw["Flip section"])
161138
elif len(sel) > 1:
162-
tg.Start("Create multiple sections")
139+
transaction_group.Start("Create multiple sections")
163140
for el in sel:
164-
create_section_by_wall(el, doc, viewFamilyTypeId, t, sw["Flip section"])
165-
tg.Assimilate()
166-
141+
create_section_by_wall(el, doc, viewFamilyTypeId, transaction, sw["Flip section"])
142+
transaction_group.Assimilate()
167143

168144
if __name__ == '__main__':
169145
main()

0 commit comments

Comments
 (0)