Jump to content

Automatic number dimension


Recommended Posts

Hi When I want to dimension for the wall quantity, I want it to number each dimension. Is something like this possible? But it needs automatic numbering when dimensioning. Also, if you have any add-ons to share for the wall footage, I would like to receive them. And it would be much nicer if I could export them to excel. Thank you for your help

Görüntü 4.png

Link to comment
Share on other sites

Q1 yes could be done by using a lisp that adds the Dim x as the dimension override string "Dim 22 <>"


Q2 measure walls yes but it depends totally on how you draw the walls.



Q3 yes 2 ways do a CSV file or write direct to excel a bit harder.


Lets start Q1 I will let you wrap it as  a defun, same as if you don't like dim position then you need to google about changing dim text position.


(setq x (getint "\nEnter start number"))
(while (setq pt1 (getpoint "\nPick Pt1 or Enter to exit"))
(command "dimaligned" pt1 (getpoint "\nPt2") "T" (strcat "Dim " (rtos x 2 0) "\n <>") (getpoint "\nPick offset"))
(setq x (1+ x))


Link to comment
Share on other sites


test this is




(defun DP (side / *error* clay cmde styht plsel pl cw inc pt1 pt2 pt3 pt4)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (setvar 'clayer clay)
    (setvar 'osmode osm)
    (command-s "_.undo" "_end")
    (setvar 'cmdecho cmde)
  ); defun -- *error*

  (setq clay (getvar 'clayer) osm (getvar 'osmode) cmde (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (setvar 'osmode 0)
  (if (not *DPseq) (setq *DPseq 1))
    "_.undo" "_begin"
    "_.layer" "_make" "A-ANNO-DIMS" "_color" 2 "" "" ;; <---EDIT if desired
  ); command
  (setq styht (cdr (assoc 40 (tblsearch "style" (getvar 'dimtxsty))))); height of text style in current dimension style
  (if (= styht 0.0) (setq styht (* (getvar 'dimtxt) (getvar 'dimscale)))); if above is non-fixed-height

  (setq s (ssget '((0 . "*POLYLINE"))))
;;;  (while
;;;    (not
;;;      (and
;;;        (setq plsel (entsel "\nSelect Polyline: "))
;;;        (wcmatch (cdr (assoc 0 (entget (car plsel)))) "*POLYLINE")
;;;        (= (logand (cdr (assoc 70 (entget (car plsel)))) 88) 0)
;;;          ;; not 3D or mesh [88 = 8 (3D) + 16 (polygon mesh) + 64 (polyface mesh)]
;;;      ); and
;;;    ); not
;;;    (prompt "\nNothing selected, or not a LW or 2D Polyline.")
;;;  ); while

  (while (setq plsel (ssname s 0))
  (setq pl (vlax-ename->vla-object plsel))
  (vla-offset pl styht); temporary
  (setq cw (< (vla-get-area (vlax-ename->vla-object (entlast))) (vla-get-area pl)))
    ;; clockwise for closed or clearly inside/outside open; may not give
    ;; desired result for open without obvious inside/outside
  (entdel (entlast))
  (repeat (setq inc (fix (vlax-curve-getEndParam pl)))
      pt1 (vlax-curve-getPointAtParam pl inc)
      pt2 (vlax-curve-getPointAtParam pl (- inc 0.5)); segment midpoint
      pt3 (vlax-curve-getPointAtParam pl (1- inc))
    ); setq
    (if (equal (angle pt1 pt2) (angle pt2 pt3) 1e-8); line segment
      (command ; then
        "_.dimaligned" pt1 pt3
        "_text" (strcat (itoa *DPseq) ": <>")
      ); [leaves at dimension line location prompt]
      (command ; else [arc segment]
        "_.dimangular" ""
        (inters ; arc center
          (setq pt4 (mapcar '/ (mapcar '+ pt1 pt2) '(2 2 2)))
          (polar pt4 (+ (angle pt1 pt2) (/ pi 2)) 1)
          (setq pt4 (mapcar '/ (mapcar '+ pt2 pt3) '(2 2 2)))
          (polar pt4 (+ (angle pt2 pt3) (/ pi 2)) 1)
        ); inters
        pt1 pt3
            (itoa *DPseq) ": "
            (rtos (abs (- (vlax-curve-getDistAtParam pl inc) (vlax-curve-getDistAtParam pl (1- inc)))) 2 0)
            ;; [edit mode and precision and suffix as desired -- this is per request on AutoCAD Forum]
          ); strcat
      ); command [leaves at dimension line location prompt]
    ); if
    (command ; complete Dimension: dimension line location
          (if (or (and cw (= side "in")) (and (not cw) (= side "out"))) '- '+)
            (angle '(0 0 0) (vlax-curve-getFirstDeriv pl (- inc 0.5)))
            (/ pi 2)
          ); list
        ); apply
        (* styht 1.5)
          ;; [If you don't use stacked fractions, consider using styht without multiplier]
      ); polar
    ); command
      inc (1- inc)
      *DPseq (1+ *DPseq)
    ); setq
  ); repeat

  (ssdel plsel s)
  (setvar 'clayer clay)
  (setvar 'osmode osm)
  (command "_.undo" "_end")
  (setvar 'cmdecho cmde)
); defun -- C:DP

(defun C:DPI () (DP "in")); = Dimension Polyline Inside
(defun C:DPO () (DP "out")); = Dimension Polyline Outside

(prompt "\nType DPI to Dimension a Polyline on the Inside, DPO to do so on the Outside.")



Link to comment
Share on other sites

That's quite a complicated way of doing what BigAl did in 5 lines.....


My usual way of going is fewer simpler LISPs to remember but have them more versatile for many cases. So in this case using BigAl which will dimension lines and polylines and using the drawing set up for dimension style would be the way I would go as opposed to having a LISP just to dimension polylines with a defined dimension style, and by inference another LISP for lines, and another for gaps,  and another if I want to use a different dimension style (different clients for example)

Link to comment
Share on other sites






I want it to be dimensioned by marking, not this way. So when I mark the beginning and the end, it will be numbered sequentially. When I exit the command and want to continue again, the numbering will continue where I left off. thanks

Link to comment
Share on other sites

Give this program a try and let me know. :)


(defun c:Test (/ *error* 1pt 2pt old new hgt ins pos)
  ;; Tharwat - 27.Dec.2021	;;
  (defun *error* (msg)
  (or *dim:nos* (setq *dim:nos* 1))
      *dim:nos* (cond ((getint (strcat "\nSpecify increment number [ "
                                       (itoa *dim:nos*)
                                       " ] : "
    (setq 1pt (getpoint "\nSpecify first point dimension : "))
    (while (setq 2pt (getpoint "\nSpecify next point : " 1pt))
      (setq old (entlast))
      (command "_.DIMALIGNED" "_none" 1pt "_none" 2pt "\\")
        (not (= old (setq new (entlast))))
        (setq blk (tblobjname "BLOCK" (cdr (assoc 2 (entget new)))))
              (= (cdr
                   (assoc 0 (setq get (entget (setq blk (entnext blk)))))
        (setq ins (cdr (assoc 10 get)))
        (setq hgt (cdr (assoc 40 get)))
          (list '(0 . "TEXT")
                (cons 10
                        pos (polar ins
                                   (angle (polar 1pt
                                                 (angle 1pt 2pt)
                                                 (/ (distance 1pt 2pt) 2.0)
                                   (* hgt 1.5)
                (cons 11 pos)
                (cons 1 (strcat "Dim " (itoa *dim:nos*)))
                (assoc 40 get)
                (assoc 50 get)
                (assoc 7 get)
                '(71 . 0)
                '(72 . 1)
                '(73 . 2)
        (setq 1pt       2pt
              *dim:nos* (1+ *dim:nos*)


Link to comment
Share on other sites

Posted (edited)


Mr Bigal:

Thank you for your understanding Similar available but only transfers dimensions Let me transfer the naming that I want in order. thank you for your help

Dim1 260

Dim2 148




(defun C:dx (/ *error* abks aexc asht col data dim_data elist en i row row_data ss tmp xbks xcel xshs)

(defun *error*    (msg)
      '("console break"
    "Function cancelled"
    "quit / exit abort"
     (princ "Error!")
     (princ msg)

(if (setq ss (ssget (list (cons 0 "dimension"))))

    (setq i -1)
    (repeat (sslength ss)
      (setq en      (ssname ss (setq i (1+ i)))
        elist (entget en)
        tmp      (cons (cdr (assoc 11 elist)) (cdr (assoc 42 elist)))
        data  (cons tmp data))

    (setq dim_data (vl-sort data
                (function (lambda (e1 e2) (< (caar e1) (caar e2))))))
    (alert "Close Excel File Only")
    (setq aexc (vlax-get-or-create-object "Excel.Application")
      xbks (vlax-get-property aexc "Workbooks")
      abks (vlax-invoke-method xbks "Add")
      xshs (vlax-get-property abks "Sheets")
      asht (vlax-get-property xshs "Item" 1)
      xcel (vlax-get-property asht "Cells")
    (vla-put-visible aexc :vlax-true)
    (setq row 0
      col 1)

    (repeat (length dim_data)
      (setq row_data (car dim_data))
      (setq row (1+ row))
    (vl-princ-to-string (cdr row_data))
      (setq dim_data (cdr dim_data))


    (vlax-release-object xcel)
    (vlax-release-object asht)
    (vlax-release-object xshs)
    (vlax-release-object abks)
    (vlax-release-object xbks)
    (vlax-release-object aexc)
    (setq aexc nil)
  (*error* nil)
(prompt "\n\t\t>>>\tType DX to execute\t<<<\n")

Edited by aliscan
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.

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