//////////////////////////////////////////////////////////////////////
			// Code Example: Importing data: trimmed surface method 
			//
			//////////////////////////////////////////////////////////////////////


			// This function is passed the step number. This allows for an application to
			// produce code with several steps as demonstrated.
			// Return 1 if you have finished, 0 if otherwise and -1 to exit.

			int CMyCode::RunMyCode(int step)
			{

			//The code below is sample code. On exiting the function the bodies that
			//exist will be drawn

				
				int finished = 0;	
				char text[500] = "";
				static PK_BODY_t body = PK_ENTITY_null;	
				int n_faces = 0;
				PK_FACE_t *faces = NULL;
				int count = 0;
				PK_BODY_t sheets[6] = {PK_ENTITY_null, PK_ENTITY_null,PK_ENTITY_null,PK_ENTITY_null,PK_ENTITY_null,PK_ENTITY_null,};
				int n_sewn_bodies = 0;
				PK_BODY_t *sewn_bodies = NULL;
				int n_unsewn_bodies = 0;
				PK_BODY_t *unsewn_bodies = NULL;
				int n_problem_groups = 0;
				PK_BODY_problem_group_t *problem_group = NULL;
				int n_faults = 0;
				PK_check_fault_t *faults = NULL;
				PK_SURF_t bsurf[6]= {PK_ENTITY_null, PK_ENTITY_null,PK_ENTITY_null,PK_ENTITY_null,PK_ENTITY_null,PK_ENTITY_null,};
				PK_LOGICAL_t sense = PK_LOGICAL_false;
				PK_SURF_trim_data_t trim_data;
				PK_check_state_t state;
				PK_GEOM_t *geoms = NULL;
				PK_INTERVAL_t *intervals = NULL;
				PK_TOPOL_t *topols = NULL;
			 
				// Create a block 

				switch( step )
				{
				case 1:
			  
					CExampleAppDoc::ExAppSetStatusBarString("Imported a solid block into Parasolid using the trim surface route");
					PK_BODY_create_solid_block( 0.1, 0.1, 0.1, NULL, &body );

					// Find all the faces of the body 

					PK_BODY_ask_faces( body, &n_faces, &faces );

					// Set up a for loop to create a trimmed surface-rep of a face and make a sheet body 

					for( count=0 ; count< n_faces ; count++ )
					{

						PK_FACE_output_surf_trimmed_o_t trim_opts;
						PK_FACE_output_surf_trimmed_o_m( trim_opts );

						trim_opts.trim_surf = PK_FACE_trim_surf_bsurf_c;


						PK_FACE_output_surf_trimmed( faces[count], &trim_opts, &bsurf[count], &sense,
							 &trim_data, &geoms, &intervals, &topols );
						
						if (geoms)
							PK_MEMORY_free( geoms );
						if (topols)
							PK_MEMORY_free( topols );
						if (intervals)
							PK_MEMORY_free( intervals );


						PK_SURF_make_sheet_trimmed_o_t make_opts;
						PK_SURF_make_sheet_trimmed_o_m( make_opts );

						PK_SURF_make_sheet_trimmed( bsurf[count], trim_data, 1.0e-06, &make_opts, 
							&sheets[count], &state );

						if( state == PK_BODY_state_ok_c)
						{
						}
						else 
						{			
							sprintf_s(text, BUFFER_SIZE, "Creating trimmed sheet %d - body is invalid - stopping", count);				
							CExampleAppDoc::ExAppShowMessage(text);
							return -1; 
						}
					}

						sprintf_s(text, BUFFER_SIZE, "Created %d trimmed surfaces from faces.\n", count );
						CExampleAppDoc::ExAppShowMessage(text);
						sprintf_s(text, BUFFER_SIZE, "Created %d sheets from trimmed surfaces.\n", count ); 
						CExampleAppDoc::ExAppShowMessage(text);
						sprintf_s(text, BUFFER_SIZE, "Checked %d sheet bodies.\n",count );
						CExampleAppDoc::ExAppShowMessage(text);
					
					// Free up some memory 
					if (faces)
						PK_MEMORY_free( faces );

					// Now that all the sheets have been created we need to sew them together 

					sprintf_s(text, BUFFER_SIZE, "Starting to sew sheets into solid.\n");
					CExampleAppDoc::ExAppShowMessage(text);

					PK_BODY_sew_bodies_o_t sew_opts;
					PK_BODY_sew_bodies_o_m( sew_opts );

					sew_opts.allow_disjoint_result = PK_LOGICAL_false;
					sew_opts.prefered_body_type = PK_BODY_sewing_solid_c;

					PK_BODY_sew_bodies( 6, sheets, 1.0e-06, &sew_opts, &n_sewn_bodies, &sewn_bodies,
						  &n_unsewn_bodies, &unsewn_bodies, &n_problem_groups, &problem_group );

					if( n_sewn_bodies == 1 && n_unsewn_bodies == 0 && n_problem_groups == 0 )
					{
						sprintf_s(text, BUFFER_SIZE, "Body sewn into solid - checking result...\n" );
						CExampleAppDoc::ExAppShowMessage(text);
						
						PK_BODY_check_o_t check_opts;
						PK_BODY_check_o_m( check_opts );

						PK_BODY_check( sheets[0], &check_opts, &n_faults, &faults );

						if( n_faults == 0 )
						{
							sprintf_s(text, BUFFER_SIZE, "Body is valid \n");
							CExampleAppDoc::ExAppShowMessage(text);
						}
						else
						{
							sprintf_s(text, BUFFER_SIZE, "Sewn Body is invalid - Stopping.\n" );
							CExampleAppDoc::ExAppShowMessage(text); 
							return -1; 
						}
					}
					else 
					{
						sprintf_s(text, BUFFER_SIZE, "Body has failed to sew - Stopping.\n" );
						CExampleAppDoc::ExAppShowMessage(text); 
						return -1; 
					}

					if (sewn_bodies)
						PK_MEMORY_free( sewn_bodies );
					if (unsewn_bodies)
						PK_MEMORY_free( unsewn_bodies );

					if (problem_group)
					{
						for( count = 0; count < n_problem_groups; count ++)
							PK_MEMORY_free( problem_group[count].edges );

							PK_MEMORY_free( problem_group );
					}

					// Delete the original body

					PK_ENTITY_delete( 1, &body );

					break;

				default:
					int n_parts;
					PK_PART_t *parts;

					PK_SESSION_ask_parts(&n_parts, &parts);
					PK_ENTITY_delete(n_parts, parts);
					PK_MEMORY_free(parts);
					finished = 1;
				}

				return finished;
			}