How to give centre to center dimension to row of blocks?

How to give centre to center dimension to row of blocks?

Anonymous
Not applicable
1,443 Views
8 Replies
Message 1 of 9

How to give centre to center dimension to row of blocks?

Anonymous
Not applicable
Hi All,
My Boss tell me a very tedious task, I have number of blocks in rows & columns in my drawing. I have to give center to center dimension to these blocks.
Is it possible to select one row or column of blocks and give a continuous dimension at ones.
Please Help!!
0 Likes
Accepted solutions (2)
1,444 Views
8 Replies
Replies (8)
Message 2 of 9

_Tharwat
Advisor
Advisor
Accepted solution

Hi,

Try this program and let me know:

 

 (defun c:DimBlks ( / int sel dir opr obj lst fst pos cmd ang)
;; Tharwat - Date: 30.Aug.2017 ;;
(if (and (princ "\nSelect blocks to connect them with dimensions :")
(setq int -1 sel (ssget '((0 . "INSERT"))))
(progn (initget "Vertical Horizontal")
(setq dir (cond ((getkword "\nSpecify direction of dimensions [Vertical Horizontal] <Vertical>: "))
("Vertical"))
)
)
)
(progn (if (= dir "Vertical") (setq opr 'cadr ang pi)
(setq opr 'car ang (* pi 0.5))
)
(while (setq obj (ssname sel (setq int (1+ int))))
(setq lst (cons (cdr (assoc 10 (entget obj))) lst))
)
(setq lst (vl-sort lst '(lambda (a b) (< ((eval opr) a) ((eval opr) b))))
fst (car lst)
pos (polar fst ang 1.0) ;; Change offset value <1.0> to your desired one.
cmd (getvar 'CMDECHO)
)
(setvar 'CMDECHO 0)
(foreach ins (cdr lst)
(command "_.DIMLINEAR" "_none" fst "_none" ins "_none" pos)
(setq fst ins)
)
(setvar 'CMDECHO cmd)
)
)
(princ)
)

 

 

Message 3 of 9

Anonymous
Not applicable
Hi Tharwat,
Thanks a lot...
It works really great. 👍
0 Likes
Message 4 of 9

_Tharwat
Advisor
Advisor

@Anonymous wrote:
Hi Tharwat,
Thanks a lot...
It works really great. 👍

You are most welcome. 

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

Here's another [and shorter!] way to do it [insertion-point-to-insertion-point, whether or not that coincides with "center-to-center" positions].  It takes advantage of the QDIM command, which avoids the necessity of sorting the Blocks by position relative to the desired direction of the Dimensions, and even avoids the necessity of telling it which direction you want the Dimensions to run, as long as you give it a reasonable point for the string location in relation to the selected Blocks.  Lightly tested:

 

(defun C:QDB (/ ss pt lines n)
  ; = Quick-Dimension string of Blocks [Kent Cooper, 30 August 2017]
  (prompt "\nTo Dimension a string of Blocks,")
  (if (setq ss (ssget '((0 . "INSERT"))))
    (progn ; then
      (setq
        pt (getpoint "\nPosition of Dimension string: ")
        lines (ssadd); initially empty
      ); setq
      (repeat (1- (setq n (sslength ss)))
        (command "_.line"
          "_none" (cdr (assoc 10 (entget (ssname ss (setq n (1- n))))))
          "_none" (cdr (assoc 10 (entget (ssname ss (1- n)))))
          ""
        ); command
        (ssadd (entlast) lines)
      ); repeat
      (command "_.qdim" lines "" pt "_.erase" lines "")
    ); progn
  ); if
  (princ)
); defun

 

Kent Cooper, AIA
0 Likes
Message 6 of 9

_Tharwat
Advisor
Advisor

Be careful if the current layer is locked.

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

Come to think of it, if you don't mind seeing the temporary Lines drawn around between the Block insertion points, while the QDIM command is asking for a position for the Dimension string, you don't even need to ask for that ahead of time.  It makes it even shorter, eliminating the 'pt' variable.

 

(defun C:QDB (/ ss dir lines n)
  ; = Quick-Dimension string of Blocks [Kent Cooper, 30 August 2017]
  (prompt "\nTo Dimension a string of Blocks,")
  (if (setq ss (ssget '((0 . "INSERT"))))
    (progn ; then
      (setq lines (ssadd)); initially empty
      (repeat (1- (setq n (sslength ss)))
        (command "_.line"
          "_none" (cdr (assoc 10 (entget (ssname ss (setq n (1- n))))))
          "_none" (cdr (assoc 10 (entget (ssname ss (1- n)))))
          ""
        ); command
        (ssadd (entlast) lines)
      ); repeat
      (command "_.qdim" lines "" pause "_.erase" lines "")
    ); progn
  ); if
  (princ)
); defun
Kent Cooper, AIA
Message 8 of 9

Kent1Cooper
Consultant
Consultant

@_Tharwat wrote:

Be careful if the current layer is locked.


Well, yes, that's a possibility, however remote.  Also be careful if it's turned Off, which is  also possible, if even more unlikely.  And the usual stuff [*error* handler, Undo begin/end wrapper, forcing to a Dimensioning Layer and Style if desired, etc.] could be added to all the routines on this thread.

Kent Cooper, AIA
0 Likes
Message 9 of 9

Anonymous
Not applicable
Thanks Kent1Cooper,
Works Great too..👍
0 Likes