Examining Do_it
The definition for Do_it is listed below:
DEFINE Do_it {Generate holes in demo04.mi}
EDIT_PART TOP {Setup: make sure we are at top part}
SPOTLIGHT OFF
PD_RESOLVE REPLACE {Solve for front holes}
AREA_PROPERTY 1 Find_midp DEL_OLD '\temp\area'
END {Get the area properties of 1 front hole}
{and write to a temporary file. }
EDIT_PART 'slot_grid' {Goto the second part, slot_grid}
PD_PARAM_FIX 'Newrad' New_radius {Find radius needed to give equivalent}
{area. Fix part radius to this value.}
PD_RESOLVE REPLACE {Solve for back slots}
EDIT_PART TOP {Clean up: go back to top part}
DISPLAY ('Variations Generated. Done.')
END_DEFINE {of Do_it}
Do_it calls the macros Find_midp and New_radius, both of which are listed here:
DEFINE Find_midp {find a point inside a front-face hole}
LOCAL A {Declare local variable A}
LOCAL B {Declare local variable B}
PD_PARAM_INQ 'Pt1' {Find Pt1 location from parameter table}
LET A (PNT_XY (INQ 3) (INQ 4)) {assign Pt1 location to A}
PD_PARAM_INQ 'Pt2' {Find Pt2 location from parameter table}
LET B (PNT_XY (INQ 3) (INQ 4)) {assign Pt2 location to B}
((A+B)/2) {Return midpoint of A and B}
END_DEFINE {of Find_midp}
DEFINE New_radius {Get area of front hole,}
{return radius of back slot.}
LOCAL L {Declare local variable L}
LOCAL A {Declare local variable A}
LET A 'junk' {Set A to some junk value!}
LET L 200 {Set L to length of a back slot}
OPEN_INFILE 1 '\temp\area' {open file of area properties written above}
WHILE ((SUBSTR A 1 3)<>'A =') {scan area_spec for the area (A=) field}
READ_FILE 1 A {and load the area field into A}
LET A (TRIM A)
END_WHILE
LET A (SUBSTR A 4 (LEN A)) {set A to be just area value (area of 1 hole}
LET A ((VAL A)*4) {total area of front holes is 4A}
(((SQRT(L*L + (PI*A)/3))-L)/PI){Given area of holes A and length of slots L}
{return hole radius for equivalent area. }
END_DEFINE {of New_radius}
The algorithm used by Do_it is as follows:
1. Solve the variation for the intake ports.
2. Use AREA_PROPERTIES to find the area properties of an intake port and write this data to a file. Call the macro Find_midp to generate the point which identifies this port.
3. Change the current part to the exhaust ports.
4. Call the macro New_radius to calculate the needed radius from the data in the file written above. Assign this radius to "Newrad."
5. Solve the variation for the exhaust slots.
This procedure is straightforward, but does use some interesting features of both Creo Elements/Direct Drafting and Parametric Design commands:
• Although Parametric Design only operates on the current part, a macro like Do_it can easily manage interchanges among multiple parts.
• The macro Find_midp uses the reference-point constraints Pt1 and Pt2 to determine a point that is guaranteed to be inside an intake port. Since Pt1 and Pt2 are constrained to always be on the corners of this port, the point between them will always be inside the port. Passing this point to AREA_PROPERTIES makes sure that we always get the properties for an intake port. Note how PD_PARAM_INQ is used to grab the locations of these points from the parameter table.
• New-radius simply reads the area data from a file and uses it along with hard-coded data about the slot length to generate the appropriate radius. The output is input to Parametric Design via PD_FIX_PARAM. Of course a much more complex macro could be used to supply this input!