I have follwoing code:
for i:=0 to num_stripes by 1
R := Row1 + 5*i
gen_rectangle1(TransStripe, R,Column1,R+4, Column2)
intersection(TransStripe, LabelSelcted, RegionIntersection)
smallest_rectangle1(RegionIntersection, dummy, BeginCol, dummy, EndCol)
inizio := BeginCol - 5
fine := EndCol + 5
area_center(RegionIntersection, dummy, centro_row, centro_col)
gen_rectangle1(Str, R, inizio, R+4, fine)
dev_set_color('red')
dev_display(Str)
endfor
In the last few lines, I create a rectangle named Str
. Is there a way to create names on the fly, so that i have a variable for each rectangle? Str1, Str2 ...
Unfortunately, there isn't a direct way to do this. There are a few workarounds:
Concatenating objects:
gen_empty_obj (EmptyObject)
for Index := 1 to 5 by 1
gen_rectangle1 (Rectangle, 30, 20, 100, 200*Index)
concat_obj (EmptyObject, Rectangle, EmptyObject)
endfor
** Selecting
select_obj (EmptyObject, ObjectSelected, 3)
Using vectors (Halcon 12+ version required)
for Index := 0 to 4 by 1
gen_rectangle1 (Rectangle.at(Index), 30, 20, 100, 200*(Index+1))
endfor
** Selecting
Object := Rectangle.at(2)
It is also possible to use vectors as structures and adding multiple levels, where one level would be the names and other objects or values. If you'd like to read more about it, I wrote an article: https://subpixel.hr/halcon-is-like-a-box-of-chocolates/