Author Topic: Need Help in Generating a table  (Read 3350 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Need Help in Generating a table
« on: May 01, 2010, 03:03:21 PM »
This is a piece of code

The table created but empty
Please Help


Code: [Select]
(defun Gen_Table ()

  (vl-load-com)

  (setq TblPnt (vlax-3d-point (getpoint "\nPick Insertion Point: "))
      num:Num 10
      actDoc(vla-get-ActiveDocument
      (vlax-get-acad-object))
      mSp(vla-get-ModelSpace actDoc)
      )
  (setq Gen:Table (vla-AddTable mSp TblPnt
                                (+ 1 num:Num)
                                3
                                (* 4 (getvar "DIMTXT"))
                                (* 14 (getvar "DIMTXT")))
        T:X 2 T:Y 1 T:R 0)
 
  (vla-put-layer Gen:Table "EC-TEXT-22-SCALE")
  (vla-put-StyleName Gen:Table "EC-TABLE-100")
  (vla-put-Alignment Gen:Table acAlignmentMiddleCenter)
  (vla-setText Gen:Table 0 0 "Coordenate")
  (vla-setText Gen:Table 1 0 "X")
  (vla-setText Gen:Table 1 1 "Y")
  (vla-setText Gen:Table 1 2 "Remarks")

  (foreach i Gen:Table
    (vl-catch-all-apply 'vla-SetText(cons Gen:Table i)) 
    (vla-SetCellTextHeight Gen:Table(car i)(cadr i)(getvar "DIMTXT"))
    (vla-SetCellAlignment Gen:Table(car i)(cadr i)acMiddleCenter)
            (vla-setText Gen:Table T:X 0 (nth T:Y NumPontLstN))
            (vla-setText Gen:Table T:X 1 (nth T:Y NumPontLstX))
            (vla-setText Gen:Table T:X 2 (nth T:Y NumPontLstY))
    )
 
  )
« Last Edit: May 02, 2010, 05:37:17 AM by asos2000 »

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Need Help in Generating a table
« Reply #1 on: May 02, 2010, 05:48:32 AM »
up

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Need Help in Generating a table
« Reply #2 on: May 02, 2010, 08:30:55 AM »
fixo

Are you advicing me
or
want to say that I didn't response you?

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Need Help in Generating a table
« Reply #3 on: May 02, 2010, 09:16:09 AM »
Get to work, baby  :x
:lmao: Nobody puts Baby in the corner.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Need Help in Generating a table
« Reply #4 on: May 02, 2010, 01:13:34 PM »
Do you have a sample point list? Trying to figure out what you are doing would be much easier if you provide all the data needed to run the code.....

Also.... Make sure the Layer and Table styles exist. When I run this it errors since in my drawing they do not. A Table does not have an Alignment property so it errors there as well. Once I addressed these 3 items, and commented out the actual data filling code since I don't have any data to work with, the table is created with the headers.
« Last Edit: May 02, 2010, 01:22:20 PM by Jeff_M »

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Need Help in Generating a table
« Reply #5 on: May 03, 2010, 09:40:35 AM »
This is full code

Code: [Select]
;
;                                  subroutine
 (defun Gen_PointBlock ()
    (entmake '((0 . "BLOCK") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbBlockReference") (2 . "Planning-Point") (10 0 0 0) (70 . 0)))
    (entmake '((0 . "CIRCLE") (100 . "AcDbEntity") (67 . 0) (8 . "0") (62 . 7) (100 . "AcDbCircle") (10 0 0.0 0) (40 . 0.1)))
    (entmake '((0 . "LINE") (100 . "AcDbEntity") (67 . 0) (8 . "0") (62 . 7) (100 . "AcDbLine") (10 -0.15 0.15 0) (11 0.15 -0.15 0)))
    (entmake '((0 . "LINE") (100 . "AcDbEntity") (67 . 0) (8 . "0") (62 . 7) (100 . "AcDbLine") (10 -0.15 -0.15 0) (11 0.15 0.15 0)))
    (entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
    (princ)
    ); end Pointblock
  (defun Gen_Layer ()
    (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 "EC-TEXT-22-SCALE") (cons 70 0) (cons 62 10)))
    (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 "EC-SYMBOL") (cons 70 0) (cons 62 13)))
    (princ)
    ); end layer
(defun *error* (msg)
    (if oldEcho (setvar "CMDECHO" oldEcho))
    (if oSnp (setvar "OSMODE" oSnp))
    (if oZin (setvar "DIMZIN" oZin))
    (if mSp (vla-EndUndoMark actDoc))
    (princ)
  ); end of *error*

(defun Gen_Table ()

  (setq TblPnt (vlax-3d-point (getpoint "\nPick Insertion Point: "))
        actDoc(vla-get-ActiveDocument
        (vlax-get-acad-object))
        mSp (vla-get-ModelSpace actDoc)
      )
  (setq Gen:Table (vla-AddTable mSp TblPnt
                                (+ 1 num:Num)
                                3
                                (* 4 (getvar "DIMTXT"))
                                (* 14 (getvar "DIMTXT")))
        T:X 2 T:Y 1 T:R 0)
 
  (vla-put-layer Gen:Table "EC-TEXT-22-SCALE")
  (vla-put-StyleName Gen:Table "EC-TABLE-100")
  (vla-put-Alignment Gen:Table acAlignmentMiddleCenter)
  (vla-setText Gen:Table 0 0 "Coordenate")
  (vla-setText Gen:Table 1 0 "X")
  (vla-setText Gen:Table 1 1 "Y")
  (vla-setText Gen:Table 1 2 "Remarks")

  (foreach i Gen:Table
    (vl-catch-all-apply 'vla-SetText(cons Gen:Table i)) 
    (vla-SetCellTextHeight Gen:Table(car i)(cadr i)(getvar "DIMTXT"))
    (vla-SetCellAlignment Gen:Table(car i)(cadr i)acMiddleCenter)
            (vla-setText Gen:Table T:X 0 (nth T:Y NumPontLstN))
            (vla-setText Gen:Table T:X 1 (nth T:Y NumPontLstX))
            (vla-setText Gen:Table T:X 2 (nth T:Y NumPontLstY))
    )
 
  );end Gen_Table
      ;;;
  ;    EndSubroutine   
 
  ;                        mainroutine   
      ;;;
  (defun c:EC-COORD (/ Pnt:Lst)
  (vl-load-com)
    (Gen_Layer)
    (Gen_PointBlock)
    (setq OldDynmode (getvar "dynmode")
          OldDynprompt (getvar "dynprompt")
   OldEcho (getvar "cmdecho")
          OZin (getvar "DIMZIN")
          )
    (if(not num:Size)(setq num:Size(getvar "DIMTXT")))
    (if(not num:Pref)(setq num:Pref ""))
    (if(not num:Suf)(setq num:Suf ""))
    (if(not num:Num)(setq num:Num 1))
    (setq oldPref num:Pref
          oldSuf num:Suf
          oldStart num:Num
          oldSize num:Size
          actDoc(vla-get-ActiveDocument
                  (vlax-get-acad-object))
          mSp(vla-get-ModelSpace actDoc)
          oldEcho(getvar "CMDECHO")
          );End of setq
    (setvar "cmdecho" 0)
    (setvar "DIMZIN" 0)
  (initget "Meter MILLImeter")
  (setq Dwg:Unts (getkword "\nWhat is drawing units? [Meter/MILLImeter]: "))
 
  (if (= Dwg:Unts "Meter")
    (progn
      (command "_.-style" "EC-22-0.01" "romans.shx" 0.22 "0.8" "0" "n" "n" "n")
      (setvar "DIMTXT" 0.22)
      (setq BlkScl 1.0)
      ))
  (if (= Dwg:Unts "MILLImeter")
    (progn
      (command "_.-style" "EC-22-100" "romans.shx" 220 "0.8" "0" "n" "n" "n")
      (setvar "DIMTXT" 220)
      (setq BlkScl 1000.0)
      ))
  (if(not num:Pref)(setq num:Pref ""))
  (if(not num:Suf)(setq num:Suf ""))
  (if(not num:Suf)(setq num:Suf ""))
 
  (if(null num:Size)(setq num:Size oldSize))
 
  (setq num:Pref (getstring T (strcat "\nPrefix: <"num:Pref">: ")))
  (if(= "" num:Pref)(setq num:Pref oldPref))
  (if(= " " num:Pref)(setq num:Pref ""))
  (setq num:Suf (getstring T (strcat "\nSuffix: <"num:Suf">: ")))
  (if(= "" num:Suf)(setq num:Suf oldSuf))
  (if(= " " num:Suf)(setq num:Suf ""))
  (setq num:Num (getint (strcat "\nStarting number <"(itoa num:Num)">: ")))
  (if(null num:Num)(setq num:Num oldStart))
 
  (princ "\n<<< Insert numbers then press Enter to insert table and quit >>> ")
    (while
      (progn
 (setq curStr (strcase (strcat num:Pref(itoa num:Num)num:Suf))
              NumPnt (getpoint "\nPick Point ")
              NumPont (list (- (car NumPnt) (* 3 (getvar "DIMTXT"))) (+ (cadr NumPnt) (* 3 (getvar "DIMTXT"))) (caddr NumPnt))
              NumPontLst (list (list curStr (car NumPnt) (cadr NumPnt)) NumPontLst)
              NumPontLstN (append NumPontLstN curStr)
              NumPontLstX (append NumPontLstx (car NumPont))
      NumPontLstY (append NumPontLsty (cadr NumPont))
       )
 )
 
 (entmakex ;pointText
          (list (cons 0 "TEXT") (cons 1 curStr) (cons 7 (getvar "textstyle")) (cons 8 "EC") (cons 10 NumPont) (cons 11 NumPont) (cons 40 (getvar "DIMTXT")) (cons 50 45) (cons 72 1) (cons 73 2)))
 (entmakex ;Pointblock
          (list (cons 0 "INSERT") (cons 2 "Planning-Point") (cons 8 "EC-SYMBOL") (cons 10 NumPnt) (cons 41 BlkScl) (cons 42 BlkScl) (cons 43 BlkScl)))
        (setq num:Num(1+ num:Num))
        ); end of progn
       ); end while
    (Gen_Table)
    (princ "http:\\www.a-a-econstruct.com ")
    (princ "Type EC-COORD to run. ")
  ); end of Defun

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Need Help in Generating a table
« Reply #6 on: May 03, 2010, 11:39:01 AM »
Here's your code with multiple revisions noted. It now works, although I would suggest adding some error traps and cleaning up the variables so you have more locals vs globals.
Code: [Select]
;
;                                  subroutine
(defun Gen_PointBlock ()
  (entmake '((0 . "BLOCK")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (100 . "AcDbBlockReference")
     (2 . "Planning-Point")
     (10 0 0 0)
     (70 . 0)
    )
  )
  (entmake '((0 . "CIRCLE")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (62 . 7)
     (100 . "AcDbCircle")
     (10 0 0.0 0)
     (40 . 0.1)
    )
  )
  (entmake '((0 . "LINE")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (62 . 7)
     (100 . "AcDbLine")
     (10 -0.15 0.15 0)
     (11 0.15 -0.15 0)
    )
  )
  (entmake '((0 . "LINE")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (62 . 7)
     (100 . "AcDbLine")
     (10 -0.15 -0.15 0)
     (11 0.15 0.15 0)
    )
  )
  (entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
  (princ)
) ; end Pointblock
(defun Gen_Layer ()
  (entmake (list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 "EC-TEXT-22-SCALE")
(cons 70 0)
(cons 62 10)
   )
  )
  (entmake (list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 "EC-SYMBOL")
(cons 70 0)
(cons 62 13)
   )
  )
  (princ)
) ; end layer
(defun *error* (msg)
  (if oldEcho
    (setvar "CMDECHO" oldEcho)
  )
  (if oSnp
    (setvar "OSMODE" oSnp)
  )
  (if oZin
    (setvar "DIMZIN" oZin)
  )
  (if mSp
    (vla-EndUndoMark actDoc)
  )
  (princ msg)
  (princ)
) ; end of *error*

