Adjustment Extended line of Dimension and Justify for Dimension Text

Adjustment Extended line of Dimension and Justify for Dimension Text

Vuxvix
Advocate Advocate
3,279 Views
13 Replies
Message 1 of 14

Adjustment Extended line of Dimension and Justify for Dimension Text

Vuxvix
Advocate
Advocate

Hi!
This is my first time posting. Although I found a lot of solutions to my other problem. However, this time I have not found a suitable solution to this my problem.
I have 2 problems: Extend line and Dimension text.
1.Extend line: [IMG1]
-I use the attached Lisp to "trim" ext Lines. (select the parallel and linear dimensions. And specify the position of the line pins) No2-IMG1.
-The Cons of this lisp. when specifying the line foot at the dimension line. then re-command will cause the dimesion jump. No3-IMG1.
>>> I want to select all dimensions (Rotated and Align dim ..) and change the length of the Ext lines to 0 or very small. So that it does not overlap with other lines. Then possible for change extline again . No4-IMG1. 
>>> It is possible to change the Ext line length after setting length = 0. And it is possible to change the  extline for all or one by one.
2. Dimension Text: [IMG2]
- For small distances. Dimension will overlap with other lines. I made a manual move to drag it to the sides (Left, Right). No2-IMG2.
-When mirroring these dimensions. It will be below the dim line. I have to move it manually or use the command "Ai_Above_DimLine" one by one and cannot be used for multiple dimensions at the same time. No3-IMG2.
>>> Is there any solution to choose the position (Left, Right, Mid, Top, Bot ...) like justify of text compared to the Ext lines. And can Adjustment offset position (with arrow button for example)
>>> It is possible  command "Ai_Above_DimLine" for all dim or selection.
 Thank in advance. Have a good day.

(DEFUN C:K (/ CMD SS LTH DEM PT DS KDL N70 GOCX GOCY PT13 PT14 PTI PT13I PT14I
                PT13N PT14N O13 O14 N13 N14 OSM OLDERR PT10 PT11)
(SETQ CMD (GETVAR "CMDECHO"))
(SETQ OSM (GETVAR "OSMODE"))
(SETQ OLDERR *error*
      *error* myerror)
(PRINC "Please select dimension object!")
(SETQ SS (SSGET))
(SETVAR "CMDECHO" 0)
(SETQ PT (GETPOINT "Point to trim or extend:"))
(SETQ PT (TRANS PT 1 0))
(COMMAND "UCS" "W")
(SETQ LTH (SSLENGTH SS))
(SETQ DEM 0)
(WHILE (< DEM LTH)
    (PROGN
    (SETQ DS (ENTGET (SSNAME SS DEM)))
    (SETQ KDL (CDR (ASSOC 0 DS)))
    (IF (= "DIMENSION" KDL)
       (PROGN
        (SETQ PT10 (CDR (ASSOC 10 DS)))
        (SETQ PT11 (CDR (ASSOC 11 DS)))
        (SETQ PT13 (CDR (ASSOC 13 DS)))
        (SETQ PT14 (CDR (ASSOC 14 DS)))
        (SETQ N70 (CDR (ASSOC 70 DS)))
        (IF (OR (= N70 32) (= N70 33) (= N70 160) (= N70 161))
           (PROGN
            (SETQ GOCY (ANGLE PT10 PT14))
            (SETQ GOCX (+ GOCY (/ PI 2)))
           )
        )
        (SETVAR "OSMODE" 0)
        (SETQ PTI (POLAR PT GOCX 2))
        (SETQ PT13I (POLAR PT13 GOCY 2))
        (SETQ PT14I (POLAR PT14 GOCY 2))
        (SETQ PT13N (INTERS PT PTI PT13 PT13I NIL))
        (SETQ PT14N (INTERS PT PTI PT14 PT14I NIL))
        (SETQ O13 (ASSOC 13 DS))
        (SETQ O14 (ASSOC 14 DS))
        (SETQ N13 (CONS 13 PT13N))
        (SETQ N14 (CONS 14 PT14N))
        (SETQ DS (SUBST N13 O13 DS))
        (SETQ DS (SUBST N14 O14 DS))
        (ENTMOD DS)
       )
    )
    (SETQ DEM (+ DEM 1))
    )
)
(COMMAND "UCS" "P")
(SETVAR "CMDECHO" CMD)
(SETVAR "OSMODE" OSM)
(setq *error* OLDERR)               ; Restore old *error* handler
(PRINC)
)

