基本的な機能 > リレーションとパラメータ > リレーション > C プログラムとリレーション > 例: ユーザープログラム
  
例: ユーザープログラム
プログラムは、圧力容器の直径と、作業圧力や許容応力のような材料パラメータに基づいて圧力容器の厚みを計算します。プログラムは、モデルから直径を求めます。ユーザーは、プロンプトに従って起動ウィンドウに材料パラメータを入力します。計算された厚みは Creo Parametric に戻されます。
[プログラムは以下の行から始まります。]
/* Template for writing user programs in the Creo Parametric environment */
/* the following definition and include file are necessary */
#define USRMAIN
#include "spgusrgl.h"

/* This include file establishes useful variables for user needs. Those are:
1. D[i] refers to dimensions you see on the screen. ‘i’ is the index of a
dimension you see on the screen.
So, D[0] has a value corresponding to "d0" on the screen (or "sd0" if you are
in SKETCHER mode). D[4] corresponds to "d4" (or "sd4") on the screen, and so forth.
2. DIM_NUM Total number of dimensions on the screen.
*/
usrmain()
/* This program computes the thickness for a pressure vessel given the diameter from the model and various material and design constants input by the user. */
{
/* ---------------------- local variables ----------------------- */
/* Declare any additional variables or functions you need here. */
double sqrt ();
double thickness, f_s, joint_eff, allow_stress, press, dia;
/* ---------------------- executable code ----------------------- */
/* Prompt user for input. Prompts appear in the startup window. You must also
enter your responses there. */
printf("Enter material parameters\n");
printf("\n Working Pressure [psia]:\n");
scanf("%lf", &press);
printf("\n Factor of Safety [ ]:\n");
scanf("%lf", &f_s);
printf("\n Joint efficiency [ ]:\n");
scanf("%lf", &joint_eff);
printf("\n Allowable stress [psia]:\n");
scanf("%lf", &allow_stress);
/* Compute thickness of pressure vessel based on equations in Mechanical Analysis
and Design, A.H. Burr, Elsevier, 1982.
Note use of dimension D[2], the pressure vessel diameter, in computing the new
thickness */
thickness = press * D[2] * f_s / (2 * joint_eff * allow_stress);
/* Pass new thickness back to Creo Parametric */
D[3] = thickness;
}
[Program ends with previous line]