The next piece of code by @kennyb6 works on whole numbers, i’m trying to adapt it to make it work with decimal numbers to. Python Dimension.Below = calculated value based on actual Dimension value(Maths)
at first i thought it wasnt possible, but now i got a ‘breakthrough’
the piece of code that i have works on a single string. and i want to adapt it to work with multiple dim values like the piece of code @kennyb6 wrote.
see attachments and code below.
Actual code that works:
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Functions
def getForm(dim, brick, brickN, seam, seamN):
val = round(dim.Value * ftmm)
x = str(int(round(val / brick)))
if val % brick == seam:
form = x + brickN + " + " + seamN
elif val % brick == brick - seam:
form = x + brickN + " - " + seamN
elif val % brick == 0:
form = x + brickN
else:
form = str(int(val // brick)) + brickN + " + R"
dim.Below = form
return form
# The inputs to this node will be stored as a list in the IN variables.
allDims = UnwrapElement(IN[0])
brick = IN[1]
seam = IN[2]
brickN = IN[3]
seamN = IN[4]
ftmm = 304.8
forms = []
TransactionManager.Instance.EnsureInTransaction(doc)
for dims in allDims:
if dims.Value == None:
form = []
for dim in dims.Segments:
form.append(getForm(dim, brick, brickN, seam, seamN))
forms.append(form)
else:
form = []
form.append(getForm(dims, brick, brickN, seam, seamN))
forms.append(form)
TransactionManager.Instance.TransactionTaskDone()
OUT = forms
The piece of code that i m trying to adapt:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import decimal
from decimal import *
getcontext().rounding = ROUND_HALF_UP
getcontext().prec = 12
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
bS = IN[0]
brick = IN[1]
tolerance = IN[2]
dimValue = IN[3]
D = decimal.Decimal
seam = str(D(bS) - D(brick))
bsLow = str(D(bS) - D(tolerance))
bsHigh = str(D(bS) + D(tolerance))
brickLow = str(D(brick) - D(tolerance))
brickHigh = str(D(brick) + D(tolerance))
seamLow = str(D(seam) - D(tolerance))
seamHigh = str(D(seam) + D(tolerance))
toleranceLow = str( 0 - D(tolerance))
toleranceHigh = str(D(tolerance))
strVoeg = ''
km_in_maat = str(int(D(dimValue) / D(bS))) # aantal bS
rest = str(D(dimValue) % D(bS))
if D(bsLow) <= D(rest) <= D(bsHigh):
km_in_maat = str(D(km_in_maat) + 1)
strVoeg = km_in_maat + 'K'
elif D(brickLow) <= D(rest) <= D(brickHigh):
km_in_maat = str(D(km_in_maat) + 1)
strVoeg = km_in_maat + 'K-V'
elif D(seamLow) <= D(rest) <= D(seamHigh):
if km_in_maat == '0':
strVoeg = 'R' # 0K+V >>> R
else:
strVoeg = km_in_maat + 'K+V'
else:
if km_in_maat == '0':
strVoeg = 'R'
elif D(toleranceLow) <= D(rest) <= D(toleranceHigh):
strVoeg = km_in_maat + 'K'
else:
strVoeg = km_in_maat + 'K+R'
OUT = strVoeg
Currently i m feeding it a single string. it needs some changes to work with dim values i think, i just dont know what to change. any help is greatly appreciated!