1.jpg2.jpg

0 Likes
Accepted solutions (2)
3,280 Views
13 Replies
Replies (13)
Message 2 of 14

Moshe-A
Mentor
Mentor
Accepted solution

@Vuxvix  hi,

 

for your first request check this one. for the second i think your problem is the dimstyle or you moved the dimtext and AutoCAD is 'committed' to do exact mirror. use DIMTEDIT Home and if it does not work post a sample dwg.

 

enjoy

Moshe

 

(defun c:dle (/ askdist Cedge ;| local functions |;
                def-de de ss)
  
 (defun askdist (def / ask)
  (if (not (setq ask (getdist (strcat "\nSpecify dimension line extention <" (rtos def 2) ">: "))))
   (setq ask def)
   (setq def ask)
  )
 ); askdist


 ; return nearby edge
 (defun Cedge (a0 t0 t1 / qang ;| local function |;)
   
  (defun qang (a1 / a2)
   (if (> a0 a1)
    (setq a2 (- a0 a1))
    (setq a2 (- a1 a0))
   )

   (if (> a2 (* pi 1.5))
    (setq a2 (- (* pi 2) a2))
    a2
   )  
  ); qang
  
  (abs (* (cos (qang (angle t0 t1))) (distance t0 t1)))
 ); Cedge

  
 ; here start c:dle
 (if (= (getvar 'userr1)  0.0)
  (setvar 'userr1 (setq def-de 1.0))
  (setq def-de (getvar 'userr1))
 ); if
  
 (if (and
       (setvar 'userr1 (setq de (askdist def-de)))
       (setq ss (ssget '((0 . "dimension"))))
     )
  (mapcar
   (function 
    (lambda (ename / elist p10 p12 p13 p14 p23 p24 rot bx)
     (setq elist (entget ename))
     (if (or
            (vl-string-search "Rotated" (cdr (assoc '100 (reverse elist))))
            (vl-string-search "Aligned" (cdr (assoc '100 (reverse elist))))
          )         
      (progn
       ; retrieve dimension defpoints 
       (setq p13 (cdr (assoc '13 elist)))
       (setq p14 (cdr (assoc '14 elist)))
       (setq p10 (cdr (assoc '10 elist)))

       ; dimension angle
       (if (eq (cdr (assoc '100 (reverse elist))) "AcDbRotatedDimension")
        (setq rot (cdr (assoc '50 elist)))
        (setq rot (angle p13 p14))
       )
        
       (setq bx  (Cedge rot p10 p13)) ; get nearby edge
       (setq p12 (polar p10 rot bx))

       ; Make sure p12 is on right spot
       (if (not (equal (Cedge rot p12 p13) 0.0 1e-4))
        (setq p12 (polar p10 (+ rot pi) bx))
       )

       ; New extension points
       (setq p23 (polar p12 (angle p12 p13) de))
       (setq p24 (polar p10 (angle p10 p14) de))

       ; Update database
       (setq elist (subst (cons '13 p23) (assoc '13 elist) elist))
       (setq elist (subst (cons '14 p24) (assoc '14 elist) elist))
       (entmod elist) 
      ); progn
     ); if 
    ); lambda
   ); function
   (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  ); mapcar
 ); if  
 
 (princ)  
); c:dle

 

 

 

Message 3 of 14

Vuxvix
Advocate
Advocate

This is really good news to start the new year. Thank you very much, this was of great help to me. May I to invite you to have a cup of coffee.

0 Likes
Message 4 of 14

Vuxvix
Advocate
Advocate

In 2-proble, I know and understand the usage of the commands in "Dimedit". In the case of small gap, then the Dimtext I need to move it manually left (or right) so it doesn't overlap another line. Because of this, the mirror will no longer be in the "Home" position. Is there any solution to move directly "Dimtext" from the below to the Above of dimension line for multiple the dimension. the use of "Above dim line" can only be used for individual dimensions. Thanks

0 Likes
Message 5 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

@Vuxvix wrote:

....
1.Extend line: [IMG1]
-I use the attached Lisp to "trim" ext Lines. (select the parallel and linear dimensions. And specify the position of the line pins) ....

 


If I understand correctly that you want to not have extension lines drawn through gaps in non-continuous other lines such as center-lines, you don't need to move their definition points -- you can suppress the extension lines.  I wrote DimExtLineToggle.lsp, with its DET command, to toggle the nearer extension line of any selected Dimension [off if it's on, on if it's off].  You can pick on the extension line itself if it's on, to turn it off, but in this case, if it coincides with some other line, you can pick on the arrow, or the dimension line, or even the text.  And that allows you to toggle one on when it's currently off and you can't pick on the extension line itself.  The routine finds which end you picked closer to, and toggles the appropriate extension line, and you don't need to know which one if #1 and which is #2 [as you would if you do it in the Properties palette].  If that will serve your purpose, you can find it >here<.

Kent Cooper, AIA
Message 6 of 14

Moshe-A
Mentor
Mentor

@Vuxvix  hi,

 

Here is a command DTM (Dimension Text Move) to move the text above or under dimension line

for this i needed to use some beautiful functions by great Lee Mac - thank you very much LEE 👍

 

 b.t.w for the previous command DLE, if you specify a negative, value the extension lines will flip 😀

 

enjoy

Moshe

 

 

 

;;-----------------=={ Reflect by Matrix }==------------------;;
;;                                                            ;;
;;  Reflects a VLA-Object or Point List using a               ;;
;;  Transformation Matrix                                     ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  target - VLA-Object or Point List to transform            ;;
;;  p1, p2 - Points representing vector in which to reflect   ;;
;;------------------------------------------------------------;;

(defun LM:ReflectByMatrix ( target p1 p2 )
  (
    (lambda ( a / m )
      (LM:ApplyMatrixTransformation target
        (setq m
          (list
            (list (cos a)    (sin a)  0.)
            (list (sin a) (- (cos a)) 0.)
            (list    0.         0.    1.)
          )
        )
        (mapcar '- p1 (mxv m p1))
      )
    )
    (* 2. (angle p1 p2))
  )
)

;;-----------=={ Apply Matrix Transformation }==--------------;;
;;                                                            ;;
;;  Transforms a VLA-Object or Point List using a             ;;
;;  Transformation Matrix                                     ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  target - VLA-Object or Point List to Transform            ;;
;;  matrix - 3x3 Matrix by which to Transform object          ;;
;;  vector - 3D translation vector                            ;;
;;------------------------------------------------------------;;

(defun LM:ApplyMatrixTransformation ( target matrix vector ) (vl-load-com)
  (cond
    ( (eq 'VLA-OBJECT (type target))
     
      (vla-TransformBy target
        (vlax-tMatrix
          (append (mapcar '(lambda ( x v ) (append x (list v))) matrix vector)
           '((0. 0. 0. 1.))
          )
        )
      )
    )
    ( (listp target)

      (mapcar
        (function
          (lambda ( point ) (mapcar '+ (mxv matrix point) vector))
        )
        target
      )
    )        
  )
)

;; Matrix x Vector - Vladimir Nesterovsky
;; Args: m - nxn matrix, v - vector in R^n

(defun mxv ( m v )
  (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
)


(defun c:dtm (/ qang Cedge ; local functions
                ss)

 ; return nearby edge
 (defun Cedge (a0 t0 t1 / qang ;| local function |;)
   
  (defun qang (a1 / a2)
   (if (> a0 a1)
    (setq a2 (- a0 a1))
    (setq a2 (- a1 a0))
   )

   (if (> a2 (* pi 1.5))
    (setq a2 (- (* pi 2) a2))
    a2
   )  
  ); qang
  
  (abs (* (cos (qang (angle t0 t1))) (distance t0 t1)))
 ); Cedge

  
 (if (setq ss (ssget '((0 . "dimension")))) 
  (mapcar
   (function
    (lambda (ename / elist p10 p11 p12 p13 p14 p15 rot bx)
    (setq elist (entget ename))
      
    (if (or
            (vl-string-search "Rotated" (cdr (assoc '100 (reverse elist))))
            (vl-string-search "Aligned" (cdr (assoc '100 (reverse elist))))
          )         
      (progn
       ; retrieve dimension defpoints 
       (setq p13 (cdr (assoc '13 elist)))
       (setq p14 (cdr (assoc '14 elist)))
       (setq p10 (cdr (assoc '10 elist)))
       (setq p11 (cdr (assoc '11 elist)))
     
       ; dimension angle
       (if (eq (cdr (assoc '100 (reverse elist))) "AcDbRotatedDimension")
        (setq rot (cdr (assoc '50 elist)))
        (setq rot (angle p13 p14))
       )
       
       (setq bx  (Cedge rot p10 p13)) ; get nearby edge
       (setq p12 (polar p10 rot bx))

       ; Make sure p12 is on right spot
       (if (not (equal (Cedge rot p12 p13) 0.0 1e-4))
        (setq p12 (polar p10 (+ rot pi) bx))
       )

       (if (< (distance p10 p11) (distance p12 p11))
        (setq p15 (car (LM:ReflectByMatrix (list p11) p12 p10)))
        (setq p15 (car (LM:ReflectByMatrix (list p11) p10 p12)))
       )
       
       ; Update database
       (setq elist (subst (cons '11 p15) (assoc '11 elist) elist))
       (entmod elist) 
      ); progn
     ); if 
    ); lambda
   ); function
   (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  ); mapcar  
 ); if

 (princ)  
)

 

 

 

 

Message 7 of 14

Vuxvix
Advocate
Advocate

First of all, many thanks for your support!
I have tried your DTM lisp. it works fine for those set to "right place". I mean, in case the Dimtext is moved left (or right, whatever ..) but is too close (or overlapping) to the Dimline. Then DTM is making a mirror (axis is Dimline). In the attached picture, there are a few dimtext overlapping with Dimline.
Forgive me, Is it too much to expect an update to the DTM lisp?DTM Lisp fix.JPG

0 Likes
Message 8 of 14

Vuxvix
Advocate
Advocate

Thank you very much. Your lisp is really helpful. It avoids errors when I have to use sketch Extline manually.

0 Likes
Message 9 of 14

Moshe-A
Mentor
Mentor

post a sample dwg with a state before dtm and after so i can see the issue

0 Likes
Message 10 of 14

Vuxvix
Advocate
Advocate

In the file is my example. thanks

0 Likes
Message 11 of 14

Moshe-A
Mentor
Mentor

@Vuxvix , 

 

Before you use DTM, you need to fix the relevent dimstyle, sets all dimvars the correct value until you reach a proper dimension line + use dimedit home option...it looks like your start is wrong and DTM is not supose to fix that.

 

all DTM does is moving the text around the dimline (using dimline as an axis)

 

Moshe

 

 

0 Likes
Message 12 of 14

Vuxvix
Advocate
Advocate

Hi!

Sometimes, my job is getting the drawing and edit the dimensions "wrong". I had to use the "Above dimension line" to edit it again. I have to choose "wrong" DimText individually. Mouse to it and choose "Above Dimension line" one by one.
I have tried setting the keyboard shortcut and the icon button for the command: "Dimension, Text, Above dim line". But it doesn't work. (I did the same thing with the "Dimension, Text, Home text" button, and it works fine).
Is there any solution to select multiple Dimensions then cmd "Above dimension line".

Many thanks!

0 Likes
Message 13 of 14

Moshe-A
Mentor
Mentor

@Vuxvix ,

 

What's beatiful in AutoCAD dimensions is they are 'attached' to dimension style. all you have to do is fix the dimension style and make it current than invoke the -DIMSTYLE (yes including the prefix dash) command and use apply option to apply the current dimension style to dimensions - job done 😀

 

Moshe

 

0 Likes
Message 14 of 14

Vuxvix
Advocate
Advocate

Thank you very much!

0 Likes