Author Topic: vla-AngleToReal  (Read 2925 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Guest
vla-AngleToReal
« on: September 18, 2012, 01:07:56 PM »
can someone help me understand what I am doing wrong?

Code: [Select]
(defun test ( str / util strReal) (vl-load-com)

  (setq util (vla-get-utility (vla-get-activedocument (vlax-get-acad-object)))
strReal (vla-AngleToReal str acDegrees)
  )
 
  (print strReal)

(princ)
)

This is what I get back

Quote
Command: (test "45")
*Cancel*
bad argument type: VLA-OBJECT "45"

I don't find much examples for this code
Thanks

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: vla-AngleToReal
« Reply #1 on: September 18, 2012, 01:15:50 PM »
(vla-AngleToReal UTIL str acDegrees)

cadman6735

  • Guest
Re: vla-AngleToReal
« Reply #2 on: September 18, 2012, 01:21:33 PM »
Doh....

Thank you ElpanovEvgeniy

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: vla-AngleToReal
« Reply #3 on: September 18, 2012, 01:26:16 PM »
Or just use angtof   :-)

Code - Auto/Visual Lisp: [Select]
  1. (angtof <string> [units])

cadman6735

  • Guest
Re: vla-AngleToReal
« Reply #4 on: September 18, 2012, 01:40:07 PM »
Yes, I found the angtof function here: 
Quote
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/vla-angle-to-real-arguments/td-p/896865,
which this guys seems to be missing the util as well
thanks for the alternative Lee, this always helps. :lol:

Quick question, I was expected to get 45 in degrees, the string seems to be converting to radians for acDegrees?  Now what do I not understand?

I know how to convert just trying to understand...

Thanks

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: vla-AngleToReal
« Reply #5 on: September 18, 2012, 01:50:10 PM »
Quick question, I was expected to get 45 in degrees, the string seems to be converting to radians for acDegrees?  Now what do I not understand?

The angtof function will always output the result in radians.

From the Visual LISP IDE Help Documentation:

Quote from: VLIDE Help Documentation
angtof
 
Converts a string representing an angle into a real (floating-point) value in radians.

string
A string describing an angle based on the format specified by the mode argument.

units
Specifies the units in which the string is formatted.

Hence:

Code - Auto/Visual Lisp: [Select]
  1. _$ (angtof "45" 0)
  2. 0.785398

Will convert the string representing 45 degrees into radians (pi/4 = 0.7853...).

The vla-angletoreal method is the equivalent ActiveX method for this AutoLISP function and operates in exactly the same way.


cadman6735

  • Guest
Re: vla-AngleToReal
« Reply #6 on: September 18, 2012, 02:20:19 PM »
I am not sure how to approach this question so bare with me...

If I use
Code: [Select]
strReal (vla-AngleToReal util str acDegrees) with my string being "45" I get 0.785398

If I use
Code: [Select]
strReal (vla-AngleToReal util str acRadians) with my string being "45" I get 1.0177

None of this is what I would expect, as before I would expect acDegrees to return 45 and acRadians to return 0.785398

What is the point of:
acDegrees = 0.785398
acDegreesMinutesSeconds = doesn't seem to be recognized
acGrads = 0.706858
acRadians = 1.0177

There is a concept I am missing

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: vla-AngleToReal
« Reply #7 on: September 18, 2012, 02:35:47 PM »
Remember:

The angtof function will always output the result in radians.

Hence:

Code - Auto/Visual Lisp: [Select]
  1. _$ (angtof "45" acdegrees)
  2. 0.785398

As 45.0 degrees = 0.7853 radians

Code - Auto/Visual Lisp: [Select]
  1. _$ (angtof "45" acradians)
  2. 1.0177

As 45 radians = 1.0177 radians (since radians are 2pi periodic).

Code - Auto/Visual Lisp: [Select]
  1. _$ (angtof "45" acgrads)
  2. 0.706858

As 45 grads = 0.706858 radians (since 1 grad = pi/200 radians)

Code - Auto/Visual Lisp: [Select]
  1. _$ (angtof "45" acdegreeminuteseconds)
  2. 0.785398

Since 45 is interpreted as 45 degrees and hence returns the same as the acdegrees result.



Note that the above results are equally applicable to vla-angletoreal, but I have used angtof for convenience.


cadman6735

  • Guest
Re: vla-AngleToReal
« Reply #8 on: September 18, 2012, 03:39:19 PM »
WOW, I would never have understood that without your explanation...  I feel just a little bit smarter today.

Thanks Lee, your a good man.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: vla-AngleToReal
« Reply #9 on: September 18, 2012, 04:22:48 PM »
WOW, I would never have understood that without your explanation...  I feel just a little bit smarter today.

Thanks Lee, your a good man.

That's very fulfilling to hear that you have grasped the concept from my explanation cadman, I think I speak for all of us who try to assist others on this forum in that there is a certain satisfying sense of accomplishment when you have successfully explained something to another member causing the penny to drop in their mind.

You're very welcome  :-)
« Last Edit: September 18, 2012, 04:26:04 PM by Lee Mac »