Skip to main content

KApplication

kds-plugin-document / Exports / KApplication

Interface: KApplication

KApplication 是使用酷大师前端 Plugin API 的起点。

从这里我们可以获取很多其他有用的 API 接口。例如:

  1. 代表当前打开的酷大师方案的 KDesign 接口,从这里我们可以调用酷大师的各种建模命令,如拉伸、扫掠、布尔等,对方案数据进行修改;
  2. 代表酷大师视图窗口的 KView 接口,从这里我们可以获取酷大师的画布和相机对象,并在画布中绘制各种临时图形元素;
  3. 代表酷大师选择集的 KSelection 接口,从这里我们可以获取酷大师画布中的各种被选择的对象,如造型面、造型边、参考线、成组等 ... ...

KApplication 还可以激活一个插件自定义工具对象 (KTool),它可以响应各种鼠标、键盘事件,实现和酷大师内置建模工具类似的交互效果; KApplication 还可以注册、注销酷大师应用的事件观察者,供插件响应酷大师发出的各种事件

请阅读下面的方法注释,以获取更详细的信息

The KApplication interface serves as the "entry point" for most other APIs. From here we can get the active design, which represents the user's design data; we can get the active view, which represents the application's graphics view. We can also activate a custom tool, which is the tool that plugin provides to interact with the design data... please check the comments below for more information.

Table of contents​

Methods​

Methods​

activateCustomTool​

▸ activateCustomTool(tool, clearSelection?): boolean

激活插件自定义工具。插件自定义工具能响应各种鼠标、键盘事件,从而实现和酷大师内置建模工具类似的交互效果

Activate the custom tool.

Parameters​

NameTypeDescription
toolKToolThe custom tool.
clearSelection?booleanIf the clearSelection flag is set to true, when the tool is activated, the selection will be cleared. The default value is false.

Returns​

boolean

Return true if successful, otherwise return false.

Defined in​

api.d.ts:478


addObserver​

▸ addObserver(observer): boolean

添加酷大师应用观察者。目前观察者主要用于响应插件关闭的消息,这样插件本身可以完成一些业务逻辑,比如保存插件本身的业务数据

The method is used to add an plugin observer to the application object.

Parameters​

NameTypeDescription
observerKApplicationObserverThe observer to add.

Returns​

boolean

Return true if successful, else return false.

Defined in​

api.d.ts:520


clearTimeout​

▸ clearTimeout(id): void

清除延时任务

Clear the timeout task.

Parameters​

NameTypeDescription
idnumberThe timeout task id.

Returns​

void

Defined in​

api.d.ts:510


deactivateCustomTool​

▸ deactivateCustomTool(tool, clearSelection?): boolean

反激活插件自定义工具

Daactivate the custom tool.

Parameters​

NameTypeDescription
toolKToolThe custom tool.
clearSelection?booleanIf the clearSelection flag is set to true, when the tool is deactivated, the selection will be cleared. The default value is false.

Returns​

boolean

Return true if successful, otherwise return false.

Defined in​

api.d.ts:489


getActiveDesign​

▸ getActiveDesign(): KDesign

获取当前打开的酷大师方案。从 KDesign 接口我们可以调用酷大师各种建模命令,如拉伸、扫掠、布尔等,对方案数据进行修改

Get the active design.

Returns​

KDesign

The active design.

Defined in​

api.d.ts:413


getActiveView​

▸ getActiveView(): KView

获取酷大师视图窗口。从 KView 接口我们可以获取酷大师的画布和相机对象,并在画布中绘制各种临时图形元素

Get the active view.

Returns​

KView

The active view.

Defined in​

api.d.ts:422


getApplicationUI​

▸ getApplicationUI(): KApplicationUI

获取酷大师应用的 UI 面板,即顶部工具栏、左侧栏、右侧属性面板等组成的酷大师 UI 面板

Get the KApplicationUI object for operating the application UI.

Returns​

KApplicationUI

The KApplicationUI object for operating the application UI.

Defined in​

api.d.ts:440


getAssetLibraryHelper​

▸ getAssetLibraryHelper(): KAssetLibraryHelper

获取酷大师素材库帮助器

get the Kudashi asset library helper

Returns​

KAssetLibraryHelper

Defined in​

api.d.ts:574


getClientStorage​

▸ getClientStorage(): KClientStorage

获取客户端临时存储对象。通过该对象,插件可在客户端进行临时数据存取

Get the KClientStorage object for allowing you to store data on the user's local machine.

Returns​

KClientStorage

The KClientStorage object.

