Jump to content

help for lisp for creating points(getpoint) and put table


Recommended Posts

Posted

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

    
  )

)
  )


 

Capture.PNG

Posted

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

 

 

Posted

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.

  • Thanks 1
Posted
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

Posted (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 by dlanorh
  • Thanks 1
Posted
Edit the code from a friend
Thank you

 

 

  1. (DEFUN c:xx (/ a b c colwidth curspace doc e ht n nn numcolumns numrows objtable pt pt1 ptcntr pts rowheight y)
  2.  (SETVAR "CECOLOR" "RGB:253,176,23")
  3.  (SETVAR "OSMODE" 35)
  4.  (INITGET 7)
  5.  (SETQ ht (GETREAL "\n-> Enter text height : "))
  6.  (SETQ n 0)
  7.  (WHILE (SETQ pt (GETPOINT "\n-> Specify a point :"))
  8.    (SETQ pts (CONS pt pts))
  9.    (SETQ n (1+ n))
  10.    (COMMAND "_.TEXT" pt ht "0" (ITOA n))
  11.    (COMMAND "_.POINT" pt "")
  12.  )
  13.  (REVERSE pts)
  14.  (SETQ ptcntr 1)
  15.  (SETQ pt1 (VLAX-3D-POINT (GETPOINT "\n-> Pick point for top left hand of table: ")))
  16.  (SETQ curspace (VLA-GET-MODELSPACE doc))
  17.  (SETQ numrows (+ 2 n))
  18.  (SETQ numcolumns 4)
  19.  (SETQ rowheight 6)
  20.  (SETQ colwidth 25)
  21.  (SETQ objtable (VLA-ADDTABLE curspace pt1 numrows numcolumns rowheight colwidth))
  22.  (VLA-SETTEXT objtable 0 0 "ÌÏæá ÇáÇÍÏÇËíÇÊ")
  23.  (VLA-SETCOLUMNWIDTH objtable 0 25)
  24.  (VLA-SETCOLUMNWIDTH objtable 1 25)
  25.  (VLA-SETTEXT objtable 1 0 "ÑÞã ÇáäÞØÉ")
  26.  (VLA-SETTEXT objtable 1 1 "x")
  27.  (VLA-SETTEXT objtable 1 2 "y")
  28.  (VLA-SETTEXT objtable 1 3 "z")
  29.  (VLA-SETTEXTHEIGHT objtable (+ ACDATAROW ACHEADERROW ACTITLEROW) 2.5)
  30.  (VLA-SETALIGNMENT objtable ACDATAROW ACMIDDLECENTER)
  31.  (SETQ y 2)
  32.  (SETQ nn 0)
  33.  (WHILE (AND (<= nn n) (/= (1- (- n nn)) -1))
  34.    (SETQ e (NTH (1- (- n nn)) pts)
  35.          a (CAR e)
  36.          b (CADR e)
  37.          c (CADDR e)
  38.    )
  39.    (RTOS a 2 2)
  40.    (RTOS b 2 2)
  41.    (RTOS c 2 2)
  42.    (VLA-SETTEXT objtable y 0 (ITOA ptcntr))
  43.    (VLA-SETTEXT objtable y 1 (RTOS a 2 3))
  44.    (VLA-SETTEXT objtable y 2 (RTOS b 2 3))
  45.    (VLA-SETTEXT objtable y 3 (RTOS c 2 3))
  46.    (SETQ y (1+ y))
  47.    (SETQ ptcntr (+ ptcntr 1))
  48.    (SETQ nn (+ 1 nn))
  49.  )
  50.  (PRINC)
  51. )
  52.  

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