.NET

Reply
New Member
qjchen
Posts: 2
Registered: ‎09-26-2013
Message 1 of 3 (208 Views)

How to get the Object Properties by Javascript

208 Views, 2 Replies
09-26-2013 04:30 AM

How to get the Object Properties by Javascript

Hello :smileyhappy:

I just started to learn javascript programming for AutoCad.

I found that it is hard for me to get the property of selected object by Javascript.

Just like the following code, I can get the object ID of each selected entity. But when I want to get the property of the DBEntity, just the center of a Circle entity, or the Position.X of a Point, I dont know how to Continue. The getExtent is the only function that I can writeout the property, it is List in the develop guide. But how about the other properties, could you please help me? Thank you very much.

 

[code]

function setPromptSelectionOptions(options) {
options.messageForAdding = "\n Please select some entities"
}
function onCompletePromptSelectionResult(jsonPromptResult) {
var resObj = JSON.parse(jsonPromptResult);
if (resObj) {
if (resObj.status == 5100) { // normal (point selected/entered)
var x=JSON.stringify(resObj);
write(x);
var allselect=resObj.value
var i=0;
for (var x in allselect)
{
var z=allselect[i];
write(JSON.stringify(z));
var entity = new Acad.DBEntity(z.objectId);
// var ext = entity.getExtents();
write(JSON.stringify(entity));
i=i+1;
}
}
}
}
function onErrorPromptResult(jsonPromptResult) {
write("\nerror\n")
}
function promptForSelectionqjchen() {
var options = new Acad.PromptSelectionOptions();
setPromptSelectionOptions(options);
Acad.Editor.getSelection(options).then(
onCompletePromptSelectionResult,
onErrorPromptResult);
}

Acad.Editor.addCommand( "Q_CMDS", "ABC", "ABC",Acad.CommandFlag.TRANSPARENT, promptForSelectionqjchen );
write("\nRegistered abc command.\n");
[/code]

ADN Support Specialist
philippe.leefsma
Posts: 625
Registered: ‎06-02-2009
Message 2 of 3 (176 Views)

Re: How to get the Object Properties by Javascript

09-27-2013 05:13 AM in reply to: qjchen

Hi,

 

There is no way to achieve that directly from the JavaScript API. it is only the first version, so this API is not very powerful.

 

You can find the API Reference here.

 

We also produced material about it. One solution might be to use either an arx or .Net extension and pass the objectId from JavaScript to your arx/.Net method in order to retrieve the properties you are looking and return that to JavaScript.

 

Extending the JavaScript API from arx/.Net is discussed in my DevTV.

 

Another useful link:

 

http://through-the-interface.typepad.com/through_the_interface/2013/05/complementing-autocads-javasc...

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

New Member
qjchen
Posts: 2
Registered: ‎09-26-2013
Message 3 of 3 (159 Views)

Re: How to get the Object Properties by Javascript

09-27-2013 04:49 PM in reply to: philippe.leefsma

Hi, Philippe

 

Thank you very much for your reply. Therefore I won't stick to solve it in pure JavaScirpt. I will try to use .Net to complement the getting and drawing entity for Javascript API.


Just like Kean published here
http://through-the-interface.typepad.com/through_the_interface/2013/05/complementing-autocads-javasc...


Surely I hope this will be included in the subsequent Autocad Javascript API version.


Your article and its attachment in "Getting Started with JavaScript API on AutoCAD 2014" is the most important material for me to get into JAVASCRIPT programming on AUTOCAD. I test all the examples in AcHTML and learn a lot. Certainly, I am also learing the useful examples shared by kean.


What I think that the funny things JAVASCRIPT giving us, have several aspects, such as Interface programming (html), easy to using bundles of libraries of JAVASCRIPT in internet like D3 or Raphaël or else, publishing the source codes online.

 

I have just wrote several Javascript codes, just like using tree menu to manage my customized command, using D3.js to draw delaunay figure, etc. It give me a different feeling than Lisp and .Net and I enjoy it.


Thanks again.

Best Regards.

qjchen

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.