Errors from Built-In Functions -
Error messages for most built in functions are stored in a message database.
-
These error messages are accessed through the use of the following functions: msg_to_form() and msg_to_string().
-
Each message in the message database is associated with a unique number between 1 and 999,999,999. This number is returned as a non-zero status when a function fails to execute properly.
status = db_count_elems(num_elems)
IF (status != 0) THEN
msg_to_form(status, MSG_FATAL, appcode(status) 0, 0.,"")
RETURN -1
END IF
This PCL code would bring up a form displaying the error message and it would be listed in the message window and session file.
-
The severity of the message is controlled by the second argument in the function msg_to_form(). Valid options are: MSG_FATAL (= 4), MSG_WARNING, MSG_ACKNOWLEDGE, MSG_CRASH, and MSG_INFO. These constants can be found in the include file, pdamsg.h
-
The severity shows up as part of the feedback to the user so they can be alerted to the severity of the error.
Handling Errors and Messaging
Custom Error Messages Using User Messages Database -
Custom (user-defined) messages can be created and accessed with the same msg_to_form() used for MSC.Patran built-in functions.
-
This is done by creating a text file with the following format:
#******** NEW APPCODE
1001000000 FEM_TOOLS3
#define form text labels
1001000001 Tools.write_nodes
1001000002 Special String
#define messages
1001000100 Invalid entry in databox
With the above user message database, the following line could produce this form:
msg_to_form(1001000100,MSG_FATAL,1001000001,0,0.,””)
Handling Errors and Messaging
Without a Messages Database -
If it is not desired to create a message database, then the user_message() function can be used to report errors or other user information.
status = db_count_elems(num_elms)
IF (status != 0) THEN
msg_to_form(status, 4, appcode(status), 0, 0., “”)
RETURN -1
END IF
IF (num_elems == 0) THEN
user_message(“Warn”, 0, “My PCL”, “No elements in the database!”)
RETURN 0
END IF
user_message(“WARN”,0,”MY PCL”,”No elements in the database!”)
Message
Warning reported in application My PCL
No elements in the database
Handling Errors and Messaging
Handling Errors and Messaging
-
The UNDO feature of MSC.Patran operates like a “fence”. Nothing is actually saved to the database until a uil_db_commit() operations is performed. When a user selects the Undo icon, everything since the last uil_db_commit() is “Un-done”.
-
The uil_db_commit() function works in conjunction with the uil_db_undo() function.
uil_db_commit(STRING)
uil_db_undo()
-
Any function that changes the contents of a MSC.Patran database should perform a uil_db_commit(…) prior to performing the operation.
-
If an error is detected during the operation, a uil_db_undo() should be performed. Example:
FUNCTION apply_btn_cb()
INTEGER status
REAL force_val
STRING lbc_name[32]
STRING node_list[VIRTUAL]
ui_wid_get_vstring(node_sdbox, “VALUE”, node_list)
ui_wid_get(force_dbox, “VALUE”, force_val)
ui_wid_get(lbc_name_dbox, “VALUE”, lbc_name)
uil_db_commit(“Create force at nodes”)
status = CreateForceAtNodes(lbc_name, force_val, node_list)
IF (status != 0) THEN
uil_db_undo()
END IF
END FUNCTION
Share with your friends: |