Jump to content

Coordinates to string convertion?


Attila The Gel

Recommended Posts

Hi,

 

I'm stuck again trying to recreate a lisp & dcl that someone else made where I work?

for learning purpose! I don't have the source code so its a perfect example to start with from scratch.

 

I would like to return the coordinates into a form to a text, key:"txt(xyz)".

 

;; dialog is hidden when I click a button to get point
(setq [color=seagreen]CRDNTS [/color](getpoint "\nInsertion point: ")) [color=seagreen];=example (102.08 25.85 0.0)[/color].

;; Dialog is reloaded and then...
(set_tile "txt(xyz)" [color=seagreen]CRDNTS [/color]) [color=red]not working because its not a string[/color]?

 

I tried some conversion but couldn't get it to work? Do I need to extract the x,y and z and then list it back together? or is there a simple solution to get this done.

 

thx.

Link to comment
Share on other sites

The point returned by GETPOINT is in fact a list of 2 or 3 items. You should decompose it and build the string.

(strcat (rtos (car CRDNTS) 2 3) ", " (rtos (cadr CRDNTS) 2 3))

However it is a little unusual to display the point into an edit box like above - most common is to have fields for each coordinate. The first approach can pose input difficulties to user.

Link to comment
Share on other sites

You're right about the edit box and displaying the point in it,

 

but I'm trying to get it into a text field and its just to inform the user that the insertion point is selected and it's not (0.0 0.0 0.0).

NTO DCL PIC.jpg

Link to comment
Share on other sites

Then set that label like this:

(set_tile [color=magenta]"labelCoordsInfo"[/color]
         (strcat "Coordinaten = (" 
                 (rtos (car   CRDNTS) 2 3) ", " 
                 (rtos (cadr  CRDNTS) 2 3) ", " 
                 (rtos (caddr CRDNTS) 2 3) ")"))

For sure, will need to replace the tile key accordingly.

Link to comment
Share on other sites

Then set that label like this:

(set_tile [color=magenta]"labelCoordsInfo"[/color]
         (strcat "Coordinaten = (" 
                 (rtos (car   CRDNTS) 2 3) ", " 
                 (rtos (cadr  CRDNTS) 2 3) ", " 
                 (rtos (caddr CRDNTS) 2 3) ")"))

For sure, will need to replace the tile key accordingly.

 

Exactly what I was looking for and even better! Thx again MSasu

Link to comment
Share on other sites

Countered another problem regarding this when loading a fresh routine. Value of CRDNTS = nil and the dialog closes with the error message bad bla bla bla nil.

so I've put it in an if:

 

  (if (= CRDNTS nil)
   
     (set_tile "labelCoordsInfo" "Coordinaten = ( 0,0 0,0 0,0 )")
   
     (set_tile "labelCoordsInfo" (strcat "Coordinaten = ( " 
                 (rtos (car   CRDNTS) 2 1) " , " 
                 (rtos (cadr  CRDNTS) 2 1) " , " 
                 (rtos (caddr CRDNTS) 2 1) " ) "))
   )

 

just in case someone is in need of this or similar things.

Link to comment
Share on other sites

You may check also the NOT function.

(if (not CRDNTS)
...

Or check the point for existency and invert the messages:

(if CRDNTS
...

Either way, make sure that the said variable is localized to don't have assigned it from previoud run.

 

May also want to reformat the default message for consistency:

(set_tile "labelCoordsInfo" "Coordinaten = ( 0.0 , 0.0 , 0.0 )")

Link to comment
Share on other sites

Hey,

 

Thanks for taking the time to reflect different possibilities and correcting typo's.

 

I'll look into the NOT function better.

 

Don't get the existence though. Could it be that (if CRDNTS actually means that CRDNTS ISNOT NIL.Equals to existence of it. Just the reverse of Not CRDNTS and that is why the message needs to be inverted?

Its just so damn short that I need to know how it works or thinks so to speak, to be able to understand it properly.

Link to comment
Share on other sites

If will test that the point is available, then the code become:

(if CRDNTS
(set_tile "labelCoordsInfo" (strcat "Coordinaten = ( " 
                                    (rtos (car   CRDNTS) 2 1) " , " 
                                    (rtos (cadr  CRDNTS) 2 1) " , " 
                                    (rtos (caddr CRDNTS) 2 1) " ) "))

(set_tile "labelCoordsInfo" "Coordinaten = ( 0.0 , 0.0 , 0.0 )")
)

Link to comment
Share on other sites

Don't get the existence though. Could it be that (if CRDNTS actually means that CRDNTS ISNOT NIL.Equals to existence of it.

 

In AutoLISP, any value that is not equal to nil is considered a 'true' value and will validate the test expression of an if, cond, while statement etc.

 

Hence for the test expression:

 

([color=blue]if[/color] [color=darkred]CRDNTS[/color]
   ...

The symbol CRDNTS is evaluated and if such symbol has been assigned a value other than nil, the test expression is validated and the 'then' expression of the if statement will be evaluated.

Link to comment
Share on other sites

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...