Author Topic: [Help] Tweak process of making Table  (Read 1201 times)

0 Members and 1 Guest are viewing this topic.

Ketxu

  • Newt
  • Posts: 105
[Help] Tweak process of making Table
« on: December 21, 2011, 02:23:01 AM »
I write a little code to make a Table that count the attribute (and make some of random of elevation of floor - for my job - Contrucstion Engineer). But i can't belive how it slow. With about more than 3 item, it took me long long long time to create.
It must have some problem in my code, but i can't find
Please test and help me.
Sorry for my poor English

Code: [Select]
(defun C:SHCD(/ lstCol lstCol_Can lstRow ss lstAll sty htext lay iText iMlist iMlist2 iDxf iNum2str col socan i row cao rong vla_table
lstCan lstCol_CDTK lstCol_SS)

(setq ss(ST:SS->List-Vla (ssget (list (cons 0 "INSERT")(cons 66 1)(cons 2 "STT")))))
(setq lstAll
(vl-sort (mapcar '(lambda(x)(cons (GetAttributeValue x "STT") (GetAttributeValue x "CAODO"))) ss) '(lambda(x y)(< (atoi (car x))(atoi (car y)))))
)

(setq 
sty  (cadr (setq tmp (GetAttributeStyles (car ss) "STT")))
hText (last tmp)
lay (cadr tmp)
iText (lambda(hang cot giatri)(vla-settext vla_table hang cot giatri))
iMList (lambda(item num / lstTmp)(reverse(repeat num (setq lstTmp (cons item lstTmp)))))
iMlist2 (lambda(start end / lstTmp)(setq start (1- start))(reverse(repeat (- end start)(setq lstTmp (cons (setq start (1+ start)) lstTmp)))))
iDxf (lambda(dxf en)(cdr(assoc dxf (entget en))))
iNum2Str (lambda(num / rt )(setq num (abs num) rt (if (< num 10)(strcat "0" (itoa num))(itoa num))))

col (+ (* 2 (setq socan(getint "\nNumber of Item :"))) 2)
i -1
row (+ (length lstAll) 3)
lstRow (iMlist2 2 (- row 2))
cao (* hText 2.5) rong (* hText 7)
vla_table (vla-addtable (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point (getpoint "\n\U+0110i\U+1EC3m \U+0111\U+1EB7t BTK :")) row col cao rong)
lstCol (reverse (repeat col (setq lstCol (cons (setq i (1+ i)) lstCol))))
lstAction (list acTitleRow acHeaderRow acDataRow)
i 0 j 0
)
(vla-deleterows vla_table 0 1)
(vla-SetColumnWidth vla_table 0 (/ cao 1.2))
(vla-SetColumnWidth vla_table 1 (* cao 2))
(mapcar '(lambda(cot)(vla-SetColumnWidth vla_table cot (* cao 2))) (cddr lstcol))
(mapcar '(lambda(x)(vla-SetTextHeight vla_table x hText)) lstAction)
(mapcar '(lambda(x)(vla-SetTextStyle vla_table x sty)) lstAction)
(setq lstCan (reverse (repeat (/ (- col 2) 2) (setq lstCan (cons (strcat "CN S " (itoa (setq j (1+ j)))) lstCan)))))
(setq lstCol_Can (mapcar '(lambda(x) (* 2 (1+ (vl-position x lstCan)))) lstCan)
lstCol_CDTK lstCol_Can
lstCol_SS (mapcar '1+ lstCol_can)
)
(iText 0 0 "V TR")
(itext 0 1 "CAO THIT K")
(mapcar 'Itext (iMList 0 (length lstCol_Can)) lstCol_Can lstCan)
(mapcar 'Itext (iMlist 1 (length lstCol_CDTK)) lstCol_CDTK (iMlist "CAO THC T" (length lstCol_CDTK)))
(mapcar 'Itext (iMlist 1 (length lstCol_SS)) lstCol_SS (iMlist "SAI S (MM)" (length lstCol_SS)))
(mapcar '(lambda(x)(vla-SetCellAlignment vla_table i x acMiddleCenter))lstCol)
(setq i 1 j 0)
(foreach item lstAll
(iText (setq i (1+ i)) 0 (car item))
(iText i 1 (strcat "+"(cdr item)))
(repeat (/ (length (cddr lstCol)) 2)
(itext i (setq j (+ j 2)) (strcat "+"(rtos (setq numtmp (ran1 (atoi (cdr item))(+ (atoi (cdr item)) 5))) 2 0)))
(itext i (1+ j) (strcat "+" (rtos (- numtmp (atoi (cdr item))) 2 0)))
)
(setq j 0)
)
(foreach row (cons 1 lstRow)
(foreach col lstCol
(vla-SetCellAlignment vla_table row col acMiddleCenter)
)
)
)









(defun ST:SS->List-Vla (ss / n e l)
  (setq n (sslength ss))
  (while (setq e (ssname ss (setq n (1- n))))
    (setq l (cons (vlax-ename->vla-object e) l))
  )
)
(defun ran1 (min max / digits)
(setq digits (substr (rtos (rem (getvar 'date) 1) 2 16) 13))
(+
min
(*
(atof (strcat "0." (substr digits 6) (substr digits 1 5)))
(- max min)
); end *
); end +
)
(defun GetAttributeStyles( block tag )
(setq tag (strcase tag))
  (vl-some
    (function
      (lambda ( attrib )
        (if (eq tag (strcase (vla-get-Tagstring attrib)))
          (list
  (vla-get-Layer attrib)
  (vla-get-StyleName attrib)
  (vla-get-Height attrib)
  )  
        )
      )
    )
    (vlax-invoke block 'GetAttributes)
  )
)
(defun GetAttributeValue ( block tag ) (setq tag (strcase tag))
  (vl-some
    (function
      (lambda ( attrib )
        (if (eq tag (strcase (vla-get-Tagstring attrib)))
          (vla-get-TextString attrib)
        )
      )
    )
    (vlax-invoke block 'GetAttributes)
  )
)

fixo

  • Guest
Re: [Help] Tweak process of making Table
« Reply #1 on: December 21, 2011, 03:37:28 AM »
After this: vla_table (vla-addtable (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))....
add this line:
(vla-put-regeneratetablesuppressed vla_table :vlax-true)
and at the end of populating this table put this line:
(vla-put-regeneratetablesuppressed vla_table :vlax-false)

~'J'~

Ketxu

  • Newt
  • Posts: 105
Re: [Help] Tweak process of making Table
« Reply #2 on: December 21, 2011, 03:43:00 AM »
Oh my god, it is what i'm looking for. Thank Fixo so so much ^^ i 'ven't work with Table before and this is the first time. It has many of property and method
« Last Edit: December 21, 2011, 04:17:37 AM by Ketxu »