Author Topic: Autolisp Conversion Functions Graphic  (Read 2998 times)

0 Members and 1 Guest are viewing this topic.

Ben Clark

  • Newt
  • Posts: 94
Autolisp Conversion Functions Graphic
« on: January 23, 2018, 03:29:49 PM »
Anybody else make anything like this?


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Autolisp Conversion Functions Graphic
« Reply #1 on: January 23, 2018, 03:33:09 PM »
mine was a gif
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Ben Clark

  • Newt
  • Posts: 94
Re: Autolisp Conversion Functions Graphic
« Reply #2 on: January 23, 2018, 03:35:15 PM »
mine was a gif

Is that a knock at my png file size being larger than necessary?

Also: care to share?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Autolisp Conversion Functions Graphic
« Reply #3 on: January 23, 2018, 04:14:52 PM »
Is that a knock at my png file size being larger than necessary?

naw, mere frivolity

Also: care to share?

I doubt I've anything new to share: numeric / string conversions have been posted ad nauseum to the swamp for 15 years.

{shrug}
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Ben Clark

  • Newt
  • Posts: 94
Re: Autolisp Conversion Functions Graphic
« Reply #4 on: January 23, 2018, 04:33:59 PM »
Yea
I doubt I've anything new to share: numeric / string conversions have been posted ad nauseum to the swamp for 15 years.

I figured this was the case.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Autolisp Conversion Functions Graphic
« Reply #5 on: January 23, 2018, 04:48:05 PM »
If you search for either of these terms (rtos itoa distof) there's an ark full of hits:

For example, Stringless Rounds.

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Autolisp Conversion Functions Graphic
« Reply #6 on: January 23, 2018, 05:59:54 PM »
IMO, the function names already give away their purpose -

rtos     =   Real     to String
atof     =   ASCII    to Float
distof   =   Distance to Float
angtos   =   Angle    to String
angtof   =   Angle    to Float
itoa     =   Integer  to ASCII
atoi     =   ASCII    to Integer


Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Autolisp Conversion Functions Graphic
« Reply #7 on: January 23, 2018, 06:24:02 PM »
To extend a bit Lee's answer, you might want to check the methods of the utility object:

Code: [Select]
_$ (vlax-dump-object (vla-get-Utility (vla-get-ActiveDocument (vlax-get-acad-object))) t)
; IAcadUtility: A series of methods provided for utility purposes
; No properties
; Methods supported:
;   AngleFromXAxis (2)
;   AngleToReal (2)
;   AngleToString (3)
;   CreateTypedArray (3)
;   DistanceToReal (2)
;   GetAngle (2)
;   GetCorner (2)
;   GetDistance (2)
;   GetEntity (3)
;   GetInput ()
;   GetInteger (1)
;   GetKeyword (1)
;   GetObjectIdString (2)
;   GetOrientation (2)
;   GetPoint (2)
;   GetReal (1)
;   GetRemoteFile (3)
;   GetString (2)
;   GetSubEntity (5)
;   InitializeUserInput (2)
;   IsRemoteFile (2)
;   IsURL (1)
;   LaunchBrowserDialog (6)
;   PolarPoint (3)
;   Prompt (1)
;   PutRemoteFile (2)
;   RealToString (3)
;   SendModelessOperationEnded (1)
;   SendModelessOperationStart (1)
;   TranslateCoordinates (5)
T
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Ben Clark

  • Newt
  • Posts: 94
Re: Autolisp Conversion Functions Graphic
« Reply #8 on: January 24, 2018, 08:57:35 AM »
IMO, the function names already give away their purpose -

rtos     =   Real     to String
atof     =   ASCII    to Float
distof   =   Distance to Float
angtos   =   Angle    to String
angtof   =   Angle    to Float
itoa     =   Integer  to ASCII
atoi     =   ASCII    to Integer


They indeed do. The confusing thing to me is the usage of two different terms for strings and reals. A real could either be r (real) or f (float); a string could either be s (string) or a (ascii). This is probably the most accurate way to represent it, but that doesn't help my memorization.

I'm sure those that engage in autolisp often enough have these pretty well memorized. I myself needed a graphic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Autolisp Conversion Functions Graphic
« Reply #9 on: January 24, 2018, 10:58:48 AM »
Does this help?

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Autolisp Conversion Functions Graphic
« Reply #10 on: January 24, 2018, 02:21:19 PM »
Real, float, oogaboogavalue... doesn't matter what the function is named.  Same thing with strings.  Just because it's (atof ...) instead of (stor ...) doesn't change anything.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Ben Clark

  • Newt
  • Posts: 94
Re: Autolisp Conversion Functions Graphic
« Reply #11 on: January 24, 2018, 04:53:42 PM »
Real, float, oogaboogavalue... doesn't matter what the function is named.  Same thing with strings.  Just because it's (atof ...) instead of (stor ...) doesn't change anything.

Of course it doesn't change anything programmatically.

My point is that it makes the conversion functions hard to memorize, hence the info-graphic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Autolisp Conversion Functions Graphic
« Reply #12 on: January 25, 2018, 05:38:03 AM »
I screenshot-ed Lee's post, and after that Michael posts a sweet short reference!  :-D
Maybe using a set of custom functions with different names would help (but that might be be a bad habit) :
Code: [Select]
; d - distance (string)
; a - angle
; s - string
; r - real
; i - integer
(setq
  d->r distof ; Dist to Float   | (distof str [mode])
  a->r angtof ; Angle to Float  | (angtof str [units])
  a->s angtos ; Angle to String | (angtos angle [unit [precision]])
  s->r atof   ; ASCII to Float  | (atof str)
  r->s rtos   ; Real to Str     | (rtos real [mode [precision]])
  i->s itoa   ; Int to ASCII    | (itoa int)
  s->i atoi   ; ASCII to Int    | (atoi str)
); setq

BTW there are also vl-prin1-to-string read prin(c/1/t) functions.



I'm sure those that engage in autolisp often enough have these pretty well memorized. I myself needed a graphic.

This is true, one just have to code alot to get used.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Autolisp Conversion Functions Graphic
« Reply #13 on: January 25, 2018, 07:58:44 AM »
Nice idea but I honestly think it’s better to just learn the proper function names. There are far bigger hurdles in one’s programming journey. Syntactic misdirection is not empowering nor does it make debugging a joy. /2’
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst