AutoCAD JavaScript API not working

AutoCAD JavaScript API not working

Anonymous
Not applicable
5,659 Views
24 Replies
Message 1 of 25

AutoCAD JavaScript API not working

Anonymous
Not applicable

Hi,

 

I tried now for quite some days to load a JavaScript into AutoCAD 2016, by following this Tutorial: https://df-prod.autocad360.com/jsapi/v3/GettingStart/index.html?url=files/tutorial_palette_wrkflw.ht...

 

However, I'm able to load the html file into AutoCAD, but I cannot get any function run. The documentation on that is extremely poor, which makes it very rough for beginners to drop in. I had to change the javascript source file into src="http://app.autocad360.com/jsapi/v2/Autodesk.AutoCAD.js"

at least to be able to execute any of the commands.

But nevertheless in this example the data of the added points are not passed back from the AutoCAC Window to the html. There is actually no interaction possible.

 

Does anyone have an idea how I could proceed?

 

Many thanks in advance

0 Likes
5,660 Views
24 Replies
Replies (24)
Message 2 of 25

hgasty1001
Advisor
Advisor

Hi,

 

You can get some help from this link: AutoCAD JavaScript , Kean Walmsley has some pretty examples of that API in his blog.

 

Gaston Nunez

0 Likes
Message 3 of 25

Anonymous
Not applicable

Thank you very much, I know Kean Walmsley's blog. However, also there I can't find any solution for my issue.

Maybe I need to get back to AutoCAD 2014... **** slowly I start to remember why I actually didn't use AutoCAD for more than 4 years...

0 Likes
Message 4 of 25

hgasty1001
Advisor
Advisor

Hi,

 

I don't know much about that API, and I'm not sure if it's a complete and mature development. Do you really need that API for your problem or use case? .NET could be more productive, and there are lots of good examples, and people here in this group with very good knowledge of that API that can help you.

 

Gaston Nunez.

0 Likes
Message 5 of 25

Anonymous
Not applicable

I had some issues get the AutoCAD examples to load as well. What solve them for me is this forum post.

 

What got it working for me is

 

1) If you using the webload command to add the palette via javascript, add the palette with

 

Acad.Application.addPalette

NOT with

Acad.Application.activeDocument.addPalette // addPalette is not defined for activeDocument

If you load add the palette with .NET then this shouldn't be an issue. However, loading with javascript avoids the hassle of creating a .NET program for AutoCAD.

 

2) I downloaded the Autodesk.AutoCAD.js api from http://app.autocad360.com/jsapi/v2/Autodesk.AutoCAD.js

and replace all instances of

 

promise.success(JSON.parse(resObj.retValue));

with

 

promise.success(resObj.retValue);

This is a bug in the javascript API. resObj is the result of a call to JSON.parse, and thus is already parsed. It is not necessary for them to be parsing resObj.retValue, since that was parsed in the original call to JSON.parse.

 

Once I did the replacement, I reference my local fixed copy of the Autodesk.AutoCD.js file instead of the hosted one.

 

Hope this helps!

Message 6 of 25

Anonymous
Not applicable

I have just installed Autocad 2021 and the javascript API stopped working (the js code with html palettes in Autcad 2018 were working fine) . The debug console says:

 

Autodesk.AutoCAD.js:6012 Uncaught ReferenceError: exec is not defined

 

line 6012 is: var jsonStr = exec(JSON.stringify({...

 

It seems that AcWebBrowser.exe was replaced for a newer version in the Autocad 2021 release. Is there any workaround so that we can keep using the javascript API in Autocad 2021 with html palettes?

Message 7 of 25

CodeDing
Advisor
Advisor

@lena.talkhina ,

 

Where can we voice our opinion to Autodesk about bringing back support for Javascript API?

Message 8 of 25

lena.talkhina
Alumni
Alumni

Hello @CodeDing !

Let me check internally which options we have and will be back then

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

0 Likes
Message 9 of 25

lena.talkhina
Alumni
Alumni

Hello everyone,

 

The question here in the thread initiated an additional investigation internally at Autodesk.

I will be back with the answer as soon as it finished.

Thank you for the patience.

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

Message 10 of 25

gotMorris
Enthusiast
Enthusiast

@lena.talkhina  any update?

0 Likes
Message 11 of 25

lena.talkhina
Alumni
Alumni

@gotMorris as far as I informed the case is still under investigation. Sorry you have to wait so long, I'll take check again with our technical specialists if there any existing answer.

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

0 Likes
Message 12 of 25

lena.talkhina
Alumni
Alumni

Hello there!

I am sorry all of you have to wait for the solution.

We confirm that bug is existing and Development team will research the issue. Keep an eye on posts here for updates.

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

Message 13 of 25

Anonymous
Not applicable

Hi, what is the latest status on this issue? Has it been fixed?

Tks,

Joao

Message 14 of 25

Anonymous
Not applicable

I found that the exec() function issue happens because it was actually removed, as confirmed by the Javascript developper guide below:

 

https://help.autodesk.com/view/OARX/2021/ENU/?guid=adsk_jsdev_autocad_javascript_api_about

 

On the other hand, the acedInvokeAsync() C++ function is not working. It does return eOk, but the corresponding JavaScript function that was declared with registerCallback() is never executed.

 

Is this a known issue?

 

Regards,

Joao

0 Likes
Message 15 of 25

Anonymous
Not applicable

Just a correction: the C++ function that is not working is acjsInvokeAsync().

0 Likes
Message 16 of 25

Anonymous
Not applicable

To get JavaScript working inside AutoCAD, we’ve integrated the open source Chromium component into the product. This gives us the all-important V8 environment for executing JavaScript as well as a WebKit-based browser for rendering HTML content. You may have heard that Google is forking WebKit to continue development on their Blink rendering engine. This shouldn’t change anything for us, moving forwards: we may well choose to – at some point – move to a newer version of Chromium, and it’ll happen to be based on Blink. https://forpc.onl/snaptube-for-pc jiofilocalhtml

0 Likes
Message 17 of 25

d3nis.code
Observer
Observer

when I try something like Acad.Editor.executeCommand('CIRCLE')i am getting that Uncaught (in promise) ReferenceError: exec is not definederror. I found this on AutoCAD 2021 help but i don't understand how to use it

 

The exec function has been deprecated from the API and synchronous calls from the JavaScript API are no longer supported. Use the execAsync() function for asynchronous calls.

 

https://help.autodesk.com/view/OARX/2021/ENU/?guid=adsk_jsdev_autocad_javascript_api_about

 

 

0 Likes
Message 18 of 25

Anonymous
Not applicable

The problem is that the code inside the JavaScript API (v3) found here: https://df-prod.autocad360.com/jsapi/v3/Autodesk.AutoCAD.js, still makes use of the exec function, and since the exec function has been deprecated in version 2021 of Autocad, the API will not work properly in this version.

 

Autodesk needs to release a new API version (v4) that does not make use of the exec function inside the code, in order to work with the JS API and Autocad 2021.

0 Likes
Message 19 of 25

Anonymous
Not applicable

WHERE NEW STATUS ABOUT IT ?!?!??!

0 Likes
Message 20 of 25

lena.talkhina
Alumni
Alumni

Hello @Anonymous !

 

Welcome to Autodesk Community. Great to see you here.
Thank you for bringing this topic up.

Our teams are still working on the issue. We will inform you here when the solution is released.

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian