.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get the Object Properties by Javascript

2 REPLIES 2
Reply
Message 1 of 3
qjchen
1209 Views, 2 Replies

How to get the Object Properties by Javascript

How to get the Object Properties by Javascript

Hello 🙂

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]

2 REPLIES 2
Message 2 of 3
philippe.leefsma
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

Message 3 of 3
qjchen
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

Tags (2)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost