Jump to content

6 xyz's, 5 strcats, 4 trans, 3 getpoints, 2 equations, and a partridge in a pear tree


kapat

Recommended Posts

ok, so there's not 5 strcats, but i thought the title was catchy.

 

so i've been making this NEW autolisp based off one i made last week of other people's code i cobbled together and personalized.

 

everything works EXCEPT the little equation i put in. here is the working code BEFORE i updated it:

 

(defun c:ptdif (/ p p1 p2 p3 x y z x1 y1 z1 x2 y2 z2 mdl pdiff ptcoord textloc cs_from cs_to)
(while ;start while

(setq cs_from 1)
(setq cs_to 0)

(setq p (getpoint "\nCHOOSE MODEL"))
(setq p2 (getpoint "\nCHOOSE SHOT"))
(setq textloc (getpoint p "\nPLACE TEXT"))

(setq p1 (trans p cs_from cs_to 0))
(setq p3 (trans p2 cs_from cs_to 0))

(setq x (rtos (car p1)))
(setq y (rtos (cadr p1)))
(setq z (rtos (caddr P1)))

(setq x2 (rtos (car p3)))
(setq y2 (rtos (cadr p3)))
(setq z2 (rtos (caddr p3)))

(setq ptcoord (strcat "Model:	X = "x"		Y = "y"		Z = " z))
(setq mdl (strcat "Sokkia:	X = "x2"		Y = "y"		Z = " z2))

(command p2)
(command "_leader" p textloc "" ptcoord mdl "")
(princ)
) ;end while
)

 

now that works nice and neat. The envelope i'm trying to push it just to add one more string into the text box with the differences between "x and x2" and the y's and the z's. i'll show you what i tried that didn't work. i think i was pretty close.

 

(defun c:ptdif ( / p p1 p2 p3 p4 x y z x1 y1 z1 x2 y2 z2 x3 y3 z3 mdl ptd ptcoord textloc cs_from cs_to)
(while 						;start while

(setq cs_from 1)				; these two keep it in world coords
(setq cs_to 0)

(setq p (getpoint "\nCHOOSE MODEL"))		; all my get points and prompts
(setq p2 (getpoint "\nCHOOSE SHOT"))
(setq textloc (getpoint p "\nPLACE TEXT"))

(setq p1 (trans p cs_from cs_to 0))		; the compliment to keeping it in world coords
(setq p3 (trans p2 cs_from cs_to 0))

(setq x (rtos (car p1)))			; breaks up x, y, and z from 1st getpoint
(setq y (rtos (cadr p1)))
(setq z (rtos (caddr P1)))

(setq x2 (rtos (car p3)))			; breaks up x, y, and z from 2nd getpoint
(setq y2 (rtos (cadr p3)))
(setq z2 (rtos (caddr p3)))

[b](setq x3 (- x x2))
(setq y3 (- y y2))
(setq z3 (- z z2))[/b]

(setq ptcoord (strcat "Model:	X = "x"		Y = "y"		Z = " z))
(setq mdl (strcat "Sokkia:	X = "x2"		Y = "y2"		Z = "z2))
[b](setq ptd (strcat x3 y3 z3))[/b]

(command p2)
(command "_leader" p textloc "" ptcoord mdl ptd "")
(princ)

) 						;end while
)

 

i've been googling my ass off and all my research says that my "equation" is correct, but i keep getting "error: bad argument type: numberp: "20.0212" "

 

now if i got "nil" back, i would revise things, but that tells me it stops at the equation, right?

 

sorry for my ignorance, i've just started doing this last week.

 

any help would be REALLY awesome. thanks for read this at least.

Edited by kapat
i put the new code in bold
Link to comment
Share on other sites

Welcome to CADTutor :)

 

Consider the following example:

([color=BLUE]defun[/color] c:ptdif ( [color=BLUE]/[/color] p1 p1w p2 p2w xd yd zd )
   
   [color=GREEN];; while the following expression returns a non-nil value[/color]
   ([color=BLUE]while[/color]
       [color=GREEN];; Every expression enclosed by the AND function must return[/color]
       [color=GREEN];; a non-nil value for AND to return T[/color]
       ([color=BLUE]and[/color]
           [color=GREEN];; Prompt user for points:[/color]
           ([color=BLUE]setq[/color] p1 ([color=BLUE]getpoint[/color][color=MAROON] "\nChoose Model <Exit>: "[/color]))
           ([color=BLUE]setq[/color] p2 ([color=BLUE]getpoint[/color] p1 [color=MAROON]"\nChoose Shot <Exit>: "[/color]))
       ) [color=GREEN];; end AND[/color]

       [color=GREEN];; p1 / p2 transformed from UCS to WCS:[/color]
       ([color=BLUE]setq[/color] p1w ([color=BLUE]trans[/color] p1 1 0)
             p2w ([color=BLUE]trans[/color] p2 1 0)
             [color=GREEN];; Difference in WCS X-Coord:[/color]
             xd  ([color=BLUE]-[/color] ([color=BLUE]car[/color] p1w) ([color=BLUE]car[/color] p2w))
             [color=GREEN];; Difference in WCS Y-Coord:[/color]
             yd  ([color=BLUE]-[/color] ([color=BLUE]cadr[/color] p1w) ([color=BLUE]cadr[/color] p2w))
             [color=GREEN];; Difference in WCS Z-Coord:[/color]
             zd  ([color=BLUE]-[/color] ([color=BLUE]caddr[/color] p1w) ([color=BLUE]caddr[/color] p2w)) 
       ) [color=GREEN];; end SETQ[/color]

       [color=GREEN];; Create Leader[/color]
       [color=GREEN];; "_non" = Ignore Object Snap (_non = prefix for 'none')[/color]
       ([color=BLUE]command[/color] [color=MAROON]"_.leader"[/color] [color=MAROON]"_non"[/color] p1 [color=MAROON]"\\"[/color] [color=MAROON]""[/color]
           ([color=BLUE]strcat[/color] [color=MAROON]"Model:\tX = "[/color]       ([color=BLUE]rtos[/color] ([color=BLUE]car[/color] p1w)) [color=MAROON]"\tY = "[/color]  ([color=BLUE]rtos[/color] ([color=BLUE]cadr[/color] p1w)) [color=MAROON]"\tZ = "[/color]  ([color=BLUE]rtos[/color] ([color=BLUE]caddr[/color] p1w)))
           ([color=BLUE]strcat[/color] [color=MAROON]"Sokkia:\tX = "[/color]      ([color=BLUE]rtos[/color] ([color=BLUE]car[/color] p2w)) [color=MAROON]"\tY = "[/color]  ([color=BLUE]rtos[/color] ([color=BLUE]cadr[/color] p2w)) [color=MAROON]"\tZ = "[/color]  ([color=BLUE]rtos[/color] ([color=BLUE]caddr[/color] p2w)))
           ([color=BLUE]strcat[/color] [color=MAROON]"Difference:\tXD = "[/color] ([color=BLUE]rtos[/color] xd)        [color=MAROON]"\tYD = "[/color] ([color=BLUE]rtos[/color] yd)         [color=MAROON]"\tZD = "[/color] ([color=BLUE]rtos[/color] zd))
           [color=MAROON]""[/color]
       ) [color=GREEN];; end COMMAND[/color]
   ) [color=GREEN];; end WHILE[/color]
   
   [color=GREEN];; Suppress the return of the last expression[/color]
   ([color=BLUE]princ[/color]) 
) [color=GREEN];; end DEFUN[/color]

The reason for your error was because you had converted the coordinate values to strings (using rtos), and then attempted to subtract the two strings rather than the numerical values, resulting in a 'bad argument type: numberp: ' error, string the '-' function requires a numerical argument and you had passed it a string. For more information on error messages, see my troubleshooter here.

Link to comment
Share on other sites

OHHH, so after i "rtos" them, it loses the definition of what they where.

 

Not quite; you are converting the coordinate values from the REAL data type to the STRing data type.

 

e.g.:

_$ (setq x 123.456)
123.456
_$ (type x)
REAL
_$ (setq x (rtos x))
"123.456000"
_$ (type x)
STR

 

thanks lee mac. You're the best.

 

Thank you.

Link to comment
Share on other sites

LEE! i just wanted to say thanks again and wanted to show you something i added.

it totally works and i dont' need any help, but i did come across this:

 

http://www.cadtutor.net/forum/showthread.php?45355-lisp-to-round-up-numbers

 

and i didn't like that code. (pretentious, i know) Seemed like i didn't have enough control over what it actually rounded.

 