Defined in​

api.d.ts:449


getEnvironmentSettings​

▸ getEnvironmentSettings(): EnvironmentSetting

获取当前环境设置

get current environment settings

Returns​

EnvironmentSetting

Defined in​

api.d.ts:600


getPickHelper​

▸ getPickHelper(): KPickHelper

获取选择帮助器,此接口提供了按屏幕 2d 点选,按屏幕 2d 矩形框选等进行选择的方法

Get the KPickHelper object for allowing you to pick entities.

Returns​

KPickHelper

The KPickHelper object.

Defined in​

api.d.ts:467


getPluginModelLibraryHelper​

▸ getPluginModelLibraryHelper(): KPluginModelLibraryHelper

获取插件模型库帮助器,包含模型公库和私库

Get the plugin model library helper, covering both public and private model library.

Returns​

KPluginModelLibraryHelper

The KPluginModelLibraryHelper object.

Defined in​

api.d.ts:557


getPluginUI​

▸ getPluginUI(): KPluginUI

获取插件 UI 面板。插件如果提供了 UI html,就是在这个 UI 面板里打开的。我们可以调整此 UI 面板的大小,发送和响应插件自定义消息

Get the KPluginUI object for operating the plugin UIs.

Returns​

KPluginUI

The KPluginUI object for operating the plugin UIs.

Defined in​

api.d.ts:431


getPluginViewById​

▸ getPluginViewById(id): KPluginView

根据viewId获取PluginView,可以从沙盒代码向iframe view发送自定义消息

Get the KPluginView object.

Parameters​

NameType
idstring

Returns​

KPluginView

The KPluginView object.

Defined in​

api.d.ts:548


getProductManager​

▸ getProductManager(): ProductManager

获取酷家乐商品库管理器

get the product library manager

Returns​

ProductManager

Defined in​

api.d.ts:566


getSelection​

▸ getSelection(): KSelection

获取酷大师选择集。用户在视图窗口中用鼠标选中的造型面、造型边、参考线、成组等,都可以从此选择集中得到

Get the selection operation handle.

Returns​

KSelection

The selection operation handle.

Defined in​

api.d.ts:405


getTestHelper​

▸ getTestHelper(): KTestHelper

Deprecated

获取酷大师测试帮助器。目前此接口仅用于酷大师 UI 自动化测试,不建议插件开发者使用

Get the utility helper that is only used for testing.

Returns​

KTestHelper

The KTestHelper object

Defined in​

api.d.ts:539


getToast​

▸ getToast(): KToast

获取酷大师信息提示接口

Get the toast operation handle.

Returns​

KToast

The toast operation handle.

Defined in​

api.d.ts:396


getToolHelper​

▸ getToolHelper(): KToolHelper

获取自定义工具 KTool 的帮助接口,此接口提供了一组帮助自定义工具实现更复杂交互效果的方法,例如激活选择功能,激活框选功能,设置选择过滤器等

Get the utility helper for plugin tools.

Returns​

KToolHelper

The KToolHelper object.

Defined in​

api.d.ts:458


registerMessageHandler​

▸ registerMessageHandler(callback): string

将沙盒代码中的自定义消息处理函数注册到酷大师

Register the custom message handler in the sandbox code to KooMaster.

Parameters​

NameType
callback(data: any, origin: string) => void

Returns​

string

the unique handleId.

Defined in​

api.d.ts:583


removeObserver​

▸ removeObserver(observer): boolean

移除酷大师应用观察者

The method is used to remove the plugin observer from the application object.

Parameters​

NameTypeDescription
observerKApplicationObserverThe observer to remove.

Returns​

boolean

Return true if successful, else return false.

Defined in​

api.d.ts:530


setTimeout​

▸ setTimeout(callback, time, ...args): number

@deprecated:延时若干毫秒后执行一个函数 (本方法将被移除。建议直接使用 JS 内置的 setTimeout 方法)

The method is used to call a function after the specified number of milliseconds.

Parameters​

NameTypeDescription
callback(...args: any[]) => voidThe called function.
timenumberThe specified number of milliseconds.
...argsany[]The parameters passed to the callback function

Returns​

number

Defined in​

api.d.ts:501


unRegisterMessageHandler​

▸ unRegisterMessageHandler(handerId): boolean

从沙盒代码中解绑自定义消息处理函数

Unregister the custom message handler.

Parameters​

NameType
handerIdstring

Returns​

boolean

true if message handler has registered and has been removed, or false if the message handler hasn't registered.

Defined in​

api.d.ts:592