Share

JavaScript Reference Guide

This guide documents the JavaScript Application Programming Interface (API) for AutoCAD.

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:

registerCallback(string name, callback)

C++ API syntax and description

Acad::ErrorStatus acjsLoadJSScript(const ACHAR* uriOfHTML)

Loads a JS file into a hidden window and executes the Javascript. This function is also exposed as the WEBLOAD command in AutoCAD.

Acad::ErrorStatus acjsDefun(const ACHAR* name, JsCallbackType callback);

Registers a callback that JavaScript code can call.

Where JsCallbackType is defined as follows:

typedef  JSON (*JsCallbackType)(const JSON* params)

Where JSON is defined as follows:

JSON is a class/structure type that can represent JSON in C++.

.NET API syntax and description

.NET Assembly Information

Assembly accoremgd.dll
Namespace Autodesk.AutoCAD.ApplicationsServices.Core
Class Application
void LoadJSScript(System.Uri uriOfHTML)

Loads the JS file specified and executes the JavaScript code.

If you want to call .NET function in JavaScript, you can define the function in .NET using this syntax:

[JavaScriptCallback("DotNetCallbackFunc")]
  public string DotNetCallbackFunc(string json)

Where DotNetCallbackFunc is the user defined function.

AutoLISP

(command "._webload" uriOfHtml)

Loads the JS file and executes the JavaScript code.

Was this information helpful?