hosneyalaa Posted November 5, 2018 Posted November 5, 2018 the lisp give me { error: bad argument type: numberp: nil} can help me thanks all. (defun C:xx (/ nn pts A acDataRow acHeaderRow acMiddleCenter acTitleRow B BE_SELECTION C COLWIDTH CURSPACE DOC E HT MPER N NUMCOLUMNS NUMROWS OBJTABLE PT PT1 PTCNTR PTS ROWHEIGHT S X Y Z) (command "layer" "m" "AVG" "") (command "color" "t" "253,176,23") (command "-osnap" "endpoint,midpoint,center,node,quadrant,tangent,INTersection,PERpendicular" ) (SETQ ht (GETreal "\Enter Text height : ")) (SETQ n 0) (while (setq pt (getpoint "\nSpecify a point :")) (setq pts (cons pt pts)) (SETQ n (1+ n)) (COMMAND "TEXT" pt ht "0" (rtos n)) (COMMAND "_point" pt "") ) ;while (vl-load-com) (setq ptCntr 1) (setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table: ") ) ) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq curspace (vla-get-modelspace doc)) (setq numrows (+ 2 n)) (setq numcolumns 4) (setq rowheight 6) (setq colwidth 25) (setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth) ) (vla-settext objtable 0 0 "جدول الاحداثيات") (vla-setcolumnwidth objtable 0 25) (vla-setcolumnwidth objtable 1 25) (vla-settext objtable 1 0 "رقم النقطة") (vla-settext objtable 1 1 "x") (vla-settext objtable 1 2 "y") (vla-settext objtable 1 3 "z") (vla-SetTextHeight Objtable (+ acDataRow acHeaderRow acTitleRow) 2.5 ) (vla-SetAlignment Objtable acDataRow acMiddleCenter) (setq x 1) (SETQ Y 2) (SETQ Z 120) (SETQ nn 0) (while ((<= nn n) (SETQ e(nth (- n nn) pts)) (SETQ a (CAR e)) (SETQ B (CADR e)) (SETQ c (CADDR e)) (RTOS a 2 2) (RTOS B 2 2) (RTOS c 2 2) (vla-settext objtable Y 0 (itoa ptCntr)) (vla-settext objtable Y 1 (rtos a 2 3)) (vla-settext objtable Y 2 (rtos b 2 3)) (vla-settext objtable Y 3 (rtos c 2 3)) (setq x (1+ x )) (setq y (1+ Y )) (setq ptCntr (+ ptCntr 1)) (setq Z (1+ Z)) (setq nn (+ 1 nn)) ) ) ) Quote
dlanorh Posted November 5, 2018 Posted November 5, 2018 OK. First error (defun C:xx (/ nn pts A acDataRow acHeaderRow acMiddleCenter acTitleRow B BE_SELECTION C COLWIDTH CURSPACE DOC E HT MPER N NUMCOLUMNS NUMROWS OBJTABLE PT PT1 PTCNTR PTS ROWHEIGHT S X Y Z) Remove variables acDataRow -> acTitleRow. Anything that starts with ac is an autocad global constant and you have declared them as lisp local variables value nil. This causes the first error. Second and Third errors (while ((<= nn n) Remove one of the two opening brackets after the while. This is causing the while loop to function incorrectly control should be (< nn n) not (<= nn n) Fourth error (SETQ e(nth (- n nn) pts)) this should be (SETQ e (nth nn pts)) e was never being set a value Fifth error (RTOS a 2 2) (RTOS B 2 2) (RTOS c 2 2) These lines do nothing and you (rtos var 2 3) later Quote
dlanorh Posted November 5, 2018 Posted November 5, 2018 To add to the above you can remove everything x and z related as it is never used in the while loop. (SETQ y 2) (SETQ nn 0) (while (< nn n) (SETQ e(nth nn pts)) (SETQ a (CAR e)) (SETQ b (CADR e)) (SETQ c (CADDR e)) (vla-settext objtable y 0 (itoa ptCntr)) (vla-settext objtable y 1 (rtos a 2 3)) (vla-settext objtable y 2 (rtos b 2 3)) (vla-settext objtable y 3 (rtos c 2 3)) (setq y (1+ y)) (setq ptCntr (1+ ptCntr)) (setq nn (1+ nn)) ) Your while loop should now look like this. 1 Quote
hosneyalaa Posted November 5, 2018 Author Posted November 5, 2018 3 hours ago, dlanorh said: To add to the above you can remove everything x and z related as it is never used in the while loop. (SETQ y 2) (SETQ nn 0) (while (< nn n) (SETQ e(nth nn pts)) (SETQ a (CAR e)) (SETQ b (CADR e)) (SETQ c (CADDR e)) (vla-settext objtable y 0 (itoa ptCntr)) (vla-settext objtable y 1 (rtos a 2 3)) (vla-settext objtable y 2 (rtos b 2 3)) (vla-settext objtable y 3 (rtos c 2 3)) (setq y (1+ y)) (setq ptCntr (1+ ptCntr)) (setq nn (1+ nn)) ) Your while loop should now look like this. I am new to LISP language Is it possible to arrange the code correctly? Because I did not know how to correct mistakes and did not work with me code Thank you Quote
dlanorh Posted November 5, 2018 Posted November 5, 2018 (edited) 6 hours ago, hosneyalaa said: (setq pts (cons pt pts)) I have just noticed the above. When you construct a list with (cons), the list ends up back to front, so you must (setq pts (reverse pts)) to set it in the correct order you collected the point coordinates (outside the while loop). You haven't done this so when you put the points into the table and give each point a number, the wrong coordinates get given to the point number. Edited November 5, 2018 by dlanorh 1 Quote
hosneyalaa Posted November 6, 2018 Author Posted November 6, 2018 Edit the code from a friend Thank you (DEFUN c:xx (/ a b c colwidth curspace doc e ht n nn numcolumns numrows objtable pt pt1 ptcntr pts rowheight y) (SETVAR "CECOLOR" "RGB:253,176,23") (SETVAR "OSMODE" 35) (INITGET 7) (SETQ ht (GETREAL "\n-> Enter text height : ")) (SETQ n 0) (WHILE (SETQ pt (GETPOINT "\n-> Specify a point :")) (SETQ pts (CONS pt pts)) (SETQ n (1+ n)) (COMMAND "_.TEXT" pt ht "0" (ITOA n)) (COMMAND "_.POINT" pt "") ) (REVERSE pts) (VL-LOAD-COM) (SETQ ptcntr 1) (SETQ pt1 (VLAX-3D-POINT (GETPOINT "\n-> Pick point for top left hand of table: "))) (SETQ doc (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT))) (SETQ curspace (VLA-GET-MODELSPACE doc)) (SETQ numrows (+ 2 n)) (SETQ numcolumns 4) (SETQ rowheight 6) (SETQ colwidth 25) (SETQ objtable (VLA-ADDTABLE curspace pt1 numrows numcolumns rowheight colwidth)) (VLA-SETTEXT objtable 0 0 "ÌÏæá ÇáÇÍÏÇËíÇÊ") (VLA-SETCOLUMNWIDTH objtable 0 25) (VLA-SETCOLUMNWIDTH objtable 1 25) (VLA-SETTEXT objtable 1 0 "ÑÞã ÇáäÞØÉ") (VLA-SETTEXT objtable 1 1 "x") (VLA-SETTEXT objtable 1 2 "y") (VLA-SETTEXT objtable 1 3 "z") (VLA-SETTEXTHEIGHT objtable (+ ACDATAROW ACHEADERROW ACTITLEROW) 2.5) (VLA-SETALIGNMENT objtable ACDATAROW ACMIDDLECENTER) (SETQ y 2) (SETQ nn 0) (WHILE (AND (<= nn n) (/= (1- (- n nn)) -1)) (SETQ e (NTH (1- (- n nn)) pts) a (CAR e) b (CADR e) c (CADDR e) ) (RTOS a 2 2) (RTOS b 2 2) (RTOS c 2 2) (VLA-SETTEXT objtable y 0 (ITOA ptcntr)) (VLA-SETTEXT objtable y 1 (RTOS a 2 3)) (VLA-SETTEXT objtable y 2 (RTOS b 2 3)) (VLA-SETTEXT objtable y 3 (RTOS c 2 3)) (SETQ y (1+ y)) (SETQ ptcntr (+ ptcntr 1)) (SETQ nn (+ 1 nn)) ) (PRINC) ) Quote
Lee Mac Posted November 6, 2018 Posted November 6, 2018 For reference, duplicate thread answered here: https://www.theswamp.org/index.php?topic=54643.0 Quote
Recommended Posts
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.