Trim Dimension Lines

Trim Dimension Lines

Anonymous
Not applicable
16,708 Views
26 Replies
Message 1 of 27

Trim Dimension Lines

Anonymous
Not applicable

Has anyone a lisp or a method for trimming dimension lines?

We tend to only extend the dim lines as far as the nearest edge/entity & not al the way to the item being dimensioned. My current meadod is to use grips to change the extension line of the dimensions. However I currently have several hundred general assembly drawings to do & would find such a tool very handy

 

Before.JPG

Before

 

 

 

After.JPG

After

 

0 Likes
Accepted solutions (1)
16,709 Views
26 Replies
Replies (26)
Message 2 of 27

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Hi,

 

You can try this:

 

(defun c:dim_attach_line ( / new_pt x y n js ent_dim dxf_ent p1 p2 alpha p13 p14)
  (initget 1)
  (setq new_pt (trans (getpoint "\nNew position line extend: ") 1 0) x (car new_pt) y (cadr new_pt) n -1)
  (princ "\nSelect dimensions: ")
  (while (null (setq js (ssget '((0 . "DIMENSION"))))))
  (repeat (sslength js)
    (setq ent_dim (ssname js (setq n (1+ n))))
    (setq dxf_ent (entget ent_dim))
    (cond
      ((or (zerop (rem (cdr (assoc 70 dxf_ent)) 32)) (eq (rem (cdr (assoc 70 dxf_ent)) 32) 1))
        (setq p1 (cdr (assoc 13 dxf_ent)) p2 (cdr (assoc 14 dxf_ent)))
        (cond
          ((or (eq (car p1) (car p2)) (and (zerop (rem (cdr (assoc 70 dxf_ent)) 32)) (zerop (rem (angle p2 (cdr (assoc 10 dxf_ent))) pi))))
            (setq dxf_ent (subst (cons 13 (list x (cadr p1) (caddr p1))) (assoc 13 dxf_ent) dxf_ent))
            (setq dxf_ent (subst (cons 14 (list x (cadr p2) (caddr p2))) (assoc 14 dxf_ent) dxf_ent))
          )
          ((or (eq (cadr p1) (cadr p2)) (and (zerop (rem (cdr (assoc 70 dxf_ent)) 32)) (zerop (rem (angle p2 (cdr (assoc 10 dxf_ent))) (/ pi 2)))))
            (setq dxf_ent (subst (cons 13 (list (car p1) y (caddr p1))) (assoc 13 dxf_ent) dxf_ent))
            (setq dxf_ent (subst (cons 14 (list (car p2) y (caddr p2))) (assoc 14 dxf_ent) dxf_ent))
          )
          (T
            (if (member '(100 . "AcDbRotatedDimension") dxf_ent)
              (setq alpha (cdr (assoc 50 dxf_ent)))
              (setq alpha (angle (list (car p1) (cadr p1)) (list (car p2) (cadr p2))))
            )
            (setq p13
              (inters
                (list x y)
                (polar (list x y) alpha (cdr (assoc 42 dxf_ent)))
                (list (car p1) (cadr p1))
                (polar (list (car p1) (cadr p1)) (+ alpha (/ pi 2)) (cdr (assoc 42 dxf_ent)))
                nil
              )
            )
            (setq p14
              (inters
                (list x y)
                (polar (list x y) alpha (cdr (assoc 42 dxf_ent)))
                (list (car p2) (cadr p2))
                (polar (list (car p2) (cadr p2)) (+ alpha (/ pi 2)) (cdr (assoc 42 dxf_ent)))
                nil
              )
            )
            (if (and p13 p14)
              (setq
                dxf_ent (subst (cons 13 (list (car p13) (cadr p13) (caddr p1))) (assoc 13 dxf_ent) dxf_ent)
                dxf_ent (subst (cons 14 (list (car p14) (cadr p14) (caddr p2))) (assoc 14 dxf_ent) dxf_ent)
              )
              (princ "\nCan't redefine point, the new point haven't same Z")
            )
          )
        )
        (entmod dxf_ent)
      )
      (T
        (princ "\nIsn't a dim aligned, rotated horizontal or vertical.")
      )
    )
  )
  (prin1)
)
Message 3 of 27

Kent1Cooper
Consultant
Consultant

That can all be done in the Dimensioning, rather than adjusting Dimensions afterwards, by using APParent-INTersection object snap and/or point filtering [.X, .Y] when designating the Dimension definition points.  Which approach would depend on the type of entity, its orientation, and where on it you're dimensioning to.

 

I will assume your uppermost horizontal purplish line is actually two Lines [or Polyline segments, or whatever] and that the 60- & 75-unit horizontal dimensions' common definition point is the midpoint of the Line or segment that forms the left part of that.  If that's the case, the 60 Dimension could be done this way:

 

DIMLINEAR

[snap to overall upper left corner for first point]

.X

[snap to midpoint of left-end-portion purplish line for X coordinate of second point]

[it will prompt "(need YZ)" -- snap to anywhere on the overall upper edge for Y coordinate of second point (Z is irrelevant)]

[specify Dimension line location]

 

The 75 Dimension could be done similarly, or its second point could be designated with:

APPINT

[pick the vertical element of the red center-mark, and the overall upper edge, to specify their APParent INTersection as the second point]

 

If you ever need to do this at non-orthogonal angles, the point-filtering approach won't help, but APPINT will do for many situations, or FROM for others.

Kent Cooper, AIA
0 Likes
Message 4 of 27

Anonymous
Not applicable

This works exactly as needed, thank you very much indeed CADaStroumph

 - Simon

0 Likes
Message 5 of 27

Anonymous
Not applicable

Further to the ealier reply, I didn't realise at first that this lisp extends dimensions as well as trims them.

 

Well done CADaStroumph

0 Likes
Message 6 of 27

tttttttttzeUXS2B
Community Visitor
Community Visitor

Hi, how can I key in this script to autocad??

0 Likes
Message 7 of 27

Kent1Cooper
Consultant
Consultant

@tttttttttzeUXS2B wrote:

Hi, how can I key in this script to autocad??


 

It's not a Script.  That has a specific -- and different -- meaning in AutoCAD.

 

Copy the code into a plain-text editor such as Notepad, and save it to a file with a .LSP filetype ending.  In an AutoCAD drawing, use APPLOAD to load it.  [There's more to know about the process, but start there.]

 

BUT, one development in more recent versions of AutoCAD, if it suits your situation, is that you can achieve the same kind of thing with fixed-length extension lines, either assigned to individual Dimension objects [in the Properties palette]:

ExtLineFixed.PNG

or incorporated into a entire Dimension Style's definition [in the Dimension Style Modify dialog box]:

ExtLineFixed2.PNG

Kent Cooper, AIA
0 Likes
Message 8 of 27

Anonymous
Not applicable

Hi, I need a Lisp similar to "dim_attach_line".

Is it possible to modify code as: for selected multiple rotated dimensions, streching grip points to it's own dimension line.

 

0 Likes
Message 9 of 27

john.uhden
Mentor
Mentor

I think I've posted this one before.

It trims and/or extends extension lines along a fence line you draw within the program.

If I recall correctly, it relocates the dimension points, also replacing aligned dimensions with rotated.

 

John F. Uhden

Message 10 of 27

Anonymous
Not applicable

Thank John,

 

There are hundreds of dimension lines and using fence line for all of them is a lot of work.  Is it possible to modify this lisp to 'use dimension lines as fence lines automatically without drawing fence line' and and trim all selected dimension recursively.

0 Likes
Message 11 of 27

john.uhden
Mentor
Mentor
It strikes me that using dimension lines as fence lines would be the same
as turning off the extensions. If you can select all your dimensions, you
can use the Properties dialog to turn them all off.

BTW,my DIMEXTRIM handles multiple dimensions with one fence.

John F. Uhden

0 Likes
Message 12 of 27

Anonymous
Not applicable

Thanks, I need this lisp. If you or someone else helps to modify the code I will be glad if not it is not end of the world I will try to learn coding:)

0 Likes
Message 13 of 27

Anonymous
Not applicable

I stil don't know how to use the lisp after i upload it into the drawing

0 Likes
Message 14 of 27

cadffm
Consultant
Consultant

Load

start DIMEXTRIM

do what the program ask for..

select (AutoCAD) dimensions

Draw a fence as trim/extent object

Sebastian

0 Likes
Message 15 of 27

Anonymous
Not applicable

Thank you for the reply but I get an error it can't find it.

 I load it, the i type: start

it asks for the aplication but it says it can find it. 

I tryed DimEXTrim

DIMEXTRIM

dimextrim and .lsp afer all of the above

0 Likes
Message 16 of 27

cadffm
Consultant
Consultant

Drag&Drop the file to your drawing (learn about APPLOAD command later)

then

 

Command: DIMEXTRIM[ENTER]

Sebastian

0 Likes
Message 17 of 27

Anonymous
Not applicable

thanks

that worked

0 Likes
Message 18 of 27

john.uhden
Mentor
Mentor

Sebastian:

Thanks for taking over.  🙂

John F. Uhden

0 Likes
Message 19 of 27

Anonymous
Not applicable

how to apply the script?

 

0 Likes
Message 20 of 27

john.uhden
Mentor
Mentor
You can use the APPLOAD command to load the .lsp file, Then run the
command DIMEXTRIM.
There are other ways if you want to have it automatically load with every
drawing you open or start.

John F. Uhden

0 Likes