(defun c:ptdif ( / p1 p1w p2 p2w xd yd zd )
   
   ;; while the following expression returns a non-nil value
   (while
       ;; Every expression enclosed by the AND function must return
       ;; a non-nil value for AND to return T
       (and
           ;; Prompt user for points:
           (setq p1 (getpoint "\nChoose Model <Exit>: "))
           (setq p2 (getpoint p1 "\nChoose Shot <Exit>: "))
       ) ;; end AND

       ;; p1 / p2 transformed from UCS to WCS:
       (setq p1w (trans p1 1 0)
             p2w (trans p2 1 0)
             ;; Difference in WCS X-Coord:
             xe (- (car p1w) (car p2w))
             ;; Difference in WCS Y-Coord:
             ye (- (cadr p1w) (cadr p2w))
             ;; Difference in WCS Z-Coord:
             ze (- (caddr p1w) (caddr p2w))
       ) ;; end SETQ


(cond       
( (< 1 xe) (setq xf " 1in+ FWD"))
( (and (>= 1.0000 xe) (<= 0.8750 xe) (setq xf " 1 inch FWD")))
( (and (>= 0.8750 xe) (<= 0.7501 xe) (setq xf " 7/8 FWD" )))
( (and (>= 0.7500 xe) (<= 0.6251 xe) (setq xf " 3/4 FWD" )))
( (and (>= 0.6250 xe) (<= 0.5001 xe) (setq xf " 5/8 FWD" )))
( (and (>= 0.5000 xe) (<= 0.3751 xe) (setq xf " 1/2 FWD" )))
( (and (>= 0.3750 xe) (<= 0.2501 xe) (setq xf " 3/8 FWD" )))
( (and (>= 0.2500 xe) (<= 0.1251 xe) (setq xf " 1/4 FWD" )))
( (and (>= 0.1250 xe) (<= 0.0626 xe) (setq xf " 1/8 FWD" )))
( (and (>= 0.0625 xe) (<= -0.0625 xe) (setq xf "GOOD")))
( (and (<= -1.0000 xe) (>= -0.8750 xe) (setq xf " 1 inch AFT")))
( (and (<= -0.8750 xe) (>= -0.7501 xe) (setq xf " 7/8 AFT" )))
( (and (<= -0.7500 xe) (>= -0.6251 xe) (setq xf " 3/4 AFT" )))
( (and (<= -0.6250 xe) (>= -0.5001 xe) (setq xf " 5/8 AFT" )))
( (and (<= -0.5000 xe) (>= -0.3751 xe) (setq xf " 1/2 AFT" )))
( (and (<= -0.3750 xe) (>= -0.2501 xe) (setq xf " 3/8 AFT" )))
( (and (<= -0.2500 xe) (>= -0.1251 xe) (setq xf " 1/4 AFT" )))
( (and (<= -0.1250 xe) (>= -0.0626 xe) (setq xf " 1/8 AFT" )))
( (> -1 xe) (setq xf " 1in+ AFT "))
)

(cond       
( (< 1 ye) (setq yf " 1in+ OB"))
( (and (>= 1.0000 ye) (<= 0.8750 ye) (setq yf " 1 inch OB")))
( (and (>= 0.8750 ye) (<= 0.7501 ye) (setq yf " 7/8 OB" )))
( (and (>= 0.7500 ye) (<= 0.6251 ye) (setq yf " 3/4 OB" )))
( (and (>= 0.6250 ye) (<= 0.5001 ye) (setq yf " 5/8 OB" )))
( (and (>= 0.5000 ye) (<= 0.3751 ye) (setq yf " 1/2 OB" )))
( (and (>= 0.3750 ye) (<= 0.2501 ye) (setq yf " 3/8 OB" )))
( (and (>= 0.2500 ye) (<= 0.1251 ye) (setq yf " 1/4 OB" )))
( (and (>= 0.1250 ye) (<= 0.0626 ye) (setq yf " 1/8 OB" )))
( (and (>= 0.0625 ye) (<= -0.0625 ye) (setq yf "GOOD")))
( (and (<= -1.0000 ye) (>= -0.8750 ye) (setq yf " 1 inch INB")))
( (and (<= -0.8750 ye) (>= -0.7501 ye) (setq yf " 7/8 INB" )))
( (and (<= -0.7500 ye) (>= -0.6251 ye) (setq yf " 3/4 INB" )))
( (and (<= -0.6250 ye) (>= -0.5001 ye) (setq yf " 5/8 INB" )))
( (and (<= -0.5000 ye) (>= -0.3751 ye) (setq yf " 1/2 INB" )))
( (and (<= -0.3750 ye) (>= -0.2501 ye) (setq yf " 3/8 INB" )))
( (and (<= -0.2500 ye) (>= -0.1251 ye) (setq yf " 1/4 INB" )))
( (and (<= -0.1250 ye) (>= -0.0626 ye) (setq yf " 1/8 INB" )))
( (> -1 ye) (setq yf " 1in+ INB "))
)

(cond       
( (< 1 ze) (setq zf " 1in+ HIGH"))
( (and (>= 1.0000 ze) (<= 0.8750 ze) (setq zf " 1 inch HIGH")))
( (and (>= 0.8750 ze) (<= 0.7501 ze) (setq zf " 7/8 HIGH" )))
( (and (>= 0.7500 ze) (<= 0.6251 ze) (setq zf " 3/4 HIGH" )))
( (and (>= 0.6250 ze) (<= 0.5001 ze) (setq zf " 5/8 HIGH" )))
( (and (>= 0.5000 ze) (<= 0.3751 ze) (setq zf " 1/2 HIGH" )))
( (and (>= 0.3750 ze) (<= 0.2501 ze) (setq zf " 3/8 HIGH" )))
( (and (>= 0.2500 ze) (<= 0.1251 ze) (setq zf " 1/4 HIGH" )))
( (and (>= 0.1250 ze) (<= 0.0626 ze) (setq zf " 1/8 HIGH" )))
( (and (>= 0.0625 ze) (<= -0.0625 ze) (setq zf "GOOD")))
( (and (<= -1.0000 ze) (>= -0.8750 ze) (setq zf " 1 inch LOW")))
( (and (<= -0.8750 ze) (>= -0.7501 ze) (setq zf " 7/8 LOW" )))
( (and (<= -0.7500 ze) (>= -0.6251 ze) (setq zf " 3/4 LOW" )))
( (and (<= -0.6250 ze) (>= -0.5001 ze) (setq zf " 5/8 LOW" )))
( (and (<= -0.5000 ze) (>= -0.3751 ze) (setq zf " 1/2 LOW" )))
( (and (<= -0.3750 ze) (>= -0.2501 ze) (setq zf " 3/8 LOW" )))
( (and (<= -0.2500 ze) (>= -0.1251 ze) (setq zf " 1/4 LOW" )))
( (and (<= -0.1250 ze) (>= -0.0626 ze) (setq zf " 1/8 LOW" )))
( (> -1 ze) (setq zf " 1in+ LOW "))
)


       ;; Create Leader
       ;; "_non" = Ignore Object Snap (_non = prefix for 'none')
       (command "_.leader" "_non" p1 "\\" ""
           (strcat "Model:\tX = "(rtos (car p1w)) "\t\tY = "  (rtos (cadr p1w)) "\t\tZ = "  (rtos (caddr p1w)))
           (strcat "Sokkia:\tX = "(rtos (car p2w)) "\t\tY = "  (rtos (cadr p2w)) "\t\tZ = "  (rtos (caddr p2w)))
           (strcat " \t\tX = "xf"\t\tY = "yf"\t\tZ = "zf)
           ""
       ) ;; end COMMAND
   ) ;; end WHILE
   
   ;; Suppress the return of the last expression
   (princ) 
) ;; end DEFUN

 

