Another way if you want to copy the rectpack folder into a given directory:
import clr
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import os
os.system('python C:\rectpack-master\rectpack.py')
from rectpack import newPacker
rectangles = [(100, 30), (40, 60), (30, 30),(70, 70), (100, 50), (30, 30)]
bins = [(300, 450), (80, 40), (200, 150)]
packer = newPacker()
#Add the rectangles to packing queue
for r in rectangles:
packer.add_rect(*r)
#Add the bins where the rectangles will be placed
for b in bins:
packer.add_bin(*b)
#Start packing
packer.pack()
nbins = len(packer)
OUT= nbins
Since the backslash is used to escape characters that otherwise have a special function, putting r before the string indicates to read the backslash as backslash and not as escape command.
Is this being used to stack views on a sheet? Would be amazing to have rectangles (viewport length and width) in as a list with the script. Then an in for the bin (sheet). But then would need an output of the center point of the stacked rectangles. Could then use that information to put views on the sheet. Another obstacle is to output views that didn’t fit to go on another sheet. I don’t have the skills at python to achieve this but thought I’d put it out there if anyone’s keen to try
Any idea how to format things correctly to change it to taking a list? spent a few hours. Cannot figure out the arguments. Went from 27 down to 2 but need 3 or max 4. Been reading to try understand. Seems like I need “self” infront but I just don’t quite get it haha
Thanks Saeedy. I’ve used that but I’m really after something that works out where to place the views. Need the bin packing algorithm sorted to get the coordinates of where to place views to use that script from the link.