While loop for finding the appropriate surface area

Depending on the accuracy needs, you could make a python loop with a desired number of iterations (accuracy) that re-calcs the area from the offset. I prefer not to use a while loop. If you use it, cap it so that any mistakes (like briefly clicking away before finishing) will not freeze Dynamo.

Below is a sample, that can be really improved for speed:

  • can add a way to offset in either direction
  • can be optimized for speed (super rough logic…)

These settings are not too slow for this single surface example…

2022-03-22 - 20-01-46

Python Node Code

# EvolveLAB | https://www.evolvelab.io
# 2022-03-22

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# inputs
polyCurveOrig = IN[0][0]
targetArea = IN[1]
offsetStepDist = IN[2]

def areaOfPolyCurve(pCurve):
    area = Surface.ByPatch(pCurve).Area
    return area
    
# vars
polyCurveNew = polyCurveOrig
offsetDist = 0
newArea = areaOfPolyCurve(polyCurveOrig)

# assumes that original shape is larger than the target
for step in range(100): # 100 max tries
	if newArea < targetArea:
		offsetDist = offsetDist - offsetStepDist # undo last offset
		offsetStepDist = offsetStepDist / 2 # gradually increase the resoution if went over
	offsetDist = offsetDist + offsetStepDist
	polyCurveNew = Curve.Offset(polyCurveOrig, offsetDist)
	newArea = areaOfPolyCurve(polyCurveNew)

OUT = [offsetDist, newArea, polyCurveNew, step]
6 Likes