Geo Pattern: Difference between revisions

From Macros Wiki
Jump to navigationJump to search
ConnerO (talk | contribs)
No edit summary
ConnerO (talk | contribs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
! create a contour and then copy it<br>
! across a rectangular grid<br>
!<br>
! show use of geometry selection lists<br>
<br>
a1$ = "This macro will create a shape and"<br>
a2$ = "then copy it across a rectangular grid"<br>
a3$ = "It will use 2 dialogs, one for the shape"<br>
a4$ = "data and another for the pattern data"<br>
a5$ = "After creating the geomtry, it will select"<br>
a6$ = "the individual parts, rows and columns"<br>
<br>
message "%a1$\n%a2$\n\n%a3$\n%a4$\n\n%a5$\n%a6$"<br>
<br>
dialog "[[GeoPattern_Part.dlg]]"<br>
<br>
<nowiki>:</nowiki>get_repeats<br>
dialog "[[GeoPattern_Repeats.dlg]]"<br>
<br>
! data from Part dialog<br>
<br>
! l1 = long length<br>
! l2 = short length<br>
! h1 = long height<br>
! h2 = short height<br>
! r1 = large fillet<br>
! r2 = small fillet<br>
<br>
! data from Repeats dialog<br>
<br>
! xs = x start<br>
! ys = y start<br>
! dx = x spacing<br>
! dy = y spacing<br>
! nx = number in x<br>
! ny = number in y<br>
<br>
if nx<2 then message "Invalid number of parts in X (2 to 5)"<br>
if nx<2 then goto get_repeats<br>
<br>
if nx>5 then message "Invalid number of parts in X (2 to 5)"<br>
if nx>5 then goto get_repeats<br>
<br>
if ny<2 then message "Invalid number of parts in Y (2 to 4)"<br>
if ny<2 then goto get_repeats<br>
<br>
if ny>4 then message "Invalid number of parts in Y (2 to 4)"<br>
if ny>4 then goto get_repeats<br>
<br>
<br>
! start a new part and set the stock size<br>
! ---------------------------------------<br>
<br>
new_part "Example.vnc"<br>
set_part_data mdd_name, "VMill3a"  ! 3 axis vertical mill<br>
set_part_data units, 1              ! inches<br>
<br>
! set the stock size<br>
! ------------------<br>
<br>
set_part_data stock_x1, xs<br>
set_part_data stock_y1, ys<br>
set_part_data stock_z1, 0<br>
set_part_data stock_x2, xs+dx*(nx-1)+l1<br>
set_part_data stock_y2, ys+dy*(ny-1)+h1<br>
set_part_data stock_z2, 1<br>
<br>
set_view top<br>
zoom_view 0<br>
<br>
message "Create one shape, starting at X 0, Y 0", "Geo pattern", 1<br>
<br>
contour [<br>
start r1,    0<br>
line  l1-r1, 0<br>
arc  l1-r1, r1,    l1,    r1,    ccw<br>
line  l1,    h2-r2<br>
arc  l1-r2, h2-r2, l1-r2, h2,    ccw<br>
line  l2+r2, h2<br>
arc  l2+r2, h2+r2, l2,    h2+r2, cw<br>
line  l2,    h1-r2<br>
arc  l2-r2, h1-r2, l2-r2, h1,    ccw<br>
line  r1,    h1<br>
arc  r1,    h1-r1, 0,    h1-r1, ccw<br>
line  0,    r1<br>
arc  r1,    r1,    r1,    0,      ccw<br>
]<br>
{|
{|
|iref=ContourRef ||            ! reference number for the contour
|!&nbsp;&nbsp;&nbsp; create a contour and then copy it
|-
|-
|clear_select    ||             ! make sure nothing is selected
|!&nbsp;&nbsp;&nbsp; across a rectangular grid
|-
|!&nbsp;&nbsp;&nbsp;
|-
|!&nbsp;&nbsp;&nbsp; show use of geometry selection lists
|-
|
|-
|a1$ = "This macro will create a shape and"
|-
|a2$ = "then copy it across a rectangular grid"
|-
|a3$ = "It will use 2 dialogs, one for the shape"
|-
|a4$ = "data and another for the pattern data"
|-
|a5$ = "After creating the geomtry, it will select"
|-
|a6$ = "the individual parts, rows and columns"
|-
|
|-
|message "%a1$\n%a2$\n\n%a3$\n%a4$\n\n%a5$\n%a6$"
|-
|
|-
|dialog "[[GeoPattern_Part.dlg]]"
|-
|
|-
|<nowiki>:</nowiki>get_repeats
|-
|dialog "[[GeoPattern_Repeats.dlg]]"
|-
|
|-
|!&nbsp;&nbsp;&nbsp; data from Part dialog
|-
|
|-
|!&nbsp;&nbsp;&nbsp; l1 = long length
|-
|!&nbsp;&nbsp;&nbsp; l2 = short length
|-
|!&nbsp;&nbsp;&nbsp; h1 = long height
|-
|!&nbsp;&nbsp;&nbsp; h2 = short height
|-
|!&nbsp;&nbsp;&nbsp; r1 = large fillet
|-
|!&nbsp;&nbsp;&nbsp; r2 = small fillet
|-
|-
|select_shape iref ||          ! select the shape we just created
|
|
|get_selection_list 1    ||     ! save list of currently selected geometry
|-
|!&nbsp;&nbsp;&nbsp; data from Repeats dialog
|-
|
|
|-
|!&nbsp;&nbsp;&nbsp; xs = x start
|-
|!&nbsp;&nbsp;&nbsp; ys = y start
|-
|!&nbsp;&nbsp;&nbsp; dx = x spacing
|-
|!&nbsp;&nbsp;&nbsp; dy = y spacing
|-
|!&nbsp;&nbsp;&nbsp; nx = number in x
|-
|!&nbsp;&nbsp;&nbsp; ny = number in y
|-
|&nbsp;&nbsp;&nbsp;
|-
|if nx<2 then message "Invalid number of parts in X (2 to 5)"
|-
|if nx<2 then goto get_repeats
|-
|&nbsp;&nbsp;&nbsp;
|-
|if nx>5 then message "Invalid number of parts in X (2 to 5)"
|-
|if nx>5 then goto get_repeats
|-
|&nbsp;&nbsp;&nbsp;
|-
|if ny<2 then message "Invalid number of parts in Y (2 to 4)"
|-
|if ny<2 then goto get_repeats
|-
|&nbsp;&nbsp;&nbsp;
|-
|if ny>4 then message "Invalid number of parts in Y (2 to 4)"
|-
|if ny>4 then goto get_repeats
|-
|&nbsp;&nbsp;&nbsp;
|-
|&nbsp;&nbsp;&nbsp;
|-
|!&nbsp;&nbsp;&nbsp; start a new part and set the stock size
|-
|!&nbsp;&nbsp;&nbsp; ---------------------------------------
|-
|&nbsp;&nbsp;&nbsp;
|-
|new_part "Example.vnc"
|-
|set_part_data mdd_name, "VMill3a"  !&nbsp;&nbsp;&nbsp; 3 axis vertical mill
|-
|set_part_data units, 1              !&nbsp;&nbsp;&nbsp; inches
|-
|&nbsp;&nbsp;&nbsp;
|-
|!&nbsp;&nbsp;&nbsp; set the stock size
|-
|!&nbsp;&nbsp;&nbsp; ------------------
|-
|&nbsp;&nbsp;&nbsp;
|-
|set_part_data stock_x1, xs
|-
|set_part_data stock_y1, ys
|-
|set_part_data stock_z1, 0
|-
|set_part_data stock_x2, xs+dx*(nx-1)+l1
|-
|set_part_data stock_y2, ys+dy*(ny-1)+h1
|-
|set_part_data stock_z2, 1
|-
|&nbsp;&nbsp;&nbsp;
|-
|set_view top
|-
|zoom_view 0
|-
|&nbsp;&nbsp;&nbsp;
|-
|message "Create one shape, starting at X 0, Y 0", "Geo pattern", 1
|-
|&nbsp;&nbsp;&nbsp;
|-
|contour [
|-
|start r1,    0
|-
|line  l1-r1, 0
|-
|arc  l1-r1, r1,    l1,    r1,    ccw
|-
|line  l1,    h2-r2
|-
|arc  l1-r2, h2-r2, l1-r2, h2,    ccw
|-
|line  l2+r2, h2
|-
|arc  l2+r2, h2+r2, l2,    h2+r2, cw
|-
|line  l2,    h1-r2
|-
|arc  l2-r2, h1-r2, l2-r2, h1,    ccw
|-
|line  r1,    h1
|-
|arc  r1,    h1-r1, 0,    h1-r1, ccw
|-
|line  0,    r1
|-
|arc  r1,    r1,    r1,    0,      ccw
|-
|]
|-
|&nbsp;&nbsp;&nbsp;
|-
|iref=ContourRef ||            !&nbsp;&nbsp;&nbsp; reference number for the contour
|-
|clear_select    ||            !&nbsp;&nbsp;&nbsp; make sure nothing is selected
|-
|select_shape iref ||          !&nbsp;&nbsp;&nbsp; select the shape we just created
|-
|get_selection_list 1    ||    !&nbsp;&nbsp;&nbsp; save list of currently selected geometry
|-
|redraw
|redraw
|-
|-
|message "Move to start position", "Geo pattern", 1
|message "Move to start position", "Geo pattern", 1
|-
|-
|translate_geo xs,ys    ||    !&nbsp;&nbsp;&nbsp; translate it to the start position
|-
|&nbsp;&nbsp;&nbsp;
|-
|redraw
|-
|&nbsp;&nbsp;&nbsp;
|-
|message "Copy Horizontally", "Geo pattern", 1
|-
|&nbsp;&nbsp;&nbsp;
|-
|translate_geo dx,0,0,(nx-1)  ! translate and copy
|-
|redraw
|-
|&nbsp;&nbsp;&nbsp;
|-
|message "Copy Vertically", "Geo pattern", 1
|-
|!&nbsp;&nbsp;&nbsp; after the translate and copy
|-
|!&nbsp;&nbsp;&nbsp; just the copies will be selected
|-
|get_selection_list 2    ||    !&nbsp;&nbsp;&nbsp; save list of currently selected geometry
|-
|select_shape iref      ||    !&nbsp;&nbsp;&nbsp; reselect the original shape
|-
|translate_geo 0,dy,0,(ny-1)||  !&nbsp;&nbsp;&nbsp; translate the whole row in Y
|-
|redraw
|-
|&nbsp;&nbsp;&nbsp;
|-
|get_selection_list 3    ||    !&nbsp;&nbsp;&nbsp; save list of currently selected geometry
|-
|&nbsp;&nbsp;&nbsp;
|-
|&nbsp;&nbsp;&nbsp;
|-
|message "Select the original shape", "Geo pattern", 1
|-
|set_selection_list 1
|-
|redraw
|-
|&nbsp;&nbsp;&nbsp;
|-
|message "Select the copies in X", "Geo pattern", 1
|-
|set_selection_list 2
|-
|redraw
|-
|&nbsp;&nbsp;&nbsp;
|-
|message "Select the copies in Y", "Geo pattern", 1
|-
|set_selection_list 3
|-
|redraw
|-
|&nbsp;&nbsp;&nbsp;
|-
|!&nbsp;&nbsp;&nbsp; using the set_selection list command with a single value
|-
|!&nbsp;&nbsp;&nbsp; means that the geometry in the list will be the only
|-
|!&nbsp;&nbsp;&nbsp; selected geometry. Adding a 1 to the command, suppresses the
|-
|-
|translate_geo xs,ys    ||    ! translate it to the start position
|!&nbsp;&nbsp;&nbsp; deselect all, so we can select geometry from multiple lists
|-
|-
|}
|&nbsp;&nbsp;&nbsp;
redraw<br>
|-
<br>
|message "Select the original shape and the copies in X", "Geo pattern", 1
message "Copy Horizontally", "Geo pattern", 1<br>
<br>
translate_geo dx,0,0,(nx-1)  ! translate and copy<br>
redraw<br>
<br>
message "Copy Vertically", "Geo pattern", 1<br>
<br>
! after the translate and copy<br>
! just the copies will be selected<br>
{|
|get_selection_list 2    ||    ! save list of currently selected geometry
|-
|-
|select_shape iref      ||    ! reselect the original shape
|set_selection_list 1
|-
|-
|translate_geo 0,dy,0,(ny-1)||  ! translate the whole row in Y
|set_selection_list 2, 1
|-
|-
|redraw
|redraw
Line 125: Line 272:
|
|
|-
|-
|get_selection_list 3   ||     ! save list of currently selected geometry
|message "Add the copies in Y", "Geo pattern", 1
|-
|set_selection_list 3, 1
|-
|redraw
|-
|&nbsp;&nbsp;&nbsp;
|-
|message "Finished"
|}
|}
message "Select the original shape", "Geo pattern", 1<br>
set_selection_list 1<br>
redraw<br>
<br>
message "Select the copies in X", "Geo pattern", 1<br>
set_selection_list 2<br>
redraw<br>
<br>
message "Select the copies in Y", "Geo pattern", 1<br>
set_selection_list 3<br>
redraw<br>
<br>
! using the set_selection list command with a single value<br>
! means that the geometry in the list will be the only<br>
! selected geometry. Adding a 1 to the command, suppresses the<br>
! deselect all, so we can select geometry from multiple lists<br>
<br>
message "Select the original shape and the copies in X", "Geo pattern", 1<br>
set_selection_list 1<br>
set_selection_list 2, 1<br>
redraw<br>
<br>
message "Add the copies in Y", "Geo pattern", 1<br>
set_selection_list 3, 1<br>
redraw<br>
<br>
message "Finished"<br>

Latest revision as of 15:00, 29 July 2010

!    create a contour and then copy it
!    across a rectangular grid
!   
!    show use of geometry selection lists
a1$ = "This macro will create a shape and"
a2$ = "then copy it across a rectangular grid"
a3$ = "It will use 2 dialogs, one for the shape"
a4$ = "data and another for the pattern data"
a5$ = "After creating the geomtry, it will select"
a6$ = "the individual parts, rows and columns"
message "%a1$\n%a2$\n\n%a3$\n%a4$\n\n%a5$\n%a6$"
dialog "GeoPattern_Part.dlg"
:get_repeats
dialog "GeoPattern_Repeats.dlg"
!    data from Part dialog
!    l1 = long length
!    l2 = short length
!    h1 = long height
!    h2 = short height
!    r1 = large fillet
!    r2 = small fillet
!    data from Repeats dialog
!    xs = x start
!    ys = y start
!    dx = x spacing
!    dy = y spacing
!    nx = number in x
!    ny = number in y
   
if nx<2 then message "Invalid number of parts in X (2 to 5)"
if nx<2 then goto get_repeats
   
if nx>5 then message "Invalid number of parts in X (2 to 5)"
if nx>5 then goto get_repeats
   
if ny<2 then message "Invalid number of parts in Y (2 to 4)"
if ny<2 then goto get_repeats
   
if ny>4 then message "Invalid number of parts in Y (2 to 4)"
if ny>4 then goto get_repeats
   
   
!    start a new part and set the stock size
!    ---------------------------------------
   
new_part "Example.vnc"
set_part_data mdd_name, "VMill3a"  !    3 axis vertical mill
set_part_data units, 1  !    inches
   
!    set the stock size
!    ------------------
   
set_part_data stock_x1, xs
set_part_data stock_y1, ys
set_part_data stock_z1, 0
set_part_data stock_x2, xs+dx*(nx-1)+l1
set_part_data stock_y2, ys+dy*(ny-1)+h1
set_part_data stock_z2, 1
   
set_view top
zoom_view 0
   
message "Create one shape, starting at X 0, Y 0", "Geo pattern", 1
   
contour [
start r1, 0
line l1-r1, 0
arc l1-r1, r1, l1, r1, ccw
line l1, h2-r2
arc l1-r2, h2-r2, l1-r2, h2, ccw
line l2+r2, h2
arc l2+r2, h2+r2, l2, h2+r2, cw
line l2, h1-r2
arc l2-r2, h1-r2, l2-r2, h1, ccw
line r1, h1
arc r1, h1-r1, 0, h1-r1, ccw
line 0, r1
arc r1, r1, r1, 0, ccw
]
   
iref=ContourRef !    reference number for the contour
clear_select !    make sure nothing is selected
select_shape iref !    select the shape we just created
get_selection_list 1 !    save list of currently selected geometry
redraw
message "Move to start position", "Geo pattern", 1
translate_geo xs,ys !    translate it to the start position
   
redraw
   
message "Copy Horizontally", "Geo pattern", 1
   
translate_geo dx,0,0,(nx-1)  ! translate and copy
redraw
   
message "Copy Vertically", "Geo pattern", 1
!    after the translate and copy
!    just the copies will be selected
get_selection_list 2 !    save list of currently selected geometry
select_shape iref !    reselect the original shape
translate_geo 0,dy,0,(ny-1) !    translate the whole row in Y
redraw
   
get_selection_list 3 !    save list of currently selected geometry
   
   
message "Select the original shape", "Geo pattern", 1
set_selection_list 1
redraw
   
message "Select the copies in X", "Geo pattern", 1
set_selection_list 2
redraw
   
message "Select the copies in Y", "Geo pattern", 1
set_selection_list 3
redraw
   
!    using the set_selection list command with a single value
!    means that the geometry in the list will be the only
!    selected geometry. Adding a 1 to the command, suppresses the
!    deselect all, so we can select geometry from multiple lists
   
message "Select the original shape and the copies in X", "Geo pattern", 1
set_selection_list 1
set_selection_list 2, 1
redraw
message "Add the copies in Y", "Geo pattern", 1
set_selection_list 3, 1
redraw
   
message "Finished"