Create a form that will allow you to create a group based on element shape from selected elements.
-
You should modify the function from Exercise 7 to accept a string of selected elements, i.e., the function arguments will be:
FUNCTION GroupElmsByShape(ElmList, GroupName, ElmShapeId)
In Exercise 7, this function created groups using all elements in the database. Now this function will created groups from only the selected elements.
In order to create groups based on the selected elements rather than all the database elements, the db_count_elems(…) statement will be replaced with fem_u_count_id_list(…) and the db_get_elem_ids(…) function will be replaced with fem_u_get_id_list(…).
-
Use either a switch, ui_switch_create(…), or an optionmenu, ui_optionmenu_create(…) to select the element shape.
-
Be sure to echo your function call to the session file via the > symbol.
Form to Group Elms By Shape
-
Built-in functions
ui_form_create(callback, x_loc, y_loc, position, width, height, label, iconnme)
ui_frame_create(parent, callback, x_loc, y_loc, label)
ui_switch_create(parent, callback, x_loc, y_loc, num_cols, label, always_one)
ui_item_create(parent, name, label, toggleable)
ui_databox_create(parent, callback, x_loc, y_loc, label_length, box_length, @
label, value, label_above, datatype, num_vals)
ui_selectframe_create(parent, callback, x_loc, y_loc, width, height, @
label, recycle)
ui_selectdatabox_create(parent, callback, x_loc, y_loc, label_length, @
box_length, label, value, label_above, datatype, prompt)
ui_separator_create(parent, name, x_loc, y_loc, length, horizontal)
ui_button_create(parent, callback, x_loc, y_loc, width, height, label, @
flag, highlight)
ui_wid_get(widget_id, parameter, value)
ui_wid_get_vstring(widget_id, parameter, value)
NumElms = fem_u_count_id_list(SublistType, PickList, DoMsg, Status)
fem_u_get_id_list(SublistType, PickList, NumElms, DoMsg, ElmIds)
ga_group_exist_get(GroupName, IntegerFlag)
ga_group_create(GroupName)
db_get_elem_etop(NumElms, ElmIds, ElmTops)
db_get_elem_topology_data(NumElms, ElmTops, ElmShapes, NodesPerElm)
ga_group_entity_add(GroupName, ElmList)
Extra credit: Include “Auto Execute” functionality
Extra credit: Include error checking via the msg_to_form(…) and user_message(…) functions
Extra credit: Include the ability to “undo” the creation of your group
Extra credit: Use the ui_wid_refresh() function to automatically update other displayed forms that might list group names.
Extra credit: Include a callback to the element shape switch that automatically provides a default group name based on the selected shape.
E
Day 4
xecuting Programs Outside of MSC.Patran
Application developers may have the need to execute other programs in order to perform certain operations. Programs that execute other programs are said to be “spawning a process.”
Spawning Remote Processes -
Spawning a remote process is one method of performing customized functionality. The PCL function utl_process_spawn(…) is used by MSC/PATRAN to spawn a process.
-
PCL process commands
Functions
|
Description
|
utl_process_spawn(command,wait)
|
Spawns a process. The return value of the command is either an error code or the process id if wait = FALSE.
|
utl_process_wait(pid)
|
Wait for the process to complete before continuing
|
utl_display_process_error(errcode, severity)
|
Display an error message based on the return value of utl_process_spawn.
|
utl_process_error(errcode)
|
Returns True or False given the errcode (status) of the utl_process_spawn or _wait command.
|
utl_process_kill(pid)
|
Kill a process
|
C
stat = utl_process_spawn( “read_results.exe”, TRUE )
IF( utl_process_error( stat ) ) THEN
utl_display_process_error( stat, 3 )
END IF
ode Example
E
Example Script
utl_process_spawn("executable_home_dir/bin/script_name",TRUE)
Script:
#! /bin/sh
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Provides a front-end for external executables and scripts
# in support of MSC/PATRAN PCL.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Extract command name from the $0 string
CmdName=`echo $0 | sed 's;^.*/;;'`
echo $CmdName
CmdDir=` echo $0 | sed -e 's;^\(.*\)/.*;\1;' -e 's;/*bin$;;'`
if [ "`echo "$CmdDir" | sed 's;^\(.\).*$;\1;'`" != / ] ; then
CmdDir=`pwd`/$CmdDir # ensure non-relative path
fi
echo $CmdDir
case `uname` in
SunOS) Machine=SUN ;;
IRIX*) Machine=SGI ;;
AIX) Machine=IBM ;;
HP-UX) Machine=HP700 ;;
OSF1) Machine=DECA ;;
esac
if [ $# -eq 0 ] ; then
exec $CmdDir/bin/exe/$Machine/$CmdName
else
exec $CmdDir/bin/exe/$Machine/$CmdName "$@"
fi
xternal Processes
-
Redirection cannot be used in the utl_process_spawn() command. If redirection is required then a shell script should be created, then executed by the utl_process_spawn command.
Invalid utl_process_spawn(“runscript > outfile”,TRUE)
-
To support multiple platforms a shell script can be setup to query machine type information and then run the appropriate executable.
External Processes
Locking a database -
Having more than one process access a database simultaneously can damage the database.
In order to prevent this, MSC/PATRAN locks the database while it is in use. Any executable that accesses the database (e.g., translator, solver, etc.) should also perform a file lock to guarantee secure access of that database. If a database is locked, a message will be relayed indicating that the database is in use.
-
The stand-alone utility ”lockfile” gives an application developer the ability to lock databases.
If this utility is run for a database that is already locked, it will wait five minutes and retry. It will not lock a database until an existing database lock has been cleared.
-
The lockfile utility requires the name of the database to lock and a command string to execute. The lock will remain active as long as the command executes.
-
The syntax for the lockfile utility is as follows:
l
FUNCTION start_mytrans(dbname, count)
str_formatc(cmd,”lockfile %s %s -db %s -cnt %d,” @
dbname, mytrans, dbname, count)
/* Spawn the process and continue; do not wait for completion.
If a process spawning error occurs, display it as severity
2 (WARNING) */
status = utl_process_spawn(cmd, FALSE)
IF ( utl_process_error( status ) ) THEN utl_display_error( status, 2)
END FUNCTION /* start_mytrans */
Using this example, this will execute the following command:
lockfile my.db mytranslator -db my.db -cnt 542
ockfile …
External Processes
Using C and Fortran executables to access a MSC.Patran database directly. -
External C and Fortran programs can access Patran databases using the C or Fortran versions of PCL database function calls. An example link script is delivered in the Patran customization directory that includes all the libraries needed to satisfy any reference to the PCL database functions. The scripts are CAccessCalls.c and fort_access_calls.f.
-
The PCL and Customization Patran Library document has more information on accessing the Patran database from external programs, Section 8.3 (V9.0 of Patran).
-
Multiple simultaneous transactions on a Patran database is not permitted. All transactions should be completed prior to performing an external operation. The db_commit_raw() function should be used to commit all previous operations that have occurred in the database.
-
If you are only extracting information, the database does not need to be closed
-
If you are modifying the contents of a database then the database must be closed prior to running the external process.
External Processes
External Access of an MSC.Patran Database -
There cannot be multiple simultaneous transactions on an MSC.Patran database.
If an external program accesses a database which is currently opened by MSC.Patran, MSC.Patran must first end the transaction with the database with the “db_commit_raw” function. Only when the external program is finished accessing the database should MSC.Patran resume a translation within the database using the “db_start_transaction_raw” function.
-
When accessing the database only to extract information, MSC.Patran need not close the database but should end the current transaction and restart it only after the external program is finished.
E
FUNCTION my_spawn()
INTEGER status
status = db_commit_raw()
status = utl_process_spawn ( “process arg1”, TRUE )
IF ( utl_process_error ( status ) ) THEN
utl_display_process_error( status, 3 )
END IF
status = db_start_transaction_raw()
END FUNCTION
xample of PCL code which would spawn an external process to extract information.
External Process
-
When an external program is modifying or adding data to a database which is currently open, the database must first be closed and then re-opened by MSC.Patran after the external program has finished.
The database must be closed and re-opened because there is no mechanism for informing MSC.Patran of external changes to an already opened database.
E
FUNCTION my_spawn()
INTEGER status
STRING database_name[256]
status = db_name_get ( database_name )
status = uil_file_close.go()
status = utl_process_spawn ( “process arg2”, TRUE )
IF ( utl_process_error ( status ) ) THEN
utl_display_process_error( status, 3 )
END IF
status = uil_file_open.go( database_name )
END FUNCTION
xample of PCL code which would spawn an external forward translator.
Share with your friends: |