Offset a rectangle in negative direction

Hi All,

I can offset a rectangle in positive direction or outer but not in negative direction or inner

what’s wrong in my code below?

import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
Rectangle = IN[0]
lst_offset = IN[1]

lst_1 = []
lst_2 = []
#Offset in positive direction
"""for d in lst_offset:
    lst_1.append(Rectangle.Offset(d))"""
    
#Offset in negative direction
for d in lst_offset:
    a = -d
    lst_2.append(Rectangle.Offset(a))
    
OUT = lst_2

Thanks.

A rectangle 16 units long and wide can only be offset inwards by 8-1/infinity units before it collapses into a point, as you are offsetting the left and right 1 unit towards each other concurrently, so offsetting by 1 gives you dimensions of 14, by two 12, by four 8, by seven 2, and offsetting by 8 gives zero which is no longer a valid polycurve.

Adjust your starting rectangle to something larger than 20 units and check the code again, or reduce to offset to maximum (1/2 of the width -1/infinity). You could also add some error handling to remove any values greater than or equal to 1/2 of the width or length.

Also seeing the warning message can help with resolving/diagnosing these types of issues in the future.

2 Likes

@jacob.small

Oh my bad!! I put 1 instead 0.1 for step in my range and it’s logical what you said, I can’t get all my rectangles below some limit dimensions

Thanks.

1 Like