Author Topic: How to extract the dimensions from a selection in to a table  (Read 1839 times)

0 Members and 1 Guest are viewing this topic.

siddik

  • Mosquito
  • Posts: 6
Hi
I was just searching for some lips or VBA code to extract dimentional text along with tolerances of each dimension to in different cell of a table in Autocad, my idea is to make a inspection report for each drawing in a sheet with a seperate table once the drawings are selected.

HOSNEYALAA

  • Newt
  • Posts: 103
Re: How to extract the dimensions from a selection in to a table
« Reply #1 on: June 01, 2021, 01:24:27 PM »
Attached example drawing
And
Example Table

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: How to extract the dimensions from a selection in to a table
« Reply #2 on: June 01, 2021, 09:01:32 PM »
Did you google ? Found an answer 1st item

"Dimensions to table Autocad"
A man who never made a mistake never made anything

siddik

  • Mosquito
  • Posts: 6
Re: How to extract the dimensions from a selection in to a table
« Reply #3 on: June 02, 2021, 09:48:25 AM »
Attached example drawing
And
Example Table

thanks for the reply, i have attached the sample drawing with the table, the idea is to extract each dimension with the balloon # to the table & print for the QC guy, after inspecting each part they will fill up the blank Part # row with the results.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: How to extract the dimensions from a selection in to a table
« Reply #4 on: June 02, 2021, 08:49:53 PM »
Ok a couple of problems and solutions.

1st use a Pt Num block this makes finding the number so much easier.

Next can use the pt num to find a dimension next to it.

Then can make table.

For me the process would be do all dims, do in an order. Select dims it would auto number you pick pt for bubble. Then seperate step do table.

Have a look at pt num bubble, it is possible to find last number before adding a new one.

Pt Num Bubble will do Alpha and squares.

Lastly Google attribute to table if get stuck just ask here.

« Last Edit: June 02, 2021, 08:57:33 PM by BIGAL »
A man who never made a mistake never made anything

HOSNEYALAA

  • Newt
  • Posts: 103
Re: How to extract the dimensions from a selection in to a table
« Reply #5 on: June 03, 2021, 04:13:17 AM »
Code: [Select]

;;;--------------------------------------------------------------------
;; HOSNEYALAA  02-06-2021
;;;--------------------------------------------------------------------
(defun Cre_Lay(lay_layn lay_laycol)
(if (= (tblsearch "Layer" lay_layn) nil)
(command "._Layer" "n" lay_layn "c" lay_laycol lay_layn "")
(command "._Layer" "t" lay_layn "on" lay_layn "c" lay_laycol lay_layn "")
)
(princ)
)
;;;--------------------------------------------------------------------
(defun C:testTD( / ss L e LLL LS1 s x y doc objtable numrows rowheight pt1 colwidth curspace Z)


  (setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table: ")))
   (princ "\nSelect LWpolylines to export to a Table :")
(setq s (ssget '((0 . "DIMENSION"))))
  (setq
   
    L 0.0
)
 (cre_lay "PntDIM" "62")
(vl-load-com)
(setq ptCntr 1)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq curspace (vla-get-modelspace doc))

 (setq numrows (+ 2 (sslength s)))
(setq numcolumns 6)
(setq rowheight 7)
(setq colwidth 25)
(setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth))
(vla-settext objtable 0 0 " Drg #: xxxx")
(vla-setcolumnwidth objtable 0 25)
(vla-setcolumnwidth objtable 1 25)
(vla-settext objtable 1 0 "Balloon #")
(vla-settext objtable 1 1 "Dimensions")
(vla-settext objtable 1 2 "Tolerances")
(vla-settext objtable 1 3 "Part #1")
(vla-settext objtable 1 4 "Part #2")
(vla-settext objtable 1 5 "Part # n")
 
(vla-SetTextHeight Objtable (+ acDataRow acHeaderRow acTitleRow) 2.5)
(vla-SetAlignment Objtable acDataRow acMiddleCenter)





 
(setq x 1)
(SETQ Y 2)


 
(while (setq e (ssname s 0))

  (vla-settext objtable Y 0 (itoa ptCntr))
  (setq fPoint(vlax-get(vlax-ename->vla-object e)'TEXTPOSITION))

 
 (mip-text-entmake
     (itoa ptCntr)           ;;; text
      fPoint                   ;;; point
     1 ;;; heigth
     0                     ;;; rotation
     "M"                   ;;; justification
     )


 
;; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;; =   C R C L E   O B J E C T 
;; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   (entmake (list (cons 0 "CIRCLE") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 fPoint) ;***
               (cons 39 0.0)
               (cons 40 0.6) ; radius
               (cons 62 256)
               (cons 210 (list 0.0 0.0 1.0))))


 
  (if (/= (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) "")
    (progn
  (vla-settext objtable Y 1 (strcat (rtos (vlax-get(vlax-ename->vla-object e)'measurement) 2 1)" " (cadr(str2list (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) " "))" " (caddr(str2list (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) " "))))
;;;  (vla-settext objtable Y 2 " ")
;;;    (vla-settext objtable Y 3 " ")
;;;    (vla-settext objtable Y 4 " ")
;;;    (vla-settext objtable Y 5 " ")
  )
  )



 
  (if (and
          (= (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) "")
          (/= (vlax-get(vlax-ename->vla-object e)'tolerancedisplay) 0)
          )
    (progn
  (vla-settext objtable Y 1 (rtos (vlax-get(vlax-ename->vla-object e)'measurement) 2 2))
   (if (= (vlax-get(vlax-ename->vla-object e)'tolerancedisplay) 2)
     (vla-settext objtable Y 2 (strcat
                                 (if (/= 0 (vlax-get(vlax-ename->vla-object e)'toleranceupperlimit))
                                 (strcat "+"(rtos (vlax-get(vlax-ename->vla-object e)'toleranceupperlimit) 2 2))
                                   (strcat(rtos (vlax-get(vlax-ename->vla-object e)'toleranceupperlimit) 2 0))
                                   )
                                 "/"
                                 (if (= 0 (vlax-get(vlax-ename->vla-object e)'tolerancelowerlimit))
                                  (strcat (rtos (vlax-get(vlax-ename->vla-object e)'tolerancelowerlimit) 2 0))
                                   (strcat "- "(rtos (vlax-get(vlax-ename->vla-object e)'tolerancelowerlimit) 2 2))
                                 )
                                 );;(strcat
                  )
     (vla-settext objtable Y 2 (strcat "+-"
                                 (if (/= 0 (vlax-get(vlax-ename->vla-object e)'toleranceupperlimit))
                                 (strcat (rtos (vlax-get(vlax-ename->vla-object e)'toleranceupperlimit) 2 2))
                                   (strcat(rtos (vlax-get(vlax-ename->vla-object e)'toleranceupperlimit) 2 0))
                                   )
;;;                                 "/"
;;;                                 (if (= 0 (vlax-get(vlax-ename->vla-object e)'tolerancelowerlimit))
;;;                                  (strcat (rtos (vlax-get(vlax-ename->vla-object e)'tolerancelowerlimit) 2 0))
;;;                                   (strcat(rtos (vlax-get(vlax-ename->vla-object e)'tolerancelowerlimit) 2 2))
;;;                                 )
                                 );;(strcat
                  )
  )
    )
    )


 
    (if (and
          (= (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) "")
          (= (vlax-get(vlax-ename->vla-object e)'tolerancedisplay) 0)
          )
 
      (progn
           (vla-settext objtable Y 1 (rtos (vlax-get(vlax-ename->vla-object e)'measurement) 2 2))
        )
   
    )



;;; 
;;;  (cadr(str2list (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) " "))
;;;  (strcat (cadr(str2list (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) " "))" " (caddr(str2list (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) " ")))
;;;  ((  (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE))
;;;  (LM:parsenumbers  (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE))
;;;    (setq L (+ L (vlax-get(vlax-ename->vla-object e)'measurement)))
;;;    (setq LLL (vlax-get(vlax-ename->vla-object e)'measurement))
;;;   
;;;;;;    (setq ePoint(vlax-curve-getEndPoint e))
;;;  (vla-settext objtable Y 0 (strcat (rtos (vlax-get(vlax-ename->vla-object e)'measurement) 2 1)" " (cadr(str2list (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) " "))" " (caddr(str2list (vlax-get(vlax-ename->vla-object e)'TEXTOVERRIDE) " "))))
;;;    (vla-settext objtable Y 0 (itoa ptCntr))
;;;    (vla-settext objtable Y 1 (rtos LLL 2 3))
;;;    (vla-settext objtable Y 2 (rtos L 2 3))
;;;   
;;;;;;    (command "._Change" e "" "p" "layer" "PntNum" "")
;;;;;;    (command "._Change" e "" "p" "COLOR" "50" "")
;;;;;;    (command "._Change" e "" "p" "LWeight" "1" "")

 
 
   (setq x (1+ x ))
    (setq y (1+ Y ))
  (setq ptCntr(+ ptCntr 1))
  (ssdel e s)
)

)
;;;--------------------------------------------------------------------






   ;;;str2list by John Uhden, as posted to the adesk customization newsgroup a long time ago
 (defun Str2List (str pat / i j n lst)
  (cond
    ((/= (type str) (type pat) 'STR))
    ((= str pat) '(""))
    (T
     (setq i 0
   n (strlen pat)
     )
     (while (setq j (vl-string-search pat str i))
       (setq lst (cons (substr str (1+ i) (- j i)) lst)
     i (+ j n)
       )
     )
     (reverse (cons (substr str (1+ i)) lst))
    )
  )
)


 
 
(defun mip-text-entmake (txt pnt height rotation justification / ent_list)
 ;;; borrowed from ShaggyDoc
 ;;; http://www.caduser.ru/forum/index.php?PAGE_NAME=read&FID=23&TID=30276
 ;;; Draw text with entmake Lisp function
 ;;; Arguments:
 ;;; txt - text string
 ;;; pnt - point in WCS
 ;;; height - text height
 ;;; rotation - rotation angle
 ;;; justification - justification or nil

 (setq  ent_list (list  '(0 . "TEXT")
    '(100 . "AcDbEntity")
    '(100 . "AcDbText")
    (list 10 (car pnt) (cadr pnt) 0.0)
    (cons 1 txt)
    (cons 40 height)
    (cons 7 (getvar "TEXTSTYLE"))
    (if justification
      (cond
        ((= justification "C")
         '(72 . 1)
        )
        ((= justification "R")
         '(72 . 2)
        )
        ((= justification "A")
         '(72 . 3)
        )
        ((= justification "M")
         '(72 . 4)
        )
        ((= justification "F")
         '(72 . 5)
        )
        (t
         '(72 . 0)
        )
      ) ;_ end of cond
      '(72 . 0)
    ) ;_ end of if
     (cons 62 1)                   
    (cons 50 rotation)
    (list 11 (car pnt) (cadr pnt) 0.0)
    ) ;_ end of list
  ) ;_ end of setq
  (setq ent_list (entmakex ent_list))
)



siddik

  • Mosquito
  • Posts: 6
Re: How to extract the dimensions from a selection in to a table
« Reply #6 on: June 03, 2021, 10:35:53 AM »
thanks a lot dear ! it is working

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: How to extract the dimensions from a selection in to a table
« Reply #7 on: June 03, 2021, 08:54:50 PM »
Hosneyalaa nice solution, rather than circle and text have a look at ptnum bubble.lsp has the entmake for a block Circle or Square with 1 attribute, much easier to use than circle and a text, your welcome to use it.
A man who never made a mistake never made anything

HOSNEYALAA

  • Newt
  • Posts: 103
Re: How to extract the dimensions from a selection in to a table
« Reply #8 on: June 05, 2021, 03:18:26 AM »
 BIGAL  thanks

I am little
  Dealing with the block

siddik

  • Mosquito
  • Posts: 6
Re: How to extract the dimensions from a selection in to a table
« Reply #9 on: June 08, 2021, 09:09:03 AM »
 Dear HOSNEYALAA

one more issue, the created table & bubbles should be in the new layer , ie: PntDIM

also i have multiple drawings in a single sheet(model space) is it possible to send each drawing & table to a separate layout with name of the layout as Drg # xxxx??

the Header of the table should populate the Drg # xxxx (note xxxx can be any number added below the drawing as attribute)

i have added a prompt for number of column to get added once the user enters the value & Number of column are increased by that number, but the column header should also get change with total number of parts for inspection, like part # 1 , part # 2 bla bla bla
excluding Balloon #, Dimensions & Tolerances column

HOSNEYALAA

  • Newt
  • Posts: 103
Re: How to extract the dimensions from a selection in to a table
« Reply #10 on: June 08, 2021, 11:16:01 AM »
Can you attach an example drawing?
or an animated picture
Because my English is not good
 I did not understand you well

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: How to extract the dimensions from a selection in to a table
« Reply #11 on: June 08, 2021, 08:54:42 PM »
If you have changed the code provided post the code as makes trouble shooting easier.

Yes can select in model then make a new layout with table is possible.
A man who never made a mistake never made anything