(defun Gen_Table ()

  (setq TblPnt (vlax-3d-point (getpoint "\nPick Insertion Point: "))
actDoc (vla-get-ActiveDocument
(vlax-get-acad-object)
       )
mSp    (vla-get-ModelSpace actDoc)
  )
  (setq Gen:Table (vla-AddTable
    mSp
    TblPnt
    (+ 1 num:Num)
    3
    (* 4 (getvar "DIMTXT"))
    (* 14 (getvar "DIMTXT"))
  )
T:X   2
T:Y   0
T:R   0
  )
  ;;changed Y to 0

  (vla-put-layer Gen:Table "EC-TEXT-22-SCALE")
  (vla-put-StyleName Gen:Table "STANDARD")
;;; Changed to Standard since the specified table style does not exist
  (vla-SetAlignment Gen:Table acDataRow acMiddleCenter)
  ;;changed format
  (vla-setText Gen:Table 0 0 "Coordinate")
  (vla-setText Gen:Table 1 0 "X")
  (vla-setText Gen:Table 1 1 "Y")
  (vla-setText Gen:Table 1 2 "Remarks")

  (foreach i NUMPONTLST
    (vla-setText Gen:Table T:X 0 (nth T:Y NumPontLstN))
    (vla-setText Gen:Table T:X 1 (nth T:Y NumPontLstX))
    (vla-setText Gen:Table T:X 2 (nth T:Y NumPontLstY))
    (setq T:X (1+ T:X)
  ;;added incrementing x & y
  T:Y (1+ T:Y)
    )
  )

) ;end Gen_Table
;;;
;    EndSubroutine   

