HyperWorks API Programming for Beginners

HyperWorks API Programming for Beginners初学者需要掌握的HyperWorks API

HyperWorks有两种控制方式:直接通过图形用户界面(GUI)和使用编程命令或API。

HyperWorks is controlled in two ways: directly via the graphical user interface (GUI) and by using programming commands, or APIs.

APIs tell HyperWorks to perform an action. For example, the AddPage API adds a page within the project.

通过API调用HyperWorks来执行操作。例如,AddPage API在项目内添加一个页面。

To be able to use APIs, you must open the command console. This can be done in two ways:

  • Drag up the horizontal sash next to the horizontal scroll box near the bottom the page.

  • From the View menu, select Command Window.

Once in the command console, you may may start programming.

为了能够使用API​​,必须打开命令控制台。这可以通过两种方式完成:

  • 向上拖动页面底部附近水平滚动框旁边的水平窗扇。

  • 从“查看”菜单中,选择“命令窗口”。

一旦进入命令控制台,就可以开始编程。

在这里插入图片描述

图片描述

To program using the APIs, handles must be opened.

要使用API​​进行编程,必须打开句柄。

  • 在对象(句柄)的层次结构中可以找到每个API。 API用于打开句柄,但也可以在句柄中找到它们,除非打开句柄,否则无法使用API​​。类推可以用来进一步解释这一点。假设您想吃巧克力冰淇淋。首先,您必须打开冰柜门才能到达纸箱。然后,您必须找到装有巧克力冰淇淋的纸箱,打开纸箱进入冰淇淋,最后可以吃了。冰淇淋的类型可能不止一种,因此该人员必须决定要使用哪种类型的冰淇淋,因此必须决定要选择哪种纸箱。要获取特定的API,必须确定需要打开哪些句柄才能获取该API并打开所需的句柄。

  • Each API is found within a hierarchy of objects (handles). APIs are used to open handles, but are also found within handles and cannot be used unless the handle is opened. An analogy can be used to further explain this. Say you want to eat chocolate ice cream. First, you must open the freezer door to get to the carton. Then, you must find the carton that has the chocolate ice cream, open the carton to get to the ice cream, and finally you can eat it. There may be more than one type of ice cream, and the person must decide what type of ice cream you want, and therefore must decide which carton to choose. To get to specific APIs, you must determine which handles need to be opened in order to get to that API and open the handles needed.

  • 打开手柄后,就可以自由使用它,直到释放(关闭)为止。以吃冰淇淋为例,这就像关闭盖子。除非再次打开盖子,否则该人无法享用冰淇淋。同样,可以再次打开手柄。手柄可以无限期打开和释放。这对于重新使用手柄很重要。

  • Once a handle is open, it is free to use until it is released (closed). In the ice cream example, this would be like shutting the lid. The person cannot get to the ice cream unless he opens the lid again. Similarly, the handle can be opened again. Handles can be opened and released indefinitely. This is important to reusing the handle.

  • 句柄总是从其父级获取的。这两个手柄必须以某种方式关联。所有句柄均从其父对象获得。

  • The handle is always obtained from its parent; the two handles must be related in some way. All handles are obtained from their parent object.

下图说明了HyperWorks中句柄的类层次结构的一部分。该图表未显示API。

The image below illustrates part of the class hierarchy of handles in HyperWorks. APIs are not shown in this chart.

在这里插入图片描述

图片描述

For example, to use the AddPage API on a hwIProject handle, you must open the session handle followed by the project handle.

例如,要在hwIProject句柄上使用AddPage API,必须先打开会话句柄,再打开项目句柄。

  • When each handle is opened, a name is given to the handle for further use.

  • 当打开每个手柄时,将为手柄指定一个名称,以备将来使用。

    - hwi GetSessionHandle sess

    *hwi is the first parent handle, which connects every API together.

* hwi是第一个父句柄,它将每个API连接在一起。

*sess is the name given to the session handle.  You can any name you want, as long as it is unique.

* sess是赋予会话句柄的名称。您可以使用任何想要的名称,只要它是唯一的即可。

  • When opening some handles, you may need to specify which handle out of many options that you want to use. For example, when opening a page handle, you must specify which page you want to get the handle from, as there can be several pages.

  • 当打开一些手柄时,您可能需要在要使用的许多选项中指定哪个手柄。例如,在打开页面句柄时,必须指定要从哪个页面获取句柄,因为可能会有多个页面。

    - hwi GetSessionHandle sess
    - sess GetProjectHandle proj
    - proj GetPageHandle p1 1

All APIs are in the form:

所有API的形式均为:

Handle Method args

Some have no arguments (args), some have many. Some handles cannot be opened until an object is added, for there is no handle to open without the object. For example, to open a curve handle in a plot, you must add a curve before opening the handle.

有些没有参数(参数),有些有很多。在添加对象之前,无法打开某些句柄,因为没有该对象就无法打开句柄。例如,要在绘图中打开曲线手柄,必须在打开手柄之前添加一条曲线。

    hwi  GetSessionHandle sess

    sess GetProjectHandle proj

    proj GetPageHandle    p1 1

    p1   GetWindowHandle  w1 1

    w1   GetClientHandle  plot

    plot AddCurve

    plot GetCurveHandle   c1 1

If you do not know how to use specific APIs (especially those that open up handles), please reference the commands listed in this help system and look up the particular API. Another way of exploring APIs is using the ListMethods command. When the list methods command is called after a handle, a list of APIs available for use in that handle is returned.

如果您不知道如何使用特定的API(尤其是那些打开句柄的API),请参考此帮助系统中列出的命令并查找特定的API。探索API的另一种方法是使用ListMethods命令。在句柄之后调用list Methods命令时,将返回可用于该句柄的API列表。

After an API is called, SOMETHING will be returned. A value, handle, list, success (0) or error code (a number in red) will be returned.

调用API后,将返回一些东西,例如:一个值、句柄(handle)、列表,成功(0)或错误代码(将以红色数字标识)。

For a more in-depth explanation of API programming and HyperWorks, see the Programming with HyperWorks Tcl/Tk Commands tutorial.

有关API编程和HyperWorks的更深入的说明,请参见[使用HyperWorks Tcl / Tk命令编程]()教程。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值