Jump to content

Extract the attributes, and written table (help)


andy_lee

Recommended Posts

Try this and let me know how you would get on with it .

 

(defun c:Test (/ ss hgt pt n i sn tg lst l c r inc tbl st dups pns wrt nu)
 ;;    Author : Tharwat Al Shoufi                        ;;
 ;;    Date : 15. November. 2014                        ;;
 ;; Write a special kind of attributes to AutoCAD table        ;;
 (if
   (and
     (if (tblsearch "STYLE" "SIMPLEX")
       t
         (progn
           (alert "Text Style < SIMPLEX > is not found in Drawing !")
           nil
         )
       )
     (princ "\n Select named blocks < TitleBar > :")
     (setq ss (ssget '((0 . "INSERT") (66 . 1) (2 . "TitleBar"))))
     (setq
       *hgt* (cond ((getdist (strcat "\n Specify Text Height < "
                                     (if *hgt*
                                       (rtos *hgt* 2 2)
                                       (rtos (setq *hgt* 1.0) 2 2)
                                     )
                                     " > :"
                             )
                    )
                   )
                   (*hgt*)
             )
     )
     (setq pt (getpoint "\n Specify Base Point of Table :"))
   )
    (progn
      (setq hgt *hgt*
            n   -1
      )
      (repeat (setq i (sslength ss))
        (setq sn (ssname ss (setq i (1- i))))
        (mapcar
          '(lambda (x)
             (if (or (eq (setq tg (strcase (vla-get-tagstring x)))
                         "DRAWINGNO."
                     )
                     (eq tg "PARTNAME")
                     (eq tg "MATERIAL")
                     (eq tg "QTY")
                 )
               (setq lst (cons (vla-get-textstring x) lst))
             )
           )
          (vlax-invoke (vlax-ename->vla-object sn) 'getattributes)
        )
        (setq l   (cons lst l)
              lst nil
        )
      )
      (setq l
             (vl-sort
               l
               '(lambda (n i)
                  (<
                    (atoi (substr (setq st (cadr n)) (- (strlen st) 2))
                    )
                    (atoi (substr (setq st (cadr i)) (- (strlen st) 2))
                    )
                  )
                )
             )
      )
      (or acdoc
          (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
      )
      (setq c   5
            r   2
            inc -1
            tbl (vla-addtable
                  (vla-get-modelspace acdoc)
                  (vlax-3d-point (trans pt 1 0))
                  (+ (length l) r)
                  c
                  (* hgt 2.5)
                  (* hgt 2.5)
                )
      )
      (if (tblsearch "LAYER" "dim")
        (vla-put-layer tbl "dim")
      )
      (mapcar
        '(lambda (h) (vla-setcolumnwidth tbl (setq inc (1+ inc)) h))
        (mapcar '(lambda (x) (* hgt x))
                '(5. 10.5 7. 7. 7.)
        )
      )
      (setq inc -1)
      (repeat (+ (length l) r)
        (vla-setrowheight tbl (setq inc (1+ inc)) (* hgt 1.2))
      )
      (defun _settext (c st)
        (vla-settext tbl r c st)
        (vla-setcelltextstyle tbl r c "SIMPLEX")
        (vla-SetCellTextHeight tbl r c hgt)
        (vla-setcellalignment tbl r c acMiddleCenter)
        (vla-setrowheight tbl r (* hgt 1.2))
      )
      (setq r 1)
      (mapcar '_settext
              (list 0 1 2 3 4)
              '("NO." "Drawing No." "Part Name" "Material" "Quantity")
      )
      (setq r 2
            c 0
            i -1
      )
      (foreach v l
        (if (or (member (cadr v) dups)
                (member (strcase (car v)) pns)
            )
          (setq wrt (list (strcat "{\\C1;" (cadr v) "}")
                          (strcat "{\\C1;" (car v) "}")
                          (strcat "{\\C1;" (caddr v) "}")
                          (strcat "{\\C1;" (nth 3 v) "}")
                    )
                red t
          )
          (setq dups (cons (cadr v) dups)
                pns  (cons (strcase (car v)) pns)
                wrt  (list (cadr v) (car v) (caddr v) (nth 3 v))
                red  nil
          )
        )
        (setq i (1+ i))
        (if (< i 10)
          (setq nu (strcat "0" (itoa i)))
          (setq nu (itoa i))
        )
        (_settext
          c
          (if red
            (strcat "{\\C1;" nu "}")
            nu
          )
        )
        (foreach txt wrt
          (_settext (setq c (1+ c)) txt)
        )
        (setq c 0
              r (1+ r)
        )
      )
      (princ)
    )
 )
 (princ)
)

Edited by Tharwat
Link to comment
Share on other sites

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

  • andy_lee

    31

  • Tharwat

    22

  • hanhphuc

    7

  • hmsilva

    1

Top Posters In This Topic

Posted Images

Try this and let me know how you would get on with it .

 

Thanks very much !Tharwat. You are my benefactor .:thumbsup:

 

Very nice! beautiful !

There is a little insufficient

1. I need the table layer is "dim"

2. and same name(PARTNAME, DRAWING NO) exists,but no pot-up tips, why?

Link to comment
Share on other sites

Thanks very much !Tharwat. You are my benefactor .:thumbsup:

 

Very nice! beautiful !

 

You are welcome :)

 

2. and same name(PARTNAME, DRAWING NO) exists,but no pot-up tips, why?

 

I did not get it well , can you explain it in more details or with an image if that is easy for you ?

Link to comment
Share on other sites

You are welcome :)

 

