even2004: [二次开发] evaluate all expressions #define WRITE(X) UF_UI_open_listing_window(); UF_UI_write_listing_window(X) #define WRITE_F(X) (write_double_to_listing_window(#X, X)) static void write_double_to_listing_window(char *title, double n) { char msg[UF_UI_MAX_STRING_LEN+1]; UF_CALL(UF_UI_open_listing_window()); sprintf(msg, "%s = %fn", title, n); UF_CALL(UF_UI_write_listing_window(msg)); } #define WRITE_L(X) (write_logical_to_listing_window(#X, X)) static void write_logical_to_listing_window(char *title, logical flag) { char msg[UF_UI_MAX_STRING_LEN+1]; UF_CALL(UF_UI_open_listing_window()); if (flag) sprintf(msg, "%s = TRUEn", title); else sprintf(msg, "%s = FALSEn", title); UF_CALL(UF_UI_write_listing_window(msg)); } /* There is no API method equvalent to these interactive options: Tools-> Update-> Update for External Change Tools-> Expression-> Refresh values from external spreadsheet- Tools-> Spreadsheet-> Edit-> Update NX part This program demonstrates a method which worked to update the model in a test case after changing values in an external spreadsheet. */ static logical evaluate_all_expressions(tag_t part, logical verbose) { logical something_changed = FALSE; int ii, n_exp; tag_t *exps; double new_value, old_value; char *full_string; UF_CALL(UF_MODL_ask_exps_of_part(part, &n_exp, &exps)); if (n_exp > 0)+ { for (ii = 0; ii < n_exp; ii++) { UF_CALL(UF_MODL_ask_exp_tag_string(exps[ii], &full_string)); if (verbose) WRITE(full_string); if (verbose) WRITE("n"); UF_CALL(UF_MODL_ask_exp_tag_value(exps[ii], &old_value)); if (verbose) WRITE_F(old_value); UF_CALL(UF_MODL_edit_exp(full_string)); UF_free(full_string); UF_CALL(UF_MODL_ask_exp_tag_value(exps[ii], &new_value)); if (verbose) WRITE_F(new_value); if (new_value != old_value) something_changed = TRUE; } if (verbose) WRITE_L(something_changed); UF_free(exps); } return something_changed; }
|
|