Creo/Proe全命令教程-程序的详细作用解读含详细视频教程

导航目录:

  1. 关于程序
  2. 学习交流
  3. 模拟测验

本节概述:

  1. 程序是参数化建模的中枢神经。
  2. 本节视频主要讲解程序的基本用法。

重要知识点笔记:

  1. 程序功能可以创建属于自己的交互式程序以通过关系驱动模型几何。

免费系统化曲面教程>>>(思路细节精讲)

联系站长;   QQ:2621139966        微信:Creo2077          学习交流群;   QQ1群:602849358        QQ2群:916477208

关于视频:

视频编号<103>  视频已为您加入隐藏水印

学习遇到问题欢迎加群一起学习讨论!

与之相关:

参数>>>

 

一.关于程序

1.关于程序

关于交互式 C 程序:

可创建属于自己的交互式程序以通过关系驱动模型几何。创建用户程序时,请考虑以下信息:

•“用户程序”(User Prog) 命令仅在“零件”和“草绘器”模式下可用。

•一次只能编辑或运行一个用户程序。但可为每个零件编写多个程序,然后依次运行。

•每个程序都被限制到称作 "USRMAIN()." 的单个输入子程序中。输入子程序可以调用该程序文件中的其它子程序。

•Creo Parametric 提供一个 C 文件模板 usermain.c 以帮助用户编写及使用用户程序。

•在用户程序中,必须用大写表示 Creo Parametric 尺寸。

•使用 D[i] 表示屏幕上的尺寸。该符号对应“零件”或“装配”模式下的 di,或对应“草绘器”模式下的 sdi。系统不接受用户分配的符号名 (例如宽度),而只使用系统分配的尺寸符号。

•在任何程序中都不要使用 exit 语句。要将错误处理机制构建到程序中,请使用 printf 或 fprintf 语句。

•不能使用用户程序驱动装配尺寸和阵列实例数。

要使用交互式程序,必须完成下列步骤:

1.创建程序。或者,可编辑现有程序创建新程序。

2.编译并链接程序。

3.运行程序以实现更改。

4.当程序结束运行后,重新生成模型以更新几何.

2.编辑交互式 C 程序

编辑交互式 C 程序:

使用此过程可创建新的程序或编辑现有的程序。

1.单击“工具”(Tools) > “关系”(Relations)。“关系”(Relations) 对话框打开。

2.单击“实用工具”(Utilities) > “用户程序”(User Prog) > “编辑”(Edit)。

3.输入程序名称而不带 .c 扩展名。编辑器窗口打开。如果编辑现有的程序,Creo Parametric 会检索指定的程序文件。

4.如果创建新程序,必须先将 C 文件 templateusermain.c 复制到编辑器中。执行下列操作:

在 Windows 中 - 使用 Windows Notepad 编辑器。打开一个模板文件,然后使用“另存为”(Save As) 保存该文件。

5.编辑程序。

6.保存程序。Creo Parametric 将被激活。

PS:只能定义尺寸符号。

3.确定环境变量

确定环境变量:

使用此过程确定当前环境变量的路径。

1.单击“窗口”(Window) > “打开系统窗口”(Open System Window)。

2.当外壳窗口打开后,执行下列操作:

◦在 Windows 下输入以下命令:

[echo %PRO_USRMAIN% %PRO_USRINCS%]

系统会在外壳窗口中显示完整路径。


示例:连接交互式 C 程序:


编辑 C 程序后,必须编译及连接程序。您需要一个编译环境才能构建程序。编译程序时,请考虑以下信息:

•在 Windows 中 - 必须定义两个环境变量:

◦NT_COMPILER - 从 Creo 安装位置,打开 parametric.psf 文件,然后添加 NT_COMPILER 环境变量。编译器的值必须为 32 位增量式 C 编译器命令。例如,可使用 Visual Studio 批处理文件 ENV=NT_COMPILER=<install_location>\\Microsoft Visual Studio\\2019\\Professional\\VC\\Auxiliary\\Build\\vcvarsall.bat <arch> & cl. 来设置此环境变量

◦LIB - 编译器的值必须是从编译器的加载点到其库 (.LIB 文件) 的目录路径。

1.单击“工具”(Tools) > “关系”(Relations)。“关系”(Relations) 对话框打开。

2.单击“实用工具”(Utilities) > “用户程序”(User Prog) > “链接”(Link)。系统开始编译程序。如果系统检测到错误,它会在启动窗口中显示出错消息。如有必要,可编辑并重新连接程序。


执行交互式 C 程序:

成功连接用户程序后,可运行程序以实现更改。

PS:
•系统不会自动运行用户程序。必须在每次更新零件时重新运行该程序。
•在完成运行程序时,必须重新生成零件以更新几何。

1.单击“工具”(Tools) > “关系”(Relations)。“关系”(Relations) 对话框打开。

2.单击“实用工具”(Utilities) > “用户程序”(User Prog) > “运行”(Run)。

3.输入程序名称。程序开始执行。任何打印输出都将写到启动窗口中。程序会提示用户进行必要的输入。执行用户程序时,系统创建下列两个临时文件:

◦spgtousr.dat 列出执行程序之前的参数及其值。

◦usrtospg.dat 列出执行程序之后的参数及其值。

可在确信程序正确运行后删除这些文件。

4.当程序结束运行后,重新生成模型以更新几何.


示例:用户程序:

该程序根据压力容器的直径和工作压力及允许的应力等材料参数计算其厚度。程序会从模型中导出直径。用户根据提示在启动窗口内输入材料参数。计算所得的厚度将传递回 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]

4.示例:连接交互式 C 程序

示例:连接交互式 C 程序:

编辑 C 程序后,必须编译及连接程序。您需要一个编译环境才能构建程序。编译程序时,请考虑以下信息:

•在 Windows 中 - 必须定义两个环境变量:

◦NT_COMPILER - 从 Creo 安装位置,打开 parametric.psf 文件,然后添加 NT_COMPILER 环境变量。编译器的值必须为 32 位增量式 C 编译器命令。例如,可使用 Visual Studio 批处理文件 ENV=NT_COMPILER=<install_location>\\Microsoft Visual Studio\\2019\\Professional\\VC\\Auxiliary\\Build\\vcvarsall.bat <arch> & cl. 来设置此环境变量

◦LIB - 编译器的值必须是从编译器的加载点到其库 (.LIB 文件) 的目录路径。

1.单击“工具”(Tools) > “关系”(Relations)。“关系”(Relations) 对话框打开。

2.单击“实用工具”(Utilities) > “用户程序”(User Prog) > “链接”(Link)。系统开始编译程序。如果系统检测到错误,它会在启动窗口中显示出错消息。如有必要,可编辑并重新连接程序。

5.执行交互式 C 程序

执行交互式 C 程序:

成功连接用户程序后,可运行程序以实现更改。

PS:
•系统不会自动运行用户程序。必须在每次更新零件时重新运行该程序。
•在完成运行程序时,必须重新生成零件以更新几何。

1.单击“工具”(Tools) > “关系”(Relations)。“关系”(Relations) 对话框打开。

2.单击“实用工具”(Utilities) > “用户程序”(User Prog) > “运行”(Run)。

3.输入程序名称。程序开始执行。任何打印输出都将写到启动窗口中。程序会提示用户进行必要的输入。执行用户程序时,系统创建下列两个临时文件:

◦spgtousr.dat 列出执行程序之前的参数及其值。

◦usrtospg.dat 列出执行程序之后的参数及其值。

可在确信程序正确运行后删除这些文件。

4.当程序结束运行后,重新生成模型以更新几何.

6.示例:用户程序

示例:用户程序:

该程序根据压力容器的直径和工作压力及允许的应力等材料参数计算其厚度。程序会从模型中导出直径。用户根据提示在启动窗口内输入材料参数。计算所得的厚度将传递回 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]

此为QQ学习交流群(小姐姐超多)

QQ群:916477208 (1群) 602849358 (2群) 群内目前聚集了很多正在学习工业设计的小伙伴,还有很多厉害的大佬帮忙解决问题哟! 站长微信:creo2077

问题答疑♥资料白嫖

群内有大量学习资料哟~
点我直接加群嘛

学习讨论          在线联系
软件下载          关于我们
鲁ICP备2022028663号-1
鲁公网安备37132302000296号