Dimensioning a polyline Lisp routine problem

Dimensioning a polyline Lisp routine problem

efaillaceW9L2E
Contributor Contributor
664 Views
5 Replies
Message 1 of 6

Dimensioning a polyline Lisp routine problem

efaillaceW9L2E
Contributor
Contributor

I am trying to use a lisp routine to dimension the total length of a polyline and the dimension line will follow the polyline. I've found things online that I could use and made changes so it will fit my standards. I am having two issues though printing the dimension text and the layer. There should be two lines of text stacked underneath of each other but for some reason, the text is staggered. Also, the command puts everything on the correct layer except the dimension line itself. The pictures attached shown my current result and what I want. Any help would be appreciated. Thanks.

 

0 Likes
665 Views
5 Replies
Replies (5)
Message 2 of 6

marko_ribar
Advisor
Advisor

Here is my revision...

 

(defun c:dimcurve ( / _line _arrow a b cm el en p q pt )
    (if (tblsearch "LAYER" "Dims")
        (setvar "CLAYER" "Dims")
        (vl-cmdf "_.-layer" "_m" "Dims" "")
    ) ;;; mod. by M.R.
    (defun _line ( a b )
        (entmake (list '(0 . "LINE") (cons 10 a) (cons 11 b)))
    )
    (defun _arrow ( a b )
        (entmake
            (list
               '(0 . "LWPOLYLINE")
               '(100 . "AcDbEntity")
               '(100 . "AcDbPolyline")
               '(90 . 2)
               '(70 . 0)
                (cons 10 a)
               '(40 . 0.0)
                (cons 41 (/ (distance a b) 3.0))
                (cons 10 b)
            )
        )
    )
    
    (while
        (progn (setvar 'errno 0) (setq en (car (entsel)))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (eq 'ename (type en))
                    (if (not (wcmatch (cdr (assoc 0 (entget en))) "ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,SPLINE"))
                        (princ "\nInvalid Object Selected.")
                    )
                )
            )
        )
    )
    (if
        (and en
            (setq pt
                (getpoint "\nSpecify Dimension Offset: "
                    (trans
                        (vlax-curve-getpointatparam en
                            (/ (+ (vlax-curve-getendparam en) (vlax-curve-getstartparam en)) 2.0)
                        )
                        0 1
                    )
                )
            )
        )
        (progn
            (setq el (entlast)
                  cm (getvar 'cmdecho)
            )
            (setvar 'cmdecho 0)
            (command "_.offset" "_T" en "_non" pt "")
            (setvar 'cmdecho cm)
            (if (equal el (setq el (entlast)))
                (princ "\nUnable to Create Dimension Line.")
                (progn
                    (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Dims") (assoc 8 (entget el)) (entget el)))))) ;;; mod. by M.R.
                    (setq a (vlax-curve-getstartpoint en)
                          b (vlax-curve-getstartpoint el)
                    )
                    (_line
                        (polar a (angle a b) (/ (distance a b) 6.0))
                        (polar b (angle a b) (/ (distance a b) 6.0))
                    )
                    (setq a (vlax-curve-getendpoint en)
                          b (vlax-curve-getendpoint el)
                    )
                    (_line
                        (polar a (angle a b) (/ (distance a b) 6.0))
                        (polar b (angle a b) (/ (distance a b) 6.0))
                    )
                    (_arrow
                        (vlax-curve-getstartpoint el)
                        (polar (vlax-curve-getstartpoint el)
                            (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv el (vlax-curve-getstartparam el)))
                            (getvar 'dimasz)
                        )
                    )
                    (_arrow
                        (vlax-curve-getendpoint el)
                        (polar (vlax-curve-getendpoint el)
                            (+ pi (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv el (vlax-curve-getendparam el))))
                            (getvar 'dimasz)
                        )
                    )
                    (setq a (vlax-curve-getpointatdist el (/ (vlax-curve-getdistatparam el (vlax-curve-getendparam el)) 2.0))
                          b (angle '(0.0 0.0) (vlax-curve-getfirstderiv el (vlax-curve-getparamatpoint el a)))
                          p (polar a (+ b (/ pi 2.0)) (* 1.25 (getvar 'dimtxt))) ;;; mod. by M.R.
                          q (polar a (- b (/ pi 2.0)) (* 1.25 (getvar 'dimtxt))) ;;; mod. by M.R.
                    )
                    (if (< (distance p (vlax-curve-getclosestpointto en p))
                           (distance q (vlax-curve-getclosestpointto en q))
                        )
                        (setq p q)
                    )
                    ;;; start mods. by M.R.
                    (entmake
                        (list
                           '(000 . "TEXT")
                            (cons 7 (getvar "textstyle"))
                            (cons 10 (mapcar '+ p (mapcar '- p a)))
                            (cons 11 (mapcar '+ p (mapcar '- p a)))
                            (cons 40 (getvar 'dimtxt))
                            (cons 01 (rtos (vlax-curve-getdistatparam en (vlax-curve-getendparam en)) 2 1))
                            (cons 50 (LM:readable b))
                           '(072 . 1)
                           '(073 . 2)
                        )
                    )
                    (entmake
                        (list
                           '(000 . "TEXT")
                            (cons 7 (getvar "textstyle"))
                            (cons 10 p)
                            (cons 11 p)
                            (cons 40 (getvar 'dimtxt))
                            (cons 01 (strcat "[" (rtos (* (vlax-curve-getdistatparam en (vlax-curve-getendparam en)) 25.4) 2 0) "mm]"))
                            (cons 50 (LM:readable b))
                           '(072 . 1)
                           '(073 . 2)
                        )
                    )
                    ;;; end mods. by M.R.
                )
            )
        )
    )
    (princ)
)
(defun LM:readable ( a )
    (   (lambda ( a )
            (if (< a 0.0)
                (LM:readable a)
                (if (and (< (* pi 0.5) a) (<= a (* pi 1.5)))
                    (LM:readable (+ a pi))
                    a
                )
            )
        )
        (rem (+ a pi pi) (+ pi pi))
    )
)
(vl-load-com) (princ)

 

HTH. M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 6

efaillaceW9L2E
Contributor
Contributor

@marko_ribar just as I pictured it thanks. I just tried to use this in paper space and it would not work. Is this possible, I use AutoCAD Mechanical and work with paper space (ie. balloon and dimension)? 

0 Likes
Message 4 of 6

rdaveyCCXBN
Enthusiast
Enthusiast

I just tried to use this in paper space and it would not work. Is this possible, I use AutoCAD Mechanical and work with paper space (ie. balloon and dimension)?

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

Just looking at this again I am pretty sure way back worked out how to get the dim arrow blocks, arrow, dot, closed fill etc will try to find again, saves a hard code entmake arrow.

0 Likes
Message 6 of 6

efaillaceW9L2E
Contributor
Contributor

Any luck finding what you were looking for? I am still trying to figure out how to use this lisp routine in paperspace.

0 Likes