[Protoolkit Example 4] Create a UDF

Source: Internet
Author: User

Vs2005 + proe3.0 example download: http://download.csdn.net/detail/wangyao1052/4954443

Usage: 1. decompress the package. The created UDF: hole. gph, part file: prt001.prt, and compiled DLL files are available in the bin directory.

2. Modify the path to start proe3.0 in goproe. bat to the installation path of your local proe3.0. Double-click goproe. BAT to start proe3.0 and load the test menu.

3. Open prt001.prt in proe and click test to call the program to let the user select a vertex. After selecting a vertex, the hole. gph will be called to create a hole.

We know that when inserting a UDF, proe looks for the UDF: current working directory of proe and the path defined in pro_group_dir in config. Pro or config. Sup in the configuration file.

Therefore, to ensure that the UDF is successfully found in this program, hole. gph must be placed in the current working directory of proe.

The reason for using goproe. when Bat starts proe, it sets the PROE working directory to goproe. in the directory where BAT is located, you can find hole. gph, and protk. the path in the DAT file is relative rather than absolute. In this way, you can use protk. dat correctly loads the path.

Create a video for the corresponding UDF: http://download.csdn.net/detail/wangyao1052/4954580

The Code is as follows:

// Else //-----------------------------------------------------------------------------//*********************************** **************************************** ** // --------------------------------------------------------------------------------- # pragma region # include <protoolkit. h> # include <proutil. h> # include <promenubar. h> # include <promenu. h> # include <promode. h> # include <promdl. h> # include <prosolid. h> # Inc Lude <proasmcomp. h> # include <proarray. h> # include <promodelitem. h> # include <prolayer. h> # include <proudf. h> # include <prowindows. h> // function declaration uicmdaccessstate testaccess (uicmdaccessmode access_mode); int test (uicmd1_id command, using * p_value, void * p_push_command_data); extern "C" int user_initialize () {proerror err; profamilyname msgfile; prostringtowstring (msgfile, "test_msg.txt"); // Add the menu testmen U err = promenubarmenuadd ("testmenu", "testmenu", "help", pro_ B _true, msgfile); // Add command and menu item uicmd1_id 1__id1; err = pro1_actionadd ("test ", test, uiproeimmediate, testaccess, pro_ B _false, pro_ B _false, & cmd_id1); err = encrypt ("testmenu", "test", "test", "test_help", null, pro_ B _true, cmd_id1, msgfile); Return 0;} extern "C" Void user_terminate () {} int test (uicmd1_id com Mand, cmd* p_value, void * handle) {proerror err; promdl mdl_curr; proselection * p_sel; proselection pnt_sel; int n_sel; // obtain the current model err = promdlcurrentget (& mdl_curr ); // select point err = proselect ("point", 1, null, & p_sel, & n_sel); If (pro_tk_no_error! = Err | n_sel! = 1) Return-1; proselectioncopy (p_sel [0], & pnt_sel); // UDF-related variable definition proudfdata udf_data; proudfreference udf_pnt_ref; proudfvardim limit, limit; progroup UDF; // UDF basic attributes: proudfdataalloc (& udf_data); proudfdatanameset (udf_data, l "hole", null); proudfdatadependencyset (udf_data, proudfdependency_independent ); // For UDF settings, see proudfreferencealloc (L "place_point", pnt_sel, pro_ B _false, & UDF _ Pnt_ref); Round (udf_data, udf_pnt_ref); // set the UDF size data: diameter = 50.0, depth = 50.0 err = proudfvardimalloc (L "diameter", 50, proudfvartype_dim, & role); err = second (udf_data, udf_diameter_dim); err = proudfvardimalloc (L "depth", 50, proudfvartype_dim, & role); err = second (udf_data, role ); // create UDF err = proudfcreate (prosoli D) mdl_curr, udf_data, null, null, 0, & UDF); If (pro_tk_no_error! = ERR) {afxmessagebox (text ("create UDF failed. ");} // release the resource proudfdatafree (udf_data); proudfvardimfree (random); random (random); proudfreferencefree (udf_pnt_ref); proselectionfree (& pnt_sel ); // refresh window displays prowindowrepaint (pro_value_unused); Return 0;} uicmdaccessstate testaccess (uicmdaccessmode access_mode) {proerror err; promode mode; err = promodecurrentget (& mode); If (err! = Pro_tk_no_error) {return access_unavailable;} If (mode = pro_mode_part | mode = pro_mode_assembly) {return access_available;} else {return access_unavailable ;}} # pragma endregion // region //-----------------------------------------------------------------------------//******************************** **************************************** *****//-----------------------------------------------------------------------------

Program description:

1. first obtain the current model under proe and use promdlcurrentget.

2. Call proselect to select the point to obtain the proselection of the selected point.

Why do you need to use proselectioncopy in the program? Because after you call proselect, the obtained proselection is only in the current selection buffer of proe. This is a temporary content. If the program behind you is useful for the proselection you have obtained, and the proselection is released before that, an error will occur, which is equivalent, you have added a buffer in C ++ and obtained its pointer. However, after you release the buffer with Delete, the obtained pointer will certainly fail if you use it later, because it points to the released buffer.

To explain this, manually select an element in proe, A proselection will be created and added to the selection buffer. You will see that the selected element is highlighted in the model window, if you press the ESC key, the selection buffer will be cleared. You can see that there are no highlighted elements in the interface. This means the selection buffer has been cleared.

3. Set the name of the udf to be inserted in proudfdatanameset.

4. proudfreferencealloc (L "place_point", pnt_sel, pro_ B _false, & udf_pnt_ref );

Proudfdatareferenceadd (udf_data, udf_pnt_ref );

Add reference. Note that "place point" is the reference name. When you create a UDF using PROE, the PROE pop-up window will show you how to name each reference, for details, refer to the operations in the previously created UDF video.

5. // set the size of the UDF: diameter = 50.0, depth = 50.0

Err = proudfvardimalloc (L "diameter", 50, proudfvartype_dim, & udf_diameter_dim );

Err = proudfdataudfvardimadd (udf_data, udf_diameter_dim );

Err = proudfvardimalloc (L "depth", 50, proudfvartype_dim, & udf_depth_dim );

Err = proudfdataudfvardimadd (udf_data, udf_depth_dim );

Set the size data of the UDF. If this parameter is not set, the default size driver is used when the UDF is created.

"Diameter" and "depth" are the size names. When you create a UDF, the PROE dialog box appears, asking you to name each driver size you set, for more information, see the operations in the UDF video created above.

Although the name you name for the drive size when creating a UDF can be different from its own name, sometimes the driver size cannot be driven when you insert a UDF program, I have not figured out this problem. It is probably a proe bug. Therefore, for security reasons, please follow the steps in the previously created UDF video to name the size first, create a UDF and name the driver size to make it consistent.

6. Insert UDF into proudfcreate

7. Do not forget to release resources.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.