;                        mainroutine   
;;;
(defun c:EC-COORD (/ Pnt:Lst       NUMPNT
   NUMPONT NUMPONTLST    NUMPONTLSTN
   NUMPONTLSTX NUMPONTLSTY
  )
  (vl-load-com)
  (Gen_Layer)
  (Gen_PointBlock)
  (setq OldDynmode   (getvar "dynmode")
OldDynprompt (getvar "dynprompt")
OldEcho      (getvar "cmdecho")
OZin      (getvar "DIMZIN")
  )
  (if (not num:Size)
    (setq num:Size (getvar "DIMTXT"))
  )
  (if (not num:Pref)
    (setq num:Pref "")
  )
  (if (not num:Suf)
    (setq num:Suf "")
  )
  (if (not num:Num)
    (setq num:Num 1)
  )
  (setq oldPref num:Pref
oldSuf num:Suf
oldStart num:Num
oldSize num:Size
actDoc (vla-get-ActiveDocument
   (vlax-get-acad-object)
)
mSp (vla-get-ModelSpace actDoc)
oldEcho (getvar "CMDECHO")
  ) ;End of setq
  (setvar "cmdecho" 0)
  (setvar "DIMZIN" 0)
  (initget "Meter MILLImeter")
  (setq Dwg:Unts
(getkword "\nWhat is drawing units? [Meter/MILLImeter]: ")
  )

  (if (= Dwg:Unts "Meter")
    (progn
      (command "_.-style"  "EC-22-0.01"    "romans.shx"
       0.22    "0.8"       "0"    "n"
       "n"    "n"
      )
      (setvar "DIMTXT" 0.22)
      (setq BlkScl 1.0)
    )
  )
  (if (= Dwg:Unts "MILLImeter")
    (progn
      (command "_.-style" "EC-22-100" "romans.shx" 220 "0.8" "0" "n" "n"
       "n")
      (setvar "DIMTXT" 220)
      (setq BlkScl 1000.0)
    )
  )
  (if (not num:Pref)
    (setq num:Pref "")
  )
  (if (not num:Suf)
    (setq num:Suf "")
  )
  (if (not num:Suf)
    (setq num:Suf "")
  )

  (if (null num:Size)
    (setq num:Size oldSize)
  )

  (setq num:Pref (getstring T (strcat "\nPrefix: <" num:Pref ">: ")))
  (if (= "" num:Pref)
    (setq num:Pref oldPref)
  )
  (if (= " " num:Pref)
    (setq num:Pref "")
  )
  (setq num:Suf (getstring T (strcat "\nSuffix: <" num:Suf ">: ")))
  (if (= "" num:Suf)
    (setq num:Suf oldSuf)
  )
  (if (= " " num:Suf)
    (setq num:Suf "")
  )
  (setq num:Num
(getint (strcat "\nStarting number <" (itoa num:Num) ">: "))
  )
  (if (null num:Num)
    (setq num:Num oldStart)
  )

  (princ
    "\n<<< Insert numbers then press Enter to insert table and quit >>> "
  )
  ;;rearranged the (progn...) and (setq...)'s
  (while
    (progn
      (setq curStr (strcase (strcat num:Pref (itoa num:Num) num:Suf))
    NumPnt (getpoint "\nPick Point ")
      )
    )
     (setq
       NumPont    (list (- (car NumPnt) (* 3 (getvar "DIMTXT")))
(+ (cadr NumPnt) (* 3 (getvar "DIMTXT")))
(caddr NumPnt)
   )
       NumPontLst  (cons (list curStr (car NumPnt) (cadr NumPnt))
NumPontLst
   )
       ;;changed (list to (cons
       NumPontLstN (append NumPontLstN (list curStr))
       ;; added (list) to this & next 2 lines
       NumPontLstX (append NumPontLstx (list (car NumPont)))
       NumPontLstY (append NumPontLsty (list (cadr NumPont)))
     )

     (entmakex ;pointText
       (list (cons 0 "TEXT")
     (cons 1 curStr)
     (cons 7 (getvar "textstyle"))
     (cons 8 "EC")
     (cons 10 NumPont)
     (cons 11 NumPont)
     (cons 40 (getvar "DIMTXT"))
     (cons 50 45)
     (cons 72 1)
     (cons 73 2)
       )
     )
     (entmakex ;Pointblock
       (list (cons 0 "INSERT")
     (cons 2 "Planning-Point")
     (cons 8 "EC-SYMBOL")
     (cons 10 NumPnt)
     (cons 41 BlkScl)
     (cons 42 BlkScl)
     (cons 43 BlkScl)
       )
     )
     (setq num:Num (1+ num:Num))
;); end of progn ;; this needed to be near beginning of (while) loop
  ) ; end while
  (Gen_Table)
  (princ "http:\\www.a-a-econstruct.com ")
) ; end of Defun

(princ "\nType EC-COORD to run. ")
;;moved out of defun

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Need Help in Generating a table
« Reply #7 on: May 04, 2010, 08:05:21 AM »
Jeff_M

More than excellent.
I dont know how to thank you.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Need Help in Generating a table
« Reply #8 on: May 08, 2010, 08:24:05 AM »
I want to change Precision of given numbers

This is what I did
Code: [Select]
(setq  NumPontLstX (append NumPontLstx (list (car NumPont))))Changed to
Code: [Select]
(setq  NumPontLstX (append NumPontLstx (list (rtos (car NumPont) 2 3))))
Searched in help and fouund this but couldnt cconvert to Lisp
Code: [Select]
Precision Property
Indicates the numeric precision of the specified object.
Signature
object.Precision
  object
          KeyDescription
          The object or objects this property applies to.
  Precision
          Integer
          Indicates the maximum number of digits allowable for a KeyDescription object.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Need Help in Generating a table
« Reply #9 on: May 08, 2010, 11:19:13 AM »
That changed code should work just fine. I just tested this with the code I posted and got the desired result.

I just realized that your data didn't match the table being created. The table's headers were "X Y Remarks" but the data entered was "Point# X Y". The following code addresses this as well as the number formatting.
Code: [Select]
;                                  subroutine
(defun Gen_PointBlock ()
  (entmake '((0 . "BLOCK")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (100 . "AcDbBlockReference")
     (2 . "Planning-Point")
     (10 0 0 0)
     (70 . 0)
    )
  )
  (entmake '((0 . "CIRCLE")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (62 . 7)
     (100 . "AcDbCircle")
     (10 0 0.0 0)
     (40 . 0.1)
    )
  )
  (entmake '((0 . "LINE")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (62 . 7)
     (100 . "AcDbLine")
     (10 -0.15 0.15 0)
     (11 0.15 -0.15 0)
    )
  )
  (entmake '((0 . "LINE")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (62 . 7)
     (100 . "AcDbLine")
     (10 -0.15 -0.15 0)
     (11 0.15 0.15 0)
    )
  )
  (entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
  (princ)
) ; end Pointblock
(defun Gen_Layer ()
  (entmake (list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 "EC-TEXT-22-SCALE")
(cons 70 0)
(cons 62 10)
   )
  )
  (entmake (list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 "EC-SYMBOL")
(cons 70 0)
(cons 62 13)
   )
  )
  (princ)
) ; end layer
(defun *error* (msg)
  (if oldEcho
    (setvar "CMDECHO" oldEcho)
  )
  (if oSnp
    (setvar "OSMODE" oSnp)
  )
  (if oZin
    (setvar "DIMZIN" oZin)
  )
  (if mSp
    (vla-EndUndoMark actDoc)
  )
  (princ msg)
  (princ)
) ; end of *error*

