Javascript API for AutoCAD give Beginners a Rough Start??

Javascript API for AutoCAD give Beginners a Rough Start??

arionXMSF7
Contributor Contributor
8,585 Views
16 Replies
Message 1 of 17

Javascript API for AutoCAD give Beginners a Rough Start??

arionXMSF7
Contributor
Contributor

Hi, 

 

I'm a web developer with AutoCAD and AutoCAD customization experience and recently wanted to integrate AutoCAD with a remote site I have a database hosted on. I'm nowhere near that aspect of things as I've found integrating many things from the AutoCAD API and tutorial examples to not be a smooth experience at all. I'm looking to see who might point me to a more focused network of peers or forum that can assist in technical details. For example, the Javascript for AutoCAD has been out since 2014 I believe, but there is no dedicated forum group here in the Autodesk Community. Additionally, I'll post my questions here. If anyone out there can answer some or all of these, or point me to the right place where I can get these answered, I'd be very grateful! 

 

As givens: 

- I host a localhost on my Windows machine using WAMP and call my test files from http://acadjs.local/filename.js. This part works and I've confirmed it. 

- I use AutoCAD 2016 and am installing the JS files using WEBLOAD. My TRUSTEDPATHS are fine. 

 

QUESTIONS: 

#1:

In this example "To Capture an Image Preview" (https://df-prod.autocad360.com/jsapi/v3/GettingStart/files/tutorial_image_wrkflw.htm), it makes reference to calling Acad.Application.activedocument.addPalette(). The API Reference at https://df-prod.autocad360.com/jsapi/v3/docs/contents.html confirms this API function. However, it simply did not work. I finally resorted to calling Object.getOwnPropertyNames(Acad.Application.activedocument) and Object.getOwnPropertyNames(Acad.Application) and discovered the addPalette() function is in Acad.Application, not Acad.Application.activedocument! After changing the code to Acad.Application.addPalette() it worked. I would like to confirm whether I found a workaround or if there was something else I should have done to make it work the way the API references it. 

 

#2

I tried this example "To Capture an Image Preview(https://df-prod.autocad360.com/jsapi/v3/GettingStart/files/tutorial_image_wrkflw.htm). It did not work. After banging my head, I looked in the Autodesk.AutoCAD.js file itself to see where the error was coming from. Turns out its on Line 4580. promise.success(JSON.parse(resObj.retValue)); is called, but just before that on line 4587 this is called: var resObj = JSON.parse(result); That seems to imply that the string parsed to a JSON Object has again been parsed a second time. I replaced line 4580 with promise.success(resObj.retValue) and it worked! Why would this be, and why don't any of the examples seem to work out the gate? Since resObj.retValue is binary data result, parsing it as JSON obviously is not going to work and is why it failed. However, this is in the core library, which I HAD TO DOWNLOAD THE Autodesk.AutoCAD.js  FILE AND EDIT IT to make it work. I've noticed this same phenomenon on other ActiveDocumentInterop.XYZ functions. 

 

#3

I'm trying to implement the example at (http://through-the-interface.typepad.com/through_the_interface/2013/03/zooming-to-an-autocad-entity-...). I load it and there are no errors. I then type the "ZEN" command per the example and click the element and nothing happens. There is no error handling. I then wrapped it in an HTML palette so I can use the F12 testing suite and see the error: Uncaught Error: Error: add command failed. I dug into that and again the error happens on Line 3943 in Autodesk.AutoCAD.js. There is no reason given for it to fail, it just fails. Again, this is the core library causing the problem, which is nerve wracking. 

 

#4

When loading an html file into an AutoCAD palette, we have the luxury of hitting F12 and using the debugger to check the console for errors. However, if you just load a JS file without an html wrapper around it, there is no debugger console to test your code. For example, there is nowhere for console.log() to echo out. Is there another feature I am not aware of to test straight JS files, or do I have to wrap it in an HTML palette just to be able to use the debugger? If not, is there a Javascript command to write text to the command console so I can read it? You can't copy text in alert boxes. 

 

#5

Is there any interface similar to VLIDE for Javascript other than the F12 debugger for HTML palettes? 

 

 

#6

I'd like to use node.js as my framework, and require('Autodesk.AutoCAD.js') from there. Is that possible to include in an AutoCAD Javascript? If so, can I use ECMAScript 6 with associated node plugins to use with AutoCAD? 

 

 

#7 

Is there ANY other resource out there other than this forum and Through The Interface (website, book, community) specifically for AutoCAD Javascript programming? 

 

I'm sure plenty of other questions will arise in my journey, but suffice it to say, it appears to me that following the examples step by step, not only in the official tutorials (which are pretty slim) and the example given on Through The Interface, do not appear to work. I'm sure they work on the writers' local machines, but not on mine. I'm at a loss for continuing with confidence, as right now I'm not sure if there is something on my machine I need to change or if the API itself is buggy and untested. Any help at all would be greatly apprecaited!! 

8,586 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable

I'd really like to see some answers to this question. It's been a few months since the original post was made, and this post was the only resource I could find to get a sample javascript app to work inside of AutoCAD. The examples still have errors in them, and the core javascript library still has the same errors described in the original post. I won't be able to use the javascript API anytime soon since the offical js file for the API won't even load the extremely simple samples posted by autodesk.

 

0 Likes
Message 3 of 17

arionXMSF7
Contributor
Contributor
Hi there,

After doing more sleuthing and questioning members of AutoDesk, I was told in no certain terms that the Javascript API never really caught on and is not being supported nor does it have an active interested community. Their links on Google are still active though which is very misleading and frustrating, as I see you have noticed.

I was advised to put my adversion to dot net aside and use that library for the most lively community of AutoDesk programmers and solutions, and of course a functioning API. Too bad since Javascript has seen a huge universal rebirth recently and I'd love if it was fully supported and embraced by the AutoDesk community.
Message 4 of 17

Anonymous
Not applicable

That really is a shame. Especially since I was just able to set up a live coding environment using light table. It's possible to write javascript, html, and css code in the editor, then evaluate it in the ACAD browser with a single hot key. The feedback loop is so much quicker compared to coding in .NET where you basically have to start a new instance of AutoCAD every time a change to the code is made. With javascript (and HTML pallets), I can just push the changes from the editor and see them instantly. Guess I'll just have to go back to .NET. Oh well. Thanks for the response!

0 Likes
Message 5 of 17

dbroad
Mentor
Mentor

If blame is of any importance, certainly lack of good documentation and samples that actually worked as advertised was a critical part of causing lack of interest on the part of the community.  I like programming in Javascript but when the sample files and documentation don't work and, as you say, when there is no support community, it's easier to switch to another language to accomplish the immediate task.

 

IMO, this is shortsighted on the part of AutoDesk, since in the not too distant future, as Web speeds increase, performance might actually be better from web based application with cloud servers, where Javascript is a native.  Support for Angular JS should also be considered.  Palettes as web page dialogs is a good concept. They really should consider revisiting their decision to withdraw support.

Architect, Registered NC, VA, SC, & GA.
Message 6 of 17

Anonymous
Not applicable

@dbroad, Angular JS applications should work just fine. Since AutoCAD is just loading up an instance of Google Chrome, you can load anything that works in Chrome, for the most part. Here's a screen shot of me loading up weather.com in AutoCAD, which was written with AngularJS.

angular-in-acad.pngNot only can it do that, but it can also load javascript that was transpiled from other languages. AutoDesk admitted they were using Typescript to write the javascript API (source). There are a lot of other languages too. I'm working on getting a basic clojurescript application to load up in AutoCAD.

 

I'm really hoping they fix all these public bugs in their example code and continue supporting their javascript API.

Message 7 of 17

dbroad
Mentor
Mentor
Thanks. Nice to know.
Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 8 of 17

john.uhden
Mentor
Mentor

Professor of Architectural Technology, eh?  Like Dr. Henry Jones was just a professor of anthropology, right?  Or was that archaeology, or maybe cinematography?  Maybe you really get your answers from a crystal skull?

John F. Uhden

0 Likes
Message 9 of 17

dbroad
Mentor
Mentor

That would be fun.  No digging around in caves for me though.  🙂

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 10 of 17

john.uhden
Mentor
Mentor
Aw, c'mon.
It's as easy as (tblobjname "block" "Map_Room").

John F. Uhden

0 Likes
Message 11 of 17

Anonymous
Not applicable

Is anyone aware if there are an news from Autodesk for future of JavaScript API? 

 

JS API looks really promising and we are just starting project of integration of WEB-based platform with AutoCad and as we will invest a significant amount of our time into this it is bit frightening not to be sure if this JavaScript API is "dead" project at AutoDesk.

 

 

Message 12 of 17

Anonymous
Not applicable

I would like to know too, cuz I'm going to use Javascript for later project.

It's bad when they stop updating Autocad Javascript API.

Message 13 of 17

Anonymous
Not applicable

Did you ever get an answer to this? I'm also experimenting with using the Javascript API and having similar issues. I've contacted support today but haven't heard back from them yet. I'm hoping to use the Javascript API just to avoid WPF and Windows Forms in making a UI.

Message 14 of 17

CodeDing
Advisor
Advisor

I bumped an old post recently too asking about it and it gets avoided like the plague. Didn't know what avenue to contact AutoCAD to get a response either so hopefully you'll have better luck than I.

Best,

~DD

0 Likes
Message 15 of 17

gotMorris
Enthusiast
Enthusiast

I would like to do the same.

0 Likes
Message 17 of 17

julio.torres.c
Explorer
Explorer

Hi, I'm a software developer trying to work on a large project for my company, using the js api.

Since is well known that the api is transpiled to js with typed jsdocs, I don't know how could be to release at least the Typescript definitions for production development with de js api?

 

0 Likes