Jump to content

Recommended Posts

Posted (edited)

I want to extract values from objects such as a line, and use them as variables in Autolisp.

 

For instance, say I draw a line:

(command "line" "0,0" "@5000<37" "")

 

It will draw a line 5000 units long from the origin at an angle of 37°, to an unknown point.

 

If I inspect the properties of this line, I can find that end point END X = 4000 and END Y = 3000.

 

Is there a way to extract these values through lisp and assign them to a variable?

 

eg.

(setq endx1 ("end x value"))
     (setq endy1 ("end y value"))

 

Conversely I also want to be able to draw a line from absolute coords point1 to point2 and get the delta x and y values, as well as the length and angle.

Edited by bpdav1
Posted
I want to extract values from objects such as a line, and use them as variables in Autolisp.

 

For instance, say I draw a line: (command "line" "0,0" "@5000

 

It will draw a line 5000 units long from the origin at an angle of 37°, to an unknown point.

 

If I inspect the properties of this line, I can find that end point END X = 4000 and END Y = 3000.

 

Is there a way to extract these values through lisp and assign them to a variable?

 

eg. (setq endx1 ("end x value"))

(setq endy1 ("end y value"))

 

Conversely I also want to be able to draw a line from absolute coords point1 to point2 and get the delta x and y values, as well as the length and angle.

 

 

try reading this :

http://www.jefferypsanders.com/autolispintr_dxf.html

 

and take note of group Code 10 and 11

Posted

This ... ?

 

(command "_.line" "0,0" "@5000<37" "")
(if (setq e (entlast))
 (progn
   (setq elist (entget e))
   (setq end (cdr (assoc 11 elist)))
   (setq x_end (car end))
   (setq y_end (cadr end))
 )
)

Posted

Since you know both starting point and the polar displacement, you can calculate the target point, don't need to list it from entity:

(setq pointTemp (polar '(0 0) (* (/ 37.0 180.0) pi) 5000.0)
     endX (car  pointTemp)
     endY (cadr pointTemp))

I believe you already had this information on your other thread.

 

Also, please edit your post and add the code tags. Thank you.

Posted

This is much better and to guarantee that the last object is created and line entity .

 

(if (setq e
      (entmakex
        (list '(0 . "LINE")
          '(10 0. 0. 0.)
          (cons 11 (polar '(0. 0. 0.) (* (/ 37.0 180.0) pi) 5000.0))
        )
      )
   )
 (progn
   (setq elist (entget e))
   (setq end (cdr (assoc 11 elist)))
   (setq x_end (car end))
   (setq y_end (cadr end))
 )
)

Posted

Sorry Tharwat, but that is totally counter-productive. Why add the entity and interrogate it later when you have access to all his features at design time?!?

Even if OP was looking for such work-around, I believe that a better approach is to advice him/her to use an effective solution.

Posted
Sorry Tharwat, but that is totally counter-productive.

 

Where is the counter-productive of the code ?

Posted

Have you read my whole message?

Why add the entity and interrogate it later when you have access to all his features at design time?!?
Posted
Have you read my whole message?

 

I don't like these kinds of replies Mircea

Posted

I just pointed to you that the answer was in my previous message. Sorry if you understood me wrong.

Posted
I just pointed to you that the answer was in my previous message. Sorry if you understood me wrong.

 

It is ok ,

 

I know what you were referring to , i just added the entmakex and retrieved the needed dxf information just the same way that OP intended to do when they posted the command call of line entity , and i just replaced it with entmakex to guarantee that the last entity is in hand which is better that the use of the function entlast .

Posted

Again, your solution is impeccable if is used to just demonstrate a principle – coordinates extraction from a line entity. From a practical point of view, please imagine how OP’s code will look if he/she need to draw a contour made of ~100 lines and retain the points for further processing. This is why I believe that this approach is counter-productive.

My opinion is that a less experienced user should be adviced to switch to effective solutions instead of encouraging him to persist to not required work-arounds that will overcomplicate his code. I may be wrong, but this is what I fell.

Posted

One more time ,

 

You have an idea in mind and built your thoughts on it , my example was to give a better way than the use of enlast function and command call is well .

Posted

Tharwat,

 

The point that I believe Mircea is making is that in your code you have already calculated the line endpoint in order to construct the line, and are then querying the DXF data of the line to retrieve the endpoint that you already have.

 

The OP was using the method of constructing the line to obtain the endpoint since evidently he/she was unaware of the polar function (even though this was suggested in a previous thread, by Mircea no less).

Posted

I do agree , and to go further in explanations won't hurt at all , IMO at least . ;)

Posted (edited)

Guys... I don't think its really appropriate to fill two pages of a public thread with a personal discussion, especially between senior members of the forum, who should set a good example.

 

I would really appreciate if you didn't do it in my posts, at any rate.

 

Thank you to everyone who posted constructive, helpful posts, and I appologise for not posting code in the code tags. I have gone and changed this in all my previous posts.

Edited by bpdav1
Posted
Guys... I don't think its really appropriate to fill two pages of a public thread with a personal discussion, especially between senior members of the forum, who should set a good example.

 

I would really appreciate if you didn't do it in my posts, at any rate.

 

Thank you to everyone who posted constructive, helpful posts, and I appologise for not posting code in the code tags. I have gone and changed this in all my previous posts.

 

If you hadn't realised, the 'personal discussion' was actually for your benefit, to explain why one particular method is more effective than another. But since you had clearly ignored the previous advice given in your last thread, we are evidently wasting our time in trying to help you.

Posted

Nice reply Lee . :thumbsup:

 

@Mircea , if you took the discussion as a personal attack or so as the following guy says , i have to apologize from you .:oops:

 

And for you bb , if you didn't get the benefit of that constructive discussion , it really means that we are wasting our time with you and with your unaccepted way of talking .

 

Guys... I don't think its really appropriate to fill two pages of a public thread with a personal discussion, especially between senior members of the forum, who should set a good example.

 

I would really appreciate if you didn't do it in my posts, at any rate.

 

Thank you to everyone who posted constructive, helpful posts, and I appologise for not posting code in the code tags. I have gone and changed this in all my previous posts.

Posted

@Lee Mac: Thank you for your intervention.

 

@Tharwat: Please don't be afraid, I really didn't considered any of your posts in such way. If you have felt that on mines, then I have to apologize too.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...