• / 236
  • 下载费用:50 金币  

MSC.Patran PCL Workshop Notes.pdf

关 键 词:
MSC PatranPCLWorkshopNotes
资源描述:
MSC.Patran PCL Handbook FUNCTION init() WIDGET id INTEGER i, status REAL x_loc, y_loc, form_width, form_height REAL frame_width REAL f_width, half_space STRING version[3] STRING method_opt[NAME_LENGTH], method[NAME_LENGTH] form_width = FORM_WID_SML frame_width = form_width - FORM_L_MARGIN - FORM_R_MARGIN f_width = frame_width - FRAME_L_MARGIN - @ FRAME_R_MARGIN - FRAME_2EDGE half_space = INTER_WIDGET_SPACE/2.0 settings.pcl p3prolog.pcl p3midilog.pcl p3epilog.pcl .Patran.EventMaps MSC.Patran PCL Workshop Notes 07/14/06 2/236 In a Nutshell7 What is PCL? .7 What can PCL be used for?8 How does PCL work?9 All you really need to know is on this page!.10 Documentation10 PCL for Everyone .11 Entering Equations11 Entering Data .12 Session Files13 Rebuilding Models.14 PCL for the More Adventurous .17 Parametric Modeling.17 Adding a Graphical User Interface, GUI21 Exercise 1: Session Files.22 PCL Programming Basics .24 Overview.24 PCL Expressions26 Expressions, Comments, Syntax Tips26 Identifiers28 Naming Conventions.28 Variable / Function Scope.29 Structure of a PCL Function30 Function Basics.30 Simple PCL function Example .31 Exercise 2: Hello World! 33 Exercise 3: Effective PCL 34 PCL Operators35 String comparisons.35 PCL Variables and Constants .36 Datatypes36 Variable Scope.37 Directly Allocated Arrays38 Virtual arrays39 Virtual strings 41 Loop Control Statements.42 MSC.Patran PCL Workshop Notes 07/14/06 3/236 For Loop.42 While Loop .42 Repeat Loop.43 BREAK44 CONTINUE45 Exercise 4: Writing Files46 Exercise 5: Reading Files48 Conditional Control Statements49 IF Statement.49 SWITCH Statement50 Structure of a PCL Function51 Compiling and Linking PCL Functions.54 Primary PCL Directives.55 Compiling PCL outside of MSC.Patran.59 Linking Compiled Libraries60 Other PCL Directives.61 Start Up Files .62 Exercise 6: p3epilog.pcl.63 Debugging.64 Debugging Compile Errors.64 Debugging Runtime Errors.65 Accessing PCL Functions.67 From The Command Line.67 From Any MSC.Patran Form 68 PCL Functions with Field Variables 69 MSC.Patran Built-In Functions70 Naming Conventions for Applications71 Naming Conventions for Other Operations72 Exercise 7: Group Elements By Shape.74 Graphical User Interface75 The PCL Class Statement.76 PCL Widgets 77 Required Functions for Building/Displaying a Form.78 The init() Function .78 The display() Function79 Widget Callbacks.82 What Are They?82 What Are They Used For?83 MSC.Patran PCL Workshop Notes 07/14/06 4/236 Callback Arguments (Widget Function Data).83 Widget Placement85 Widget Variables87 Modifying Widgets.88 Getting Data from Widgets.89 Putting it all Together (Example) .90 Exercise 8: Simple Form92 The C-Preprocessor and Include Files.93 Make Files 94 Exercise 9: Callbacks.96 Handling Errors and Messaging .98 Errors from Built-In Functions.98 Custom Error Messages.99 Using User Messages Database 99 Without a Messages Database.100 Taking Advantage of the UNDO Feature.102 Select Mechanism 103 Select Mechanism GUI Mechanics 103 Select Databoxes, Select Frames, and Select Menus103 GUI PCL Example105 List Processor106 List Processor Mechanics106 All You Really Need to Know107 Exercise 10: Form to Group Elms By Shape110 Executing Programs Outside of MSC.Patran.112 Spawning Remote Processes 112 Locking a database.114 Using C and Fortran executables to access a MSC.Patran database directly115 External Access of an MSC.Patran Database.116 Special Widgets118 File Widget .118 Spreadsheet Widget121 Exercise 11: File Widget 122 Adding Help/Description to your PCL 123 Percent Complete.124 Functions124 Example124 Event Manager125 MSC.Patran PCL Workshop Notes 07/14/06 5/236 General .125 Functions126 Example126 Primitive Graphics127 Graphic Objects.127 Graphic Segments.128 Example129 Another Example.130 Exercise 12: Primitive Graphics131 MSC.Patran Customization132 Adding Utility Programs to the Main Menu.132 Example133 Example: p3_user_menu.my_menu.def134 Customizing the MSC.Patran Toolbar.135 Exercise 13: Pulldown Menu.138 Exercise 14: Toolbar 139 Some Final Thoughts.141 Appendix A .144 Built-in Function Examples144 Documentation for a typical MSC.Patran built-in function. 145 To get all the nodes and their global coordinates.146 To get the topology of every element147 To get the shape of every element 148 To get all the element connectivity for all elements149 To get the elements associated to a particular element property set .150 To get an element property value (shell thickness) for a specific element.151 To get a material property value153 To get a list of all groups154 To get the nodes and elements associated to the current group 154 To get result values for specified elements155 Appendix B .164 Strings ” alpha = 30.0; beta = 120.0 ? PCL expressions can be continued on subsequent lines by using the “@” symbol ui_wid_set(main_form, @ “HEIGHT”, @ NewHeight) ui_wid_set( /* widget_id */ main_form, @ /* parameter */ “HEIGHT”, @ /* value */ NewHeight) PCL Expressions ? Don’t break expressions in the middle of a keyword, constant, or identifier ? Multiple blanks are the same as a single blank space ? Lines beginning with “!” (bang operator) are echoed to the xterm (UNIX) or command window (NT), but are not executed In MSC.Patran type: !`i` nodes created In the xterm you see: %27 nodes created ? PCL expressions beginning with “>” are echoed to the session file ? PCL expressions can be typed directly into MSC.Patran at the command line ? PCL expressions may also be created with an editor in a text file and directed into MSC.Patran as a session file or by using the PCL directive !!INPUT MSC.Patran PCL Workshop Notes 07/14/06 27/236 MSC.Patran PCL Workshop Notes 07/14/06 28/236 Identifiers Naming Conventions ? Function names and/or variable names are called identifiers ? Can be up to 32 characters long ? Must begin with a non-digit ? Case insensitive (as is all of PCL) ? Cannot be a reserved keyword, i.e., FOR, IF, etc. ? Valid identifiers current_group CurrentGroup MyString ? Invalid identifiers a_very_very_very_very_very_very_very_very_long_name 95abc list MSC.Patran PCL Workshop Notes 07/14/06 29/236 Identifiers Variable / Function Scope? Global variable names and functions share the same name space ? When two function names or two variable names conflict, the most recent addition supercedes the previous ? When function names and variable names conflict, the variable name takes precedence ? When compiling functions, PCL will indicate if a function name is superceded by writing “Cleared memory function” to the history window ? Hint: Use a unique prefix to keep function definitions separate, i.e au_do_this_and_that.pcl MSC.Patran PCL Workshop Notes 07/14/06 30/236 Structure of a PCL Function Function Basics ? PCL functions begin with a FUNCTION statement and end with an END FUNCTION statement. ? The FUNCTION statement may contain an argument list to be passed in or out of the function. ? An optional RETURN statement can be used to return a calculated value from the function to the calling statement. ? Processing of the function terminates at either the END FUNCTION statement or a RETURN statement. ? There may be multiple RETURN statements within a single function. Structure of a PCL Function Simple PCL function Example Function arguments (null) FUNCTION a_very_simple_function() /* This is a simple function that writes: “$# My favorite number is 29” in the MSC.Patran history window using 3 different “write” or “print” statements. */ /* This is a comment. */ $ This is also a comment. INTEGER MyFavoriteNumber MyFavoriteNumber = 29 ui_writec(“My favorite number is %d \n”, MyFavoriteNumber) ui_writef(“A21,1X,I3”, “My favorite number is”, MyFavoriteNumber) ui_write(“My favorite number is “//STR_FROM_INTEGER(MyFavoriteNumber)) END FUNCTION /* a_very_simple_function */Function declaration Statements or expressions Function terminator Comments (Who we kidding? We all know that everyone loathes commenting their code!) Variable declaration Variable initialization MSC.Patran PCL Workshop Notes 07/14/06 31/236 Structure of a PCL Function ? Another simple PCL function another_simple_function(29) $#My favorite number is 29 $#My least favorite number is 13 FUNCTION another_simple_function(MyFavoriteNumber) INTEGER MyFavoriteNumber INTEGER MyLeastFavoriteNumber MyLeastFavoriteNumber = 13 ui_write(“My favorite number is “//str_from_integer(MyFavoriteNumber)) ui_write(“My least favorite number is “// @ str_from_integer(MyLeastFavoriteNumber)) END FUNCTION /* another_simple_function */ Function argument Note all variables must be declared, including function argumentsCalling statement Sample output. The ui_write functions write text to the history window, the session file (patran.ses.##), and the journal file (model.db.jou) Sample output Calling statement MSC.Patran PCL Workshop Notes 07/14/06 32/236 MSC.Patran PCL Workshop Notes 07/14/06 33/236 Exercise 2: Hello World! Write and execute a PCL function that accepts a single real number argument and echoes Hello World, my favorite number is …. to the MSC.Patran session file and history window. Your function will use either the ui_write(…), ui_writef(…), or ui_writec(…) functions. If you use the ui_writef(…) and ui_writec(…) functions, refer to the documentation for the correct format specifiers. Extra credit: How would this function change if you wanted to echo your favorite 10 numbers to the session file? Extra credit: How would this function change if you wanted to echo your favorite color to the session file? Exercise 3: Effective PCL Write an essay on how the effective use of PCL could: a) Help create a lasting world peace b) Eliminate world hunger c) Conquer the common cold d) Stop global warming Extra credit: How could PCL be used to find Elvis? MSC.Patran PCL Workshop Notes 07/14/06 34/236 MSC.Patran PCL Workshop Notes 07/14/06 35/236 PCL Operators Operators Comments + - ! Unary plus, minus, logical not ** Exponentiation * / Multiplication and division + - Additions and subtraction // String concatenation = == != Relational operators || the name of the group to be created and the element shape code, i.e., FUNCTION GroupElmsByShape(GroupName, ElmShapeId) 2) Use the following built-in functions: ga_group_create(GroupName) db_count_elems(NumElms) db_get_elem_ids(NumElms, ElmIds) db_get_elem_etop(NumElms, ElmIds, ElmTops) db_get_elem_topology_data(NumElms, ElmTops, ElmShapes, NodesPerElm) ga_group_entity_add(GroupName, ElmString) 3) Sample code outline: a) Declare variables b) Count the elements in the database c) Get the element Ids d) Get the element topology codes e) Use the element topology codes to get the element shape codes f) Create the group g) LOOP: If an element’s shape code matches the selected shape code then add it to the group Extra Credit: For each element of the correct shape, automatically include its associated nodes in the group as well. Extra Credit: Modify the function to create a group for each of several selected element shapes. Extra Credit: Write a PCL function to create groups based on element topology (i.e., quad4, tria3, hex8, hex20, etc.) instead of element shape. Graphical User Interface ? Nearly all forms and widgets that are contained in MSC.Patran were created in PCL ? PCL can be used to customize the MSC.Patran interface by adding menus to the top menu bar. ? Each menu item will reference a PCL function that is referred to as a “callback” function. Typically, this “callback” function will perform an operation (such as, delete groups, etc.) or open a form. MSC.Patran PCL Workshop Notes 07/14/06 75/236 MSC.Patran PCL Workshop Notes 07/14/06 76/236 Graphical User Interface The PCL Class Statement ? The Class is a way of grouping functions for a common task. Classes in PCL are similar (but not equivalent) to Classes in C. ? Classes allow variables to be visible or “Global” among a limited set of functions. CLASSWIDE REAL global_tol ? At least one class is required for each form. ? Only one class should be defined per file and the file name should match the class name. ? Generally, only functions related to managing forms and form data are defined within a class. ? A class structure consists of a CLASS class_name statement near the beginning of the file and a END CLASS statement at the end of the file. CLASS I_have_class CLASSWIDE WIDGET main_form FUNCTION init() END FUNCTION /* init / . . FUNCTION display() END FUNCTION /* display */ . . END CLASS /* end of I_have_class */ Graphical User Interface PCL Widgets ? Graphical objects for displaying and accepting user supplied data. ? Based on Motif Xlib and Xtlib intrinsics (UNIX) and Windows GUI (NT). ? Subset of the OSF/Motif and Windows widget library specialized to MCAE applications. ? Examples include: forms, menus, databoxes, labels, switches, buttons, etc. Databox Label Frame Label Menu Label:Menu item Menu item Menu Label: Button 2 Button 1 Form Label Select Frame Label Select databox1 label Select databox2 label MSC.Patran PCL Workshop Notes 07/14/06 77/236 MSC.Patran PCL Workshop Notes 07/14/06 78/236 Graphical User Interface Required Functions for Building/Displaying a Form Every form is defined within a class and has at least two, but usually more specific functions; init(), display(). Sometimes the refresh() function is also required. The init() Function ? The init() function is user defined, but must be called init(). ? It is the first function defined in the class and is the function that defines the form and all of its widgets. ? It is also used to initialize any classwide variables that need initializing the first time the form is opened. ? The built-in functions for defining widgets will only be called in this function. Below are examples to build a form and place a button: main_form = ui_form_create(“”, @ /* x position */ FORM_X_LOC, @ /* y position */ FORM_Y_LOC, @ /* relative to */ “UL”, @ /* width */ FORM_WID_SML, @ /* height */ FORM_HGT_QTR, @ /* label */ “My_Form_Label”, @ /* unused */ “”) my_button = ui_button_create( @ /* parent */ main_form, @ /* callback */ “my_button_cb”, @ /* x position */ FORM_L_MARGIN, @ /* y position */ y_loc, @ /* width */ BUTTON_WID_FULL, @ /* height */ BUTTON_HGT, @ /* label */ “My Button…”, @ /* unused */ “”, @ /* highlight */ FALSE) MSC.Patran PCL Workshop Notes 07/14/06 79/236 Graphical User Interface The display() Function ? The display() function is simple, but required. A complete function may only contain the following: FUNCTION display() ui_form_display(“my_class”) END FUNCTION ? The only required element is the built-in function ui_form_display(classname). Classname is the name of the class that these functions are members of. ? Once the display() function is ca
展开阅读全文
  麦档网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
0条评论

还可以输入200字符

暂无评论,赶快抢占沙发吧。

关于本文
本文标题:MSC.Patran PCL Workshop Notes.pdf
链接地址:https://www.maidoc.com/p-2385348.html
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

[email protected] 2018-2020 maidoc.com版权所有  文库上传用户QQ群:3303921 

麦档网为“文档C2C模式”,即用户上传的文档所得金币直接给(下载)用户,本站只是中间服务平台,本站所有文档下载所得的金币归上传人(含作者)所有。
备案号:蜀ICP备17040478号-3  
川公网安备:51019002001290号 


收起
展开