TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: the7347 on May 08, 2015, 03:29:29 PM

Title: get the coordinates of a line created with the command "line"
Post by: the7347 on May 08, 2015, 03:29:29 PM
Simply I can not get the entity store just after creating it with the command "line". followed by entmake I can do it with (setq ent (entlast)), but it does not work after using the command "line".

Someone has the solution...

or could help to create a line that has the second coordinate as a string, I mean in this way:

Code - Auto/Visual Lisp: [Select]
  1. (setq P1 (getpoint "1st. point:"))
  2. (setq P2 (strcat "@" Dist "<" deg "d" min"'" sec "\""))
  3. (entmake (list '(0 . "LINE")(cons 10 P1)(cons 11 P2)))
this fails, the P2 no is a bad DXF group: (11 .  .........

Help please.

Title: Re: get the coordinates of a line created with the command "line"
Post by: tombu on May 08, 2015, 03:42:47 PM
Take a look at the polar function for getting P2
http://help.autodesk.com/view/CIV3D/2016/ENU/?guid=GUID-6A84BFD3-8788-45B1-AB52-5E83F0C5286E
Title: Re: get the coordinates of a line created with the command "line"
Post by: roy_043 on May 08, 2015, 03:48:16 PM
... I can do it with (setq ent (entlast)), but it does not work after using the command "line".
This is not correct, there must be another issue.

BTW: You are using a variable 'min'. This is unwise as there is a Lisp function called 'min'.
Title: Re: get the coordinates of a line created with the command "line"
Post by: the7347 on May 08, 2015, 03:57:24 PM
Take a look at the polar function for getting P2
http://help.autodesk.com/view/CIV3D/2016/ENU/?guid=GUID-6A84BFD3-8788-45B1-AB52-5E83F0C5286E
I can not to use the polar function because I'm using the angle in DDMMSS format as string.

Take a look at the polar function for getting P2
http://help.autodesk.com/view/CIV3D/2016/ENU/?guid=GUID-6A84BFD3-8788-45B1-AB52-5E83F0C5286E
Thanks for the warning, this is just an example I'm using the word "minutes"

Thanks for the quick response
Title: Re: get the coordinates of a line created with the command "line"
Post by: PKENEWELL on May 08, 2015, 04:21:03 PM
Simply I can not get the entity store just after creating it with the command "line". followed by entmake I can do it with (setq ent (entlast)), but it does not work after using the command "line".

Someone has the solution...

or could help to create a line that has the second coordinate as a string, I mean in this way:

Code - Auto/Visual Lisp: [Select]
  1. (setq P1 (getpoint "1st. point:"))
  2. (setq P2 (strcat "@" Dist "<" deg "d" min"'" sec "\""))
  3. (entmake (list '(0 . "LINE")(cons 10 P1)(cons 11 P2)))
this fails, the P2 no is a bad DXF group: (11 .  .........

Help please.

You cannot set the variable P2 to a command string because ENTMAKE only accepts a list of numbers representing x y and z. Tombu is correct that you should use the POLAR function to return a real point list.

Also - you will need to convert the Deg / min / sec value to a radians (Hint: Look up the function ANGTOF) for the polar function. See example below::

Code: [Select]
(setq angInDegress (Angtof (strcat deg "d" min "'" sec "\"") 1) ;convert deg min sec to RADIANS.

(setq p2 (polar p1 angleInDegrees dist))

EDIT: Corrected my Previous Message as ANGTOF already returns radians.
Title: Re: get the coordinates of a line created with the command "line"
Post by: the7347 on May 08, 2015, 04:29:49 PM
Now I have a few problems, I need to determine the coordinates for the hands of relog (ANGDIR 1) and polar does not respect this

The angle is calculated regardless ANGBASE and ANGDIR,

Look the attachment When the angle is 90 degrees
Title: Re: get the coordinates of a line created with the command "line"
Post by: roy_043 on May 08, 2015, 04:59:49 PM
The angtof function respects both the ANGBASE and the ANGDIR*. Maybe your problem is caused by a UCS that is not the WCS?

* Note: I use BricsCAD instead of AutoCAD.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / dist deg mnt sec pt)
  2.   (setq dist "1")
  3.   (setq deg "90")
  4.   (setq mnt "0")
  5.   (setq sec "0")
  6.   (setq pt (getpoint "First point:"))
  7.     (list
  8.       '(0 . "LINE")
  9.       (cons 10 pt)
  10.       (cons
  11.         11
  12.         (polar
  13.           pt
  14.           (angtof (strcat deg "d" mnt "'" sec "\"") 1)
  15.           (distof dist)
  16.         )
  17.       )
  18.     )
  19.   )
  20. )
Title: Re: get the coordinates of a line created with the command "line"
Post by: Lee Mac on May 08, 2015, 06:18:52 PM
The angtof function respects both the ANGBASE and the ANGDIR*. Maybe your problem is caused by a UCS that is not the WCS?

* Note: I use BricsCAD instead of AutoCAD.

Confirmed in AutoCAD:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setvar 'angdir 0)
  2. 0
  3. _$ (setvar 'angbase 0.0)
  4. 0.0
  5. _$ (angtof "90d0'0\"" 1)
  6. 1.5708
  7. _$ (setvar 'angbase (/ pi 3.0))
  8. 1.0472
  9. _$ (angtof "90d0'0\"" 1)
  10. 2.61799
  11. _$ (setvar 'angdir 1)
  12. 1
  13. _$ (angtof "90d0'0\"" 1)
  14. 5.75959
Title: Re: get the coordinates of a line created with the command "line"
Post by: the7347 on May 08, 2015, 11:33:07 PM
I totally agree with what they say, excuse my bad English. I mean I need the angle for polar coordinate start from ANGBASE and clockwise,like the example I gave in the image. But using polar, the angle always starts from the x axis and counterclockwise :/
Title: Re: get the coordinates of a line created with the command "line"
Post by: roy_043 on May 09, 2015, 04:09:58 AM
But using polar, the angle always starts from the x axis and counterclockwise :/
That is true. But the angtof function will correctly translate the angle. See the test function in my previous post.
Title: Re: get the coordinates of a line created with the command "line"
Post by: Lee Mac on May 09, 2015, 07:43:56 AM
But using polar, the angle always starts from the x axis and counterclockwise :/
That is true. But the angtof function will correctly translate the angle. See the test function in my previous post.

As roy has correctly noted, observe the following:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setvar 'angbase (/ pi 2.0))
  2. 1.5708
  3. _$ (setvar 'angdir 1)
  4. 1
  5. _$ (angtof "0.0")
  6. 1.5708
  7. _$ (angtof "10.0")
  8. 1.39626

With ANGBASE set to pi/2 radians (90 degrees), 0.0 rad/deg is in the positive y-axis direction; and with ANGDIR set to 1, angles increase in the clockwise direction.

As you can see from the above console output, angtof respects these system variable settings, with an input of 0.0 returning pi/2 radians or 90 degrees, and a positive angle decreases the angle in radians returned by angtof.
Title: Re: get the coordinates of a line created with the command "line"
Post by: the7347 on May 11, 2015, 11:33:50 AM
I apologize, I did not understand, now works perfectly thanks to the angtof function.

thanks a million :-D
Title: Re: get the coordinates of a line created with the command "line"
Post by: Lee Mac on May 11, 2015, 12:00:10 PM
No need to apologise - you're welcome!