To Load and Execute JavaScript APIs
Based on which supported programming language you are using, JavaScript code can be loaded and executed using one of the following methods:
- WEBLOAD command - AutoLISP, scripts and from the AutoCAD UI
acjsLoadJSScript()
- ObjectARX and C++Application.LoadJSScript()
- Managed .NET
Using the acedInvoke(…)
function, you can call the JavaScript functions from your C++ code. Register the functions using a global JavaScript function, the syntax is:
defun(string name, callback)
ObjectARX and C++
Execute JavaScript functions using this method:
Acad::ErrorStatus acjsLoadJSScript(const ACHAR* uriOfHTML)
Register a callback for the JavaScript function using:
Acad::ErrorStatus acjsDefun(const ACHAR* name, JsCallbackType callback);
Where
jsCallbackType
is defined as:typedef JSON (*JsCallbackType)(const JSON* params)
Managed .NET
Use this information to import the .NET assembly required to execute JavaScript functions:
.NET Assembly Information
Assembly | accoremgd.dll |
Namespace | Autodesk.AutoCAD.ApplicationsServices.Core |
Class | Application |
Execute JavaScript functions using this method:
void LoadJSScript(System.Uri uriOfHTML)
Register a callback for the JavaScript function using:
void DefunJS(String name, JsCallbackType callback)
Where
jsCallbackType
is defined as:typedef JSON (*JsCallbackType)(const JSON* params)
AutoLISP
Execute JavaScript functions using the COMMAND
function and WEBLOAD command:
(command "._webload" uriOfHtml)