Separating data from a table depending on the value of the first column

Separating data from a table depending on the value of the first column

Anonymous
Not applicable
898 Views
5 Replies
Message 1 of 6

Separating data from a table depending on the value of the first column

Anonymous
Not applicable

I want to make a LISP that would enable me to select a table, then it would separate it's content depending on the value of the first column. It kind of work because it separates the data, but I have to click between each bit of text being placed.. I'd also like the table to disappear once the text has been placed.

 

This is the original matrix

 

Img1.png

 

Here's what I want it to do

 

Img5.png

 

Here's my code so far :

 

(defun c:midz  (/ c ctr dat etdata ind lst prefix r tab tblent tblobj val varname)

  (setq snapMode (getvar "osmode"))                                                                  ;Enlève le Object Snap (F3)
  (setvar "osmode" 0)

  (setq maximum (getint "\n Nombre de lignes: "))

 (setq etdata (entget (setq tblent (car (entsel "\nSelect table object: "))))
       ind    (cdr (assoc 91 etdata))
       tab    (cdr (assoc 92 etdata))
       r      0
       c      0
       ctr    1
       prefix "var"
       tblobj (vlax-ename->vla-object tblent))
 (while (< c tab)
  (while (< r ind)
   (set (setq varname (read (strcat prefix (itoa ctr))))
        (setq val (vlax-invoke tblobj 'getcellvalue r c)))
   (setq lst (cons (setq dat (cons varname val)) lst))
   (setq ctr (if (listp (cdr dat))
              ctr
              (1+ ctr))
         r   (1+ r)))
  (setq r 0
        c (1+ c)))
 (vl-remove-if '(lambda (x) (listp (cdr x))) (reverse lst))
 
  (setq iteration 1)
  (setq yvalue1 27.75)
  (setq yvalue2 27.75)

(while (<= iteration maximum)
  (if (= (eval (read (strcat "var" (itoa iteration)))) 1)

    (command "_text" "J" "M" (strcat "-53.5," (rtos yvalue1)) "4" "0" (eval (read (strcat "var" (itoa (+ iteration maximum)))))
      (setq yvalue1 (+ yvalue1 -30.5)))
    )
 
     (setq iteration (1+ iteration)))

  (setq iteration 1)
  (while (<= iteration maximum)
  (if (= (eval (read (strcat "var" (itoa iteration)))) 2)

    (command "_text" "J" "M" (strcat "153.5," (rtos yvalue2)) "4" "0" (eval (read (strcat "var" (itoa (+ iteration maximum)))))
      (setq yvalue2 (+ yvalue2 -30.5)))
    )
 
     (setq iteration (1+ iteration)))

 (princ))

0 Likes
Accepted solutions (1)
899 Views
5 Replies
Replies (5)
Message 2 of 6

pbejse
Mentor
Mentor

@Anonymous wrote:

I want to make a LISP that would enable me to select a table, then it would separate it's content depending on the value of the first column...


And place it where and what format? 

 

0 Likes
Message 3 of 6

Anonymous
Not applicable

If it's a 1, at [-53.5;27.75], then the next 1 [-53.5; (27.75-30.5)]

If it's a 2, at [153.5;27.75], then the next 2 [153.5; (27.75-30.5)]

 

for the format it's "_text" "J" "M" [location] "4" "0"

0 Likes
Message 4 of 6

DannyNL
Advisor
Advisor
Accepted solution

Ok, try this.

Code is written specifically for your purpose as described but can easily be modified to be more flexible.

 

(defun c:Test (/ T_Entity T_Object T_Count T_TextPosition T_ValueList T_Point1X T_Point1Y T_Point2X T_Point2Y T_StepY T_OldVars T_VarList T_TextPoint)
   (if
      (and
         (setq T_Entity (car (entsel "\nSelect table: ")))
         (= (vla-get-ObjectName (setq T_Object (vlax-ename->vla-object T_Entity))) "AcDbTable")
         (= (vla-get-Columns T_Object) 2)
      )
      (progn         
         (repeat (setq T_Count (vla-get-Rows T_Object))
            (if
               (member (setq T_TextPosition (atoi (vla-GetText T_Object (setq T_Count (1- T_Count)) 0))) '(1 2))
               (setq T_ValueList (append T_ValueList (list (list T_TextPosition (vla-GetText T_Object T_Count 1)))))
            )
         )
         (if
            T_ValueList
            (progn
               (setq T_Point1X -53.5)
               (setq T_Point1Y 27.75)
               (setq T_Point2X 153.5)
               (setq T_Point2Y 27.75)
               (setq T_StepY   -30.5)
               (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))               
               (setq T_OldVars (mapcar 'getvar (setq T_VarList '("CMDECHO" "OSMODE"))))
               (mapcar 'setvar T_VarList '(0 0))
               (foreach T_Item (reverse T_ValueList)
                  (if
                     (= (car T_Item) 1)
                     (progn
                        (setq T_TextPoint (list T_Point1X T_Point1Y))
                        (setq T_Point1Y (+ T_Point1Y T_StepY))
                     )
                     (progn
                        (setq T_TextPoint (list T_Point2X T_Point2Y))
                        (setq T_Point2Y (+ T_Point2Y T_StepY))
                     )
                  )
                  (command "_TEXT" "J" "M" T_TextPoint "4" "0" (cadr T_Item))
               )
               (vla-Delete T_Object)
               (mapcar 'setvar T_VarList T_OldVars)
               (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
            )
         )                     
      )
   )
   (princ)
)

 

Message 5 of 6

Anonymous
Not applicable

Yes it does exactly what I want it to do! Thank you very much! I'll still have to analyse the script to understand how it works but thank you very much Danny!

0 Likes
Message 6 of 6

DannyNL
Advisor
Advisor

You're welcome and glad I could help Smiley Happy

And if there is some part you can't figure out, let me know and I'll try to explain.

0 Likes