Msc. Patran pcl handbook In a Nutshell 7


Handling Errors and Messaging



Download 1.08 Mb.
Page13/25
Date05.08.2017
Size1.08 Mb.
#26706
1   ...   9   10   11   12   13   14   15   16   ...   25

Handling Errors and Messaging

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



  • Several message types are supported, some of those include: “WARN”, “FATAL”, “INFO”, “ACK”, “Q_YN”, “Q_YN_Y”, “C_YN”, “C_YNY”, “C_YNYN”, “C_YNYN_Y”, etc.

  • C_YN = “Critical” decision with Yes and No buttons

  • C_YNY = “Critical” decision with Yes, No, and YesForAll buttons

  • C_YNYN = “Critical” decision with Yes, No, YesForAll, and NoForAll buttons

  • C_YN_Y = “Critical” decision with Yes and No buttons. The Yes button is the default action.

  • C_YN_N = “Critical” decision with Yes and No buttons. The No button is the default action.

  • The return value for user_message(…) indicates which button was selected: 1 = Yes, 2 = No, 3 = Yes for all, 4 = Abort, 5 = No for all

    IF (file_exists(fname, “”)) THEN

    status = user_message(“C_YN”, 0, “PCL: Field Tool”, @

    Selected file already exists! Overwrite?)



    IF (status != 1) THEN RETURN -1

    file_delete(fname)

    END IF

Handling Errors and Messaging

Taking Advantage of the UNDO Feature


  • 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


Download 1.08 Mb.

Share with your friends:
1   ...   9   10   11   12   13   14   15   16   ...   25




The database is protected by copyright ©ininet.org 2024
send message

    Main page