(defun Gen_Table ()

  (setq TblPnt (vlax-3d-point (getpoint "\nPick Insertion Point: "))
actDoc (vla-get-ActiveDocument
(vlax-get-acad-object)
       )
mSp    (vla-get-ModelSpace actDoc)
  )
  (setq Gen:Table (vla-AddTable
    mSp
    TblPnt
    (+ 1 num:Num)
    4
    (* 4 (getvar "DIMTXT"))
    (* 14 (getvar "DIMTXT"))
  )
T:X   2
T:Y   0
T:R   0
  )
  ;;changed Y to 0

  (vla-put-layer Gen:Table "EC-TEXT-22-SCALE")
  (vla-put-StyleName Gen:Table "STANDARD")
;;; Changed to Standard since the specified table style does not exist
  (vla-SetAlignment Gen:Table acDataRow acMiddleCenter)
  ;;changed format
  (vla-setText Gen:Table 0 0 "Coordinate")
  (vla-setText Gen:Table 1 0 "Point #")
  (vla-setText Gen:Table 1 1 "X")
  (vla-setText Gen:Table 1 2 "Y")
  (vla-setText Gen:Table 1 3 "Remarks")

  (foreach i NUMPONTLST
    (vla-setText Gen:Table T:X 0 (nth T:Y NumPontLstN))
    (vla-setText Gen:Table T:X 1 (nth T:Y NumPontLstX))
    (vla-setText Gen:Table T:X 2 (nth T:Y NumPontLstY))
    (setq T:X (1+ T:X)
  ;;added incrementing x & y
  T:Y (1+ T:Y)
    )
  )

) ;end Gen_Table
;;;
;    EndSubroutine   