I know my code is really blocked and simple and redundant, but it's in a body that i can read with ease. i'm more of a "notepad" coder.

That visual lisp tutorial you have on your site is really great, but it kinda kicks into super advanced really fast.

 

TL;DR

thanks again, great website lee.

your "error message" page has become my favorite bookmark.

Link to comment
Share on other sites

i'm more of a "notepad" coder.

That visual lisp tutorial you have on your site is really great, but it kinda kicks into super advanced really fast.

 

I'm sorry to hear that you found my tutorial to be too complex - I honestly tried to write it to be as clear and comprehensible as possible, however, it is incredibly difficult to gauge the technical level and read the tutorial from the perspective of a novice - all whilst striving to maintain the interest of the reader and avoiding informaton overload...

 

Though, I would strongly suggest that you use a code editor to write your code, rather than standard notepad. I would always recommend the Visual LISP IDE specifically for writing AutoLISP (AfraLISP has a few tutorials on the VLIDE if you found mine hard-going); but if you wanted to avoid using the VLIDE, there are a plethora of other free code editors available online - I personally use Notepad++ for all of my non-AutoLISP programming, as it is a great 'all-rounder'.

 

Other code editors include: UltraEdit / Eclipse / Vim / Emacs / MSVS ...

 

thanks again, great website lee.

your "error message" page has become my favorite bookmark.

 

Cheers! 8)

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