I did not get it well , can you explain it in more details or with an image if that is easy for you ?

 

t.gif

 

Same name, but without prompting

 

Maybe duplicate names, can use red font display .

Link to comment
Share on other sites

Lots of changes considered in the above modified lisp routine , so try it and let me know .

 

CODES UPDATED ABOVE.

 

Master Tharwat, I appriciate your help! Thank you for your effort.

Near perfect!

DRAWING NO.duplicate Can identify .But PARTNAME duplicate can't identify.

Link to comment
Share on other sites

Really ? what does the routine do then ?

 

Master Tharwat, the routine is very difficult to do it ?

Previous, must "DRAWING NO " is exactly the same , can check out , But two DRAWING NO is 1-SS706A-030 & 2-SS706A-030, It is not allowed in ERP.

Link to comment
Share on other sites

Settle all your things of the program up first then write them all here clearly , otherwise I can not keep on guessing which is right and suitable for your needs .

 

I'm so sorry! sorry for my english. Master Tharwat.

your routine has reached 99.7% ,:D

 

0.1

t3.png

 

0.2

t2.png

 

0.3 If possible ,at last( after insert table), Deciding whether to output to xls(or csv)

t4.png

 

This picture explaining what i mean. Hope that would be clearer.

Thanks so much! Master Tharwat.

Link to comment
Share on other sites

01 : do you want to avoid including the duplicate drawing number into the table ? Show me with a sample drawing Before and After with the outcome you want .

02 : easy to add the BOM .

03 : you can export contents of any AutoCAD Table to Excel if you right click on the table and chose export ...

Link to comment
Share on other sites

01 : do you want to avoid including the duplicate drawing number into the table ? Show me with a sample drawing Before and After with the outcome you want .

2.gif

The DRAWING NO "2-SS706A-030" and "1-SS706A-030" ,the last(end) three digits is the same ! so need Red font .

 

 

This is the right.

sshot-5.png

 

 

 

02 : easy to add the BOM .

03 : you can export contents of any AutoCAD Table to Excel if you right click on the table and chose export ...

Great!!!:thumbsup:

Link to comment
Share on other sites

So you want the last two rows to be in red since there are with the same Drawing No. ?

 

sshot-5.png

 

you are right .

row 13 and row 14 have same Drawing NO. ,so row 14 need to be in red since .

Link to comment
Share on other sites

[ATTACH=CONFIG]51622[/ATTACH]

 

row 13 and row 14 have same Drawing NO. ,so row 14 need to be in red since .

 

Maybe you wanted to say 13 and 14 instead of ONLY 14 since they have the same Drawing No. in the two rows ?

Link to comment
Share on other sites

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