;                        mainroutine   
;;;
(defun c:EC-COORD (/ Pnt:Lst       NUMPNT
   NUMPONT NUMPONTLST    NUMPONTLSTN
   NUMPONTLSTX NUMPONTLSTY
  )
  (vl-load-com)
  (Gen_Layer)
  (Gen_PointBlock)
  (setq OldDynmode   (getvar "dynmode")
OldDynprompt (getvar "dynprompt")
OldEcho      (getvar "cmdecho")
OZin      (getvar "DIMZIN")
  )
  (if (not num:Size)
    (setq num:Size (getvar "DIMTXT"))
  )
  (if (not num:Pref)
    (setq num:Pref "")
  )
  (if (not num:Suf)
    (setq num:Suf "")
  )
  (if (not num:Num)
    (setq num:Num 1)
  )
  (setq oldPref num:Pref
oldSuf num:Suf
oldStart num:Num
oldSize num:Size
actDoc (vla-get-ActiveDocument
   (vlax-get-acad-object)
)
mSp (vla-get-ModelSpace actDoc)
oldEcho (getvar "CMDECHO")
  ) ;End of setq
  (setvar "cmdecho" 0)
  (setvar "DIMZIN" 0)
  (initget "Meter MILLImeter")
  (setq Dwg:Unts
(getkword "\nWhat is drawing units? [Meter/MILLImeter]: ")
  )

  (if (= Dwg:Unts "Meter")
    (progn
      (command "_.-style"  "EC-22-0.01"    "romans.shx"
       0.22    "0.8"       "0"    "n"
       "n"    "n"
      )
      (setvar "DIMTXT" 0.22)
      (setq BlkScl 1.0)
    )
  )
  (if (= Dwg:Unts "MILLImeter")
    (progn
      (command "_.-style" "EC-22-100" "romans.shx" 220 "0.8" "0" "n" "n"
       "n")
      (setvar "DIMTXT" 220)
      (setq BlkScl 1000.0)
    )
  )
  (if (not num:Pref)
    (setq num:Pref "")
  )
  (if (not num:Suf)
    (setq num:Suf "")
  )
  (if (not num:Suf)
    (setq num:Suf "")
  )

  (if (null num:Size)
    (setq num:Size oldSize)
  )

  (setq num:Pref (getstring T (strcat "\nPrefix: <" num:Pref ">: ")))
  (if (= "" num:Pref)
    (setq num:Pref oldPref)
  )
  (if (= " " num:Pref)
    (setq num:Pref "")
  )
  (setq num:Suf (getstring T (strcat "\nSuffix: <" num:Suf ">: ")))
  (if (= "" num:Suf)
    (setq num:Suf oldSuf)
  )
  (if (= " " num:Suf)
    (setq num:Suf "")
  )
  (setq num:Num
(getint (strcat "\nStarting number <" (itoa num:Num) ">: "))
  )
  (if (null num:Num)
    (setq num:Num oldStart)
  )

  (princ
    "\n<<< Insert numbers then press Enter to insert table and quit >>> "
  )
  ;;rearranged the (progn...) and (setq...)'s
  (while
    (progn
      (setq curStr (strcase (strcat num:Pref (itoa num:Num) num:Suf))
    NumPnt (getpoint "\nPick Point ")
      )
    )
     (setq
       NumPont    (list (- (car NumPnt) (* 3 (getvar "DIMTXT")))
(+ (cadr NumPnt) (* 3 (getvar "DIMTXT")))
(caddr NumPnt)
   )
       NumPontLst  (cons (list curStr (car NumPnt) (cadr NumPnt))
NumPontLst
   )
       ;;changed (list to (cons
       NumPontLstN (append NumPontLstN (list curStr))
       ;; added (list) to this & next 2 lines
       NumPontLstX (append NumPontLstx (list (rtos (car NumPont) 2 3)))
       NumPontLstY (append NumPontLsty (list (rtos (cadr NumPont) 2 3)))
     )

     (entmakex ;pointText
       (list (cons 0 "TEXT")
     (cons 1 curStr)
     (cons 7 (getvar "textstyle"))
     (cons 8 "EC")
     (cons 10 NumPont)
     (cons 11 NumPont)
     (cons 40 (getvar "DIMTXT"))
     (cons 50 45)
     (cons 72 1)
     (cons 73 2)
       )
     )
     (entmakex ;Pointblock
       (list (cons 0 "INSERT")
     (cons 2 "Planning-Point")
     (cons 8 "EC-SYMBOL")
     (cons 10 NumPnt)
     (cons 41 BlkScl)
     (cons 42 BlkScl)
     (cons 43 BlkScl)
       )
     )
     (setq num:Num (1+ num:Num))
;); end of progn ;; this needed to be near beginning of (while) loop
  ) ; end while
  (Gen_Table)
  (princ "http:\\www.a-a-econstruct.com ")
) ; end of Defun

(princ "\nType EC-COORD to run. ")
;;moved out of defun
« Last Edit: May 08, 2010, 11:29:37 AM by Jeff_M »

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Need Help in Generating a table
« Reply #10 on: May 08, 2010, 11:29:39 AM »
I would suggest adding some error traps and cleaning up the variables so you have more locals vs globals.

Whats meaning of error traps?

Thanks

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Need Help in Generating a table
« Reply #11 on: May 08, 2010, 11:35:02 AM »
Error traps = Catch whatever errors MAY be caused by the user not using the routine exactly how you expect. Such as, if the user chooses to start with number 100 and creates 10 points, your table creates 110 rows, not 10 as would be expected.

What I would do.... Place the Point number into the block as an attribute. Then add the points without keeping track of what is added. Whne it's time to create the table, use a selection set to get all of the point blocks, sort the data based on point#'s, then add all of them to the table.
« Last Edit: May 08, 2010, 11:41:14 AM by Jeff_M »