Javascript API for AutoCAD give Beginners a Rough Start??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!!