Dimension's extension line jumping with lisp

Dimension's extension line jumping with lisp

Vuxvix
Advocate Advocate
2,577 Views
16 Replies
Message 1 of 17

Dimension's extension line jumping with lisp

Vuxvix
Advocate
Advocate

Hi !

I have 2 problems when using the Dim edit lisp
1. I'm using this lisp to edit dim extension line. when working with dims without extension lines, it will cause dim to jump and change values. Is there any way to fix this problem of lisp(image attached and lisp "Dim Edit").

Dim.JPG

2. I searched but didn't find any topic about selecting linear dims (like how to create dim continue) horizontally, vertically or even diagonally. Is there any solution.
Ps: I use this macro for select vertical dimension:
^C^C(sssetfirst nil (ssget (list '(0 . "DIMENSION") '(-4 . "&=") '(70 . 0) (cons 50 (* pi 0.5)))));
Appreciate any help.

 

0 Likes
Accepted solutions (1)
2,578 Views
16 Replies
Replies (16)
Message 2 of 17

Kent1Cooper
Consultant
Consultant

Does it make a difference if you turn off Object Snap before selecting a point, instead of later in the routine?

....

(SETVAR "CMDECHO" 0)
(SETVAR "OSMODE" 0)
(SETQ PT (GETPOINT "Point to trim or extend:"))
(SETQ PT (TRANS PT 1 0))

....

Kent Cooper, AIA
0 Likes
Message 3 of 17

diagodose2009
Collaborator
Collaborator

 You,  upload a Sample.dwg,

You , please, you save before,  you save the Sample.dwg as version autocad2004.

(or Acad2010, Acad 2016 or Acad200)

Why acad2004? Perhaps, Autocad2020 store and others information/s inside Dimension/s and otherCad (e.g. NanoCad, Z*Cad) do not accept. ,

or OtherCad open invalid Sample.dwg 

even Visual-Lisp failed.

 

0 Likes
Message 4 of 17

Vuxvix
Advocate
Advocate

Thanks for the quick response.
First I have no knowledge of writing Autolisp.
@Kent1Cooper: I usually edit drawings, where the generated dimensions sometimes the footing of extension line is snap to Line dimension.
so when i use D2 lisp to edit Dim ext line it gets changed.
Also, I don't understand the blue Lisp line in your reply. i checked the lisp again and tried adding it in. But the problem is still there.
@diagodose2009 : I uploaded a sample.dwg. Also I don't understand what you are saying, the picture you attached is on autocad software!?

0 Likes
Message 5 of 17

Kent1Cooper
Consultant
Consultant

@Vuxvix wrote:

... I don't understand the blue Lisp line in your reply. i checked the lisp again and tried adding it in. But the problem is still there. ....


It was just a line of code moved earlier than it was in your original.  If you have running Object Snap modes turned on at a (getpoint) function, they can affect the resulting location.  You had Osnap being turned off later in the routine, so I thought your point selection could be getting a location you didn't really want.  [This is by far the most common reason for routines having results that are not where someone expects them to be.]  But if turning it off earlier did not fix the problem, there's obviously some other cause.

Kent Cooper, AIA
0 Likes
Message 6 of 17

Vuxvix
Advocate
Advocate
Previously, I also looked into the values and tried to debug. But it's not easy for starters. Thanks for the information you provided. Hope there is a solution in the future. Best regards
0 Likes
Message 7 of 17

Sea-Haven
Mentor
Mentor

If you add a entmod assoc 1 to  (rtos (cdr (assoc 42 DS)) 2 0) that will round down the value.

 

(SETQ O1 (ASSOC 1 DS))
(SETQ N1 (CONS 1 (rtos (cdr (assoc 42 DS)) 2 0)))
(SETQ DS (SUBST N1 O1 DS))
(ENTMOD DS)

0 Likes
Message 8 of 17

Vuxvix
Advocate
Advocate

Hi!
I found these values in lisp:
(SETQ O11 (ASSOC 11 DS))
(SETQ N11 (CONS 11 PT11N))
(SETQ DS (SUBST N11 O11 DS))
(ENTMOD DS)
how to need to edit the lisp. Can you share the edited lisp file. Thanks a lot

 

0 Likes
Message 9 of 17

Vuxvix
Advocate
Advocate

(DEFUN C:kkk2 (/ 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)
(SETVAR "OSMODE" 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))
(SETQ O1 (ASSOC 1 DS))
(SETQ N1 (CONS 1 (rtos (cdr (assoc 42 DS)) 2 0)))
(SETQ DS (SUBST N1 O1 DS))
(ENTMOD DS)
)
)
(SETQ DEM (+ DEM 1))
)
)
(COMMAND "UCS" "P")
(SETVAR "CMDECHO" CMD)
(SETVAR "OSMODE" OSM)
(setq *error* OLDERR) ; Restore old *error* handler
(PRINC)
)
Is it correctly!? Thanks!

0 Likes
Message 10 of 17

Kent1Cooper
Consultant
Consultant

@Vuxvix wrote:

I found these values in lisp:
(SETQ O11 (ASSOC 11 DS))
(SETQ N11 (CONS 11 PT11N))
(SETQ DS (SUBST N11 O11 DS))
....


I don't think you want to change the 11-code entry.  That's the Text insertion point, which I assume you do not want to move.

Kent Cooper, AIA
0 Likes
Message 11 of 17

Kent1Cooper
Consultant
Consultant

@Vuxvix wrote:

....

Ps: I use this macro for select vertical dimension:
^C^C(sssetfirst nil (ssget (list '(0 . "DIMENSION") '(-4 . "&=") '(70 . 0) (cons 50 (* pi 0.5)))));
....


That will see only those whose vertical-ness is from bottom to top.  The 50-code entry for a vertical dimension could also be  (cons 50 (* pi 1.5))  [top-to-bottom], as some are in your sample drawing.

 

Also, the 70-code value is not a purely bit-coded sum-of-powers-of-2 entry, so the '(-4 . "&=") is not really an appropriate approach.  Even for a horizontal or vertical Dimension, which the DXF reference says a 0 value would represent, it also says that since R13 it will always have 32 in it, as those in your sample drawing do.

Kent Cooper, AIA
0 Likes
Message 12 of 17

Kent1Cooper
Consultant
Consultant

Here's a potential problem line:

 

  (SETQ GOCY (ANGLE PT10 PT14))

 

In your Dimensions without extension lines [which, by the way @hak_vz , are already in a Style defined to have both extension lines suppressed], the dimension line location is on the line between definition points, which means that PT10 [where an arrowhead meets extension line 2] and PT14 [definition point 2] will be in the same place.  The (angle) function always returns zero when the points given are the same.  So in one where you are wanting a 180° direction for the repositioning of the definition point, it will go in the wrong direction.  Or, when working with horizontal Dimensions, wanting 90° or 270° movement, or in Aligned Dimensions at any kinds of angles, it will never be right.

 

I'm not sure accounting for that will fix the problem, but first I would like to have a better idea of what your prompt "Point to trim or extend:" means.  Can you post a drawing with before and after, showing where you pick in answer to that prompt, and how that location relates to the result you want?

Kent Cooper, AIA
0 Likes
Message 13 of 17

hak_vz
Advisor
Advisor

@Kent1CooperI have been solving similar problem last year. I have noticed that dimension entity with extension lines turned may be created by acad dimension command itself with switched left and right ext line points (p10 and p14). As a consequence, final result is as you described in your post.   

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 14 of 17

Vuxvix
Advocate
Advocate

Hi!

1. @Sea-Haven's suggestion is not clear to my abilities. so I tried many options (including insert and repalce.) Adding the code fixed the horizontal dim lines. But with vertical dim lines it still jumps a bit (not good enough).
2.Point to trim or extend means: specify the point where the extension line should start. like using the Trim or extend command to cut the line. I have attached pictures and files.

スクリーンショット (5).jpg
3.Is there anything I can do with your instructions on choosing dimensions in the Marco paragraph. It's too much for me 😄
Thanks for taking the time to address my issue.

0 Likes
Message 15 of 17

Vuxvix
Advocate
Advocate

@hak_vz

 

Create two separate dimension styles, one with extension lines turned on ("ISO-25"), other with turned off ("ISO-25-no-extensions"). For style "ISO-25-no-extensions" in style definition select

vundarch_0-1629845218113.png

 

 

If your dimension lines with extension lines turned on are defined with dimension stile named, let say "ISO-25" to apply changes only on them and leave other untouched, you should modify selection filters . Apply to both your functions.

Replace
(SETQ SS (SSGET))
with
setq ss (ssget '((0 . "DIMENSION") (3 . "ISO-25"))))

 

0 Likes
Message 16 of 17

Vuxvix
Advocate
Advocate

(PRINC "Please select dimension object!")
(SETQ SS (SSGET '((0 . "DIMENSION") (3 . "A50"))))
(SETVAR "CMDECHO" 0)
(SETQ PT (GETPOINT "Point to trim or extend:"))

Hi!@hak_vz 

This is my fix lisp. but its not working

 My Dim style:

  • A50: Checked Ext line1, 2
  • A50.none: Uncheck
    Also try with Dim style: ISO-25, ISO-25.none

I have no experience with lisp. Lisp editing will always have the potential to go wrong. Can you share the edited lisp file? I also attached lisp and sample follow your instructions. Thanks

0 Likes
Message 17 of 17

Vuxvix
Advocate
Advocate
Accepted solution

This is the Debugged Lisp Extension Line. Hope it helps anyone who uses it.

(defun C:D2 (/ cmd osm olderr ss PT index DS N13 N14)
(setq cmd (getvar "CMDECHO")
osm (getvar "OSMODE")
olderr *error* *error* myerror
)
(princ "Please select dimension object!")
(setq ss (ssget '((0 . "DIMENSION"))))
(setvar "CMDECHO" 0)
(setq PT (getpoint "\nPoint to trim or extend:")
PT (trans PT 1 0)
)
(command "UCS" "_W")
(repeat (setq index (sslength ss))
(setq DS (entget (ssname ss (setq index (1- index)))))
(cond
((equal (cdr (assoc 50 DS)) 0.0 0.001)
(setq N13 (cons 13 (list (car (cdr (assoc 13 DS))) (cadr PT) (caddr (cdr (assoc 13 DS)))))
DS (subst N13 (assoc 13 DS) DS)
N14 (cons 14 (list (car (cdr (assoc 14 DS))) (cadr PT) (caddr (cdr (assoc 14 DS)))))
DS (subst N14 (assoc 14 DS) DS)
)
(entmod DS)
)
((equal (cdr (assoc 50 DS)) (/ pi 2) 0.001)
(setq N13 (cons 13 (list (car PT) (cadr (cdr (assoc 13 DS))) (caddr (cdr (assoc 13 DS)))))
DS (subst N13 (assoc 13 DS) DS)
N14 (cons 14 (list (car PT) (cadr (cdr (assoc 14 DS))) (caddr (cdr (assoc 14 DS)))))
DS (subst N14 (assoc 14 DS) DS)
)
(entmod DS)
)
)
)
(command "UCS" "_P")
(setvar "CMDECHO" cmd)
(setvar "OSMODE" osm)
(setq *error* olderr)
(princ)
)
0 Likes