Directly use the open API method in C #/a method of using open API in C #

Source: Internet
Author: User

The NXOpen class library provided by ug nx supports C #, but unfortunately there are too few materials. Many people use the C # language to develop the NX tool and still use the previous UFUN, that is, Open API. It is encapsulated by the UF space provided in NXOpen. Encapsulation is a common. net technology.

Unfortunately, many functions (such as uc1601) are not included in these encapsulation methods. That is to say, using C # for development is basically out of line with these unencapsulated functions.

The methods described in this article can solve the problems that these functions cannot be used. Take uc1601 as an example.

First, find the function entry (locate the function ). The APIs of UG are encapsulated in five dll files: libufun. dll, libnxopencpp. dll, libugopenint. dll, libnxopenuicpp. dll, and libopenpp. dll. You only need to use DEPENDS. EXE to find the dll of the API. For example, uc1601 is in libugopenint. dll.

Then import the function. It should be noted that it is best to check the API manual in advance to understand the definition of this API, that is, parameters and responses.

Public class OpenAPI
{
[System. Runtime. InteropServices. DllImport ("libugopenint. dll")]
Public static extern void uc1601 (string msg, int mode );
}

Next we can use:

Public static int Main (string [] args)
{
Int retValue = 0;
Try
{
TheProgram = new Program ();

// TODO: Add your application code here
OpenAPI. uc1601 ("OK", 1 );

TheProgram. Dispose ();
}
Catch (NXOpen. NXException ex)
{
// ---- Enter your exception handling code here -----
UI. GetUI (). NXMessageBox. Show ("Message", NXMessageBox. DialogType. Error, ex. Message );
}
Return retValue;
}

Of course, the environment must also be the method required by NX (Main or Startup function as the entry ).

Finally, it is difficult to use this method if the parameters are complex. However, C #4, which is about to enter the development stage, is said to have greatly improved the Dynamic Language Features and may be better used.

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.