PCL for the more Adventurous
Adding a Graphical User Interface, GUI
?
The next step might be to create a user interface to run the plate session file!
#include “appforms.p” CLASS plate_hole /* classwide variables */ CLASSWIDE WIDGET main_form, description_btn, radius_dbox CLASSWIDE WIDGET sep1, apply_btn, cancel_btn FUNCTION init() REAL x_loc, y_loc main_form = ui_form_create( @ /* callback */ “”, @ /* x location */ FORM_X_LOC, @ /* y location */ FORM_Y_LOC, @ ... END FUNCTION /* init */ FUNCTION display() ui_form_display(“plate_hole”) END FUNCTION /* display */ FUNCTION apply_button_cb() GLOBAL REAL radius ui_wid_get(radius_dbox, “VALUE”, radius) sf_play(“plate_hole.ses”) END FUNCTION /* apply_button_cb */ END CLASS /* plate_hole */ Hitting the “Apply” button executes the function: apply_button_cb()
MSC.Patran PCL Workshop Notes 04/13/16 21/236
Exercise 1: Session Files
Use MSC.Patran to create a parameterized session file that creates a rectangular surface with an arbitrarily located hole. 1) Create variables for the dimensions shown below.
2) Steps:
a) Create variables using MSC.Patran?s command line b) Create/Surface/XYZ (use variables length and width)
c) Edit/Surface/Add Hole (use x_center, y_center, and diameter)
Extra credit: Include error checking, i.e., it doesn?t make sense
for the hole to be outside the surface boundary.
IF (x_center + diameter/2.0 > length) THEN RETURN
Extra credit: Include meshing, boundary conditions, element
properties, etc. Extra credit: Use ui_read_real(prompt) to enter the variable
values interactively Extra credit: Turn your session file into a PCL FUNCTION.
MSC.Patran PCL Workshop Notes 04/13/16 22/236
Exercise 1
Below is an image showing an MSC.Patran form allowing the interactive creation of the model for this exercise.
NB – See Appendix G for notes about Parametric Patran. 1) Variables and macros are defined interactively via a GUI 2) Variables and macros are persistent 3) Plus, more. See Appendix G for the details
MSC.Patran PCL Workshop Notes 04/13/16 23/236
PCL Programming Basics
Overview
? ?
PCL is a full-featured programming language.
Operators for arithmetic, relational, and string expressions. Examples include:
addition multiplication string concatenation logical or logical equal logical not equal + * // || == != ?
Variables with type, scope, and dimension attributes
INTEGER LOGICAL REAL GLOBAL STRING
i, j, status, NodeIds(1000) flag
xyz(1000, 3), pressure(100), time my_group[32], all_groups[32](100)
?
Dynamically allocated virtual strings and arrays
INTEGER STRING
node_ids(VIRTUAL)
groups[32](VIRTUAL), MyString[VIRTUAL]
?
Intrinsic functions for math, string manipulation, etc.
sinr(angle) cosd(angle) mth_abs(MyVal)
mth_sort(MyArray, CompactDuplicates, NumLeft) mth_array_search(MyArray, Look4, Sorted) str_length(MyString)
str_substr(MyString, Position, SubStringLength) str_index(StringToSearchIn, StringToSearchFor)
str_token(MyString, Delimiter, TokenNumber, [Compress])
MSC.Patran PCL Workshop Notes 04/13/16 24/236
PCL Programming Basics
?
Loop control features, such as, WHILE, FOR, REPEAT, and LIST
Conditional control structure, such as, IF-THEN-ELSE and SWITCH-CASE
Subroutine (procedure) and function (command) calls Class grouping of related functions
Read/write access to external ASCII and/or binary files
text_open(FileName, Options, 0, 0, FileId)
text_read_string(FileId, InString, InStringLength) text_write_string(FileId, OutString)
text_read(FileId, Format, MyIntegers, MyReals, MyChar) text_write(FileId, Format, MyIntegers, MyReals, MyChar) text_close(FileId, Options) file_exists(FileSpec, Options) file_delete(FileSpec)
?
? ? ?
?
Access to MSC.Patran “built-in” functions that allow for direct access to the MSC.Patran database, geometry creation, drawing graphic primitives,
db_count_nodes(NumNodes)
db_get_node_ids(NumNodes, NodeIds)
asm_const_grid_xyz(output_ids, coordinates_list, coord_frame, @ created_ids)
MSC.Patran PCL Workshop Notes 04/13/16 25/236