Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pline Dimensioning

53 REPLIES 53
Reply
Message 1 of 54
Anonymous
11486 Views, 53 Replies

Pline Dimensioning

Does anyone have a lisp to place aligned dimensions on each segment of a polyline?

I would use it for reinforcing bar detailing.
Thanks for any other suggestion.

Matthew
53 REPLIES 53
Message 2 of 54
Anonymous
in reply to: Anonymous

Ask Luis E.


wrote in message news:5078769@discussion.autodesk.com...
Does anyone have a lisp to place aligned dimensions on each segment of a
polyline?

I would use it for reinforcing bar detailing.
Thanks for any other suggestion.

Matthew
Message 3 of 54
Anonymous
in reply to: Anonymous

where I can find him? which forum?

Thanks
Matthew
Message 4 of 54
Anonymous
in reply to: Anonymous

Hi Matthew

Try this one:

;; Program draw a dimension of all polygon segments
;; Polygon must be closed or opened
;; copyrights (c) 2005 Fatty T.O.H. all rights removed
;; A2005 / Windows XP


;; helper functions : written by Fatty T.O.H.

;; *** group list ***

(defun group-by-num (lst num / ls ret)
(if (= (rem (length lst) num ) 0)
(progn
(setq ls nil)
(repeat (/ (length lst) num)
(repeat num (setq ls
(cons (car lst) ls)
lst (cdr lst)))
(setq ret (append ret (list (reverse ls)))
ls nil)))
)
ret
)

;; *** coordinates ***

(defun get-vexs (pline_obj / verts)
(setq verts (vlax-get pline_obj 'Coordinates)
verts
(cond
((wcmatch (vlax-get pline_obj 'Objectname )
"AcDb2dPolyline,AcDb3dPolyline")
(group-by-num verts 3)
)
((eq (vlax-get pline_obj 'Objectname )
"AcDbPolyline")
(group-by-num verts 2)
)
(T nil)
)
)
)


;; *** inclined angle ***

(defun dif-angle (ang1 ang2 / def)
(set 'ang1
(if (> ang2 (+ pi ang1))
(+ (* pi 2) ang1)
ang1
)
)
(set 'ang2
(if (> ang1 (+ pi ang2))
(+ (* pi 2) ang2)
ang2
)
)
(setq def (- ang2 ang1))
)

;; *** test on CW/CCW ***
;; (angdir=0)
(defun ccw-test (pt_list / angle_list)
(setq angle_list
(mapcar (function (lambda (x y)
(angle x y)
)
)
pt_list
(cdr pt_list)
)
)
(if (> (apply '+
(mapcar (function (lambda (x y) (dif-angle x y)))
angle_list
(cdr angle_list)
)
)
0
)
t
nil
)
)
;; *** main programm ***

(defun C:dmp (/ acsp adoc cent_coords coords pl txt_coords)
(vl-load-com)
(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
(setq acsp (vla-get-modelspace adoc))
(setq pl (vlax-ename->vla-object
(car (entsel "\n >> Select pline >> \n"))
)
)

(setq coords (get-vexs pl))
(if (eq :vlax-true (vla-get-closed pl))
(setq coords (append coords (list (car coords)))))
(if (ccw-test coords)(setq dop pi)(setq dop 0))
(setq cent_coords
(mapcar (function (lambda (x y)
(mapcar '/ (mapcar '+ x y) '(2 2 2))
)
)
coords
(cdr coords)
)
)
(setq txt_coords
(mapcar (function (lambda (x y z)
(polar x (+ dop (angle y z) (/ pi 2)) 8.);change extline length
)
)
cent_coords
coords
(cdr coords)
)
)
(mapcar (function (lambda (x y z)
(vla-adddimaligned acsp x y z)
)
)
(mapcar 'vlax-3d-point coords)
(mapcar 'vlax-3d-point (cdr coords))
(mapcar 'vlax-3d-point txt_coords)
)
(princ)
)

(prompt "\n\t***\tPLINE DIMENSIONING\t***\n")
(prompt "\nType DMP to execute\n")

Fatty

~'J'~
Message 5 of 54
Anonymous
in reply to: Anonymous

Wow, thank you Fatty! nearly perfect...

This is ok if I have straight line segments, but if I have a filleted pline?
I think we should consider the bulge of each segment...
Message 6 of 54
Anonymous
in reply to: Anonymous

Lately I just look, what is going on here... I think I have one similar to
what Fatty just did... If I found it, I'll post it here.

Do you required to use dimension objects?

--
http://www.geometricad.com



wrote in message news:5078806@discussion.autodesk.com...
where I can find him? which forum?

Thanks
Matthew
Message 7 of 54
Anonymous
in reply to: Anonymous

Hi Luis, here you are!

As I posted before, that lisp was ok, but I would even like to dimension arc segments in a pline.
Yes, I would like to use dim objects, no text objects.

Here is an image of what I mean; the green texts are dimension objects on the magenta pline.
Message 8 of 54
Anonymous
in reply to: Anonymous

Sorry Matthew,
but for the present I could't solve a problem
with bulged segments, in this case I think, there is need
to apply a method, same as to measurement of an arcs, if in the further I shall solve this problem, I shall return back to this thread

Fatty

~'J'~
Message 9 of 54
Anonymous
in reply to: Anonymous

No problem Fatty, many thanks for your help.
I'll keep watch

Matthew
Message 10 of 54
Anonymous
in reply to: Anonymous

Hi Matthew
Try this but very quick and dirty,
no time to varnish on it
(partially grabbed from J. Menzi - bulge calculation)

[code]
;; Program draw a dimension of all polygon segments
;; Polygon must be closed or opened
;; copyrights (c) 2005 Fatty T.O.H. all rights removed
;; A2005 / Windows XP


;; helper functions : written by Fatty T.O.H.

;; *** group list ***

(defun group-by-num (lst num / ls ret)
(if (= (rem (length lst) num ) 0)
(progn
(setq ls nil)
(repeat (/ (length lst) num)
(repeat num (setq ls
(cons (car lst) ls)
lst (cdr lst)))
(setq ret (append ret (list (reverse ls)))
ls nil)))
)
ret
)

;; *** coordinates ***

(defun get-vexs (pline_obj / verts)
(setq verts (vlax-get pline_obj 'Coordinates)
verts
(cond
((wcmatch (vlax-get pline_obj 'Objectname )
"AcDb2dPolyline,AcDb3dPolyline")
(group-by-num verts 3)
)
((eq (vlax-get pline_obj 'Objectname )
"AcDbPolyline")
(group-by-num verts 2)
)
(T nil)
)
)
)


;; *** inclined angle ***

(defun dif-angle (ang1 ang2 / def)
(set 'ang1
(if (> ang2 (+ pi ang1))
(+ (* pi 2) ang1)
ang1
)
)
(set 'ang2
(if (> ang1 (+ pi ang2))
(+ (* pi 2) ang2)
ang2
)
)
(setq def (- ang2 ang1))
)

;; *** test on CW/CCW ***
;; (angdir=0)
(defun ccw-test (pt_list / angle_list)
(setq angle_list
(mapcar (function (lambda (x y)
(angle x y)
)
)
pt_list
(cdr pt_list)
)
)
(if (> (apply '+
(mapcar (function (lambda (x y) (dif-angle x y)))
angle_list
(cdr angle_list)
)
)
0
)
t
nil
)
)
;; *** main programm ***

(defun C:dmp (/ )
(vl-load-com)
(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
(setq acsp (vla-get-modelspace adoc))
(setq pl (vlax-ename->vla-object
(car (entsel "\n >> Select pline >> \n"))
)
)

(setq coords (get-vexs pl))
(if (eq :vlax-true (vla-get-closed pl))
(setq coords (append coords (list (car coords)))))
(if (ccw-test coords)(setq dop pi)(setq dop 0))
;;; (setq cent_coords
;;; (mapcar (function (lambda (x y)
;;; (mapcar '/ (mapcar '+ x y) '(2 2 2))
;;; )
;;; )
;;; coords
;;; (cdr coords)
;;; )
;;; )
;;; (setq txt_coords
;;; (mapcar (function (lambda (x y z)
;;; (polar x (+ dop (angle y z) (/ pi 2)) 8.);change extline length
;;; )
;;; )
;;; cent_coords
;;; coords
;;; (cdr coords)
;;; )
;;; )
(setq param_list (mapcar (function (lambda (x)
(fix (vlax-curve-getparamatpoint pl x))))
(mapcar (function (lambda (y)(trans y 0 1))) coords)))
(mapcar (function (lambda (x y z)
(cond
((not (zerop (setq blg (vla-getbulge pl x))))
(progn
(setq hgt (* 4 (atan (abs blg)))
chord (distance y z)
rad (abs (/ chord 2 (sin (/ hgt 2))))
mid (trans (vlax-curve-getpointatparam pl (+ (fix x) 0.5)) 0 1)
cen (trans (mapcar (function (lambda (a b)(/ (+ a b) 2))) y z) 0 1)
txp (trans (polar mid (if (minusp blg)(angle cen mid)
(angle mid cen)) 😎 0 1)
)
(setq dm (vla-adddim3pointangular acsp
(vlax-3d-point cen)
(vlax-3d-point y)
(vlax-3d-point z)
(vlax-3d-point txp)))
(vla-put-textoverride dm (rtos (abs (- (vlax-curve-getdistatpoint pl y)
(vlax-curve-getdistatpoint pl z))) 2 2)))
)
(T (progn
(setq mid (trans (vlax-curve-getpointatparam pl (+ (fix x) 0.5)) 0 1))
(setq txp (trans (polar mid (+ dop (angle y z) (/ pi 2)) 8.) 0 1))
(vla-adddimaligned acsp
(vlax-3d-point y)
(vlax-3d-point z)
(vlax-3d-point txp))

)
))))
param_list
coords
(cdr coords))

(princ)
)

(prompt "\n\t***\tPLINE DIMENSIONING\t***\n")
(prompt "\nType DMP to execute\n")

[/code]

Fatty

~'J'~
Message 11 of 54
Anonymous
in reply to: Anonymous

So good!
I've slightly changed this line (where you find the center of the arched segment):
cen (trans (mapcar (function (lambda (a b)(/ (+ a b) 2))) y z) 0 1)

into this one:
cen (trans (polar y (if (minusp blg)(-(angle y z)(-(/ pi 2)(/ hgt 2)))(+(angle y z)(-(/ pi 2)(/ hgt 2)))) rad) 0 1)

In the attached image you can see the difference.
So... problem resolved!
Thank you, Fatty, you were so generous!

Matthew
Message 12 of 54
Anonymous
in reply to: Anonymous

Good point, Matthew
I think I need to work on further else
to fix all of weak places in the routine

Happy computing,

Fatty

~'J'~
Message 13 of 54
Anonymous
in reply to: Anonymous

hii  thanx for great routin  ,    if we use this routin the last dimension value is not correct kindly update

Message 14 of 54
Anonymous
in reply to: Anonymous

Hello Fatty,

I just came across this routine and I was wondering if you can make some modifications for me. I have very very limited understanding of AutoLisp and really no understanding of any other programming language.

I would like to use this routine to dimension a closed polyline and place the dimensions inside the polyline. I use the height of the text as the distance to place the dimension. (i.e. if the text height is 1.5 then the dimension is placed 1.5 inside the polyline segment)

Also, is there a way to make the dimensions not associative. I can always just explode them so this isn't a big deal.

Any help you can give me is greatly appreciated.

Message 15 of 54
Kent1Cooper
in reply to: Anonymous

[I haven't seen Fatty participating here recently (that routine is about 8 years old).  But there are various Polyline-dimensioning routines out there, such as this one and several related threads on these forums.  I may look at it later....]

Kent Cooper, AIA
Message 16 of 54
Anonymous
in reply to: Kent1Cooper

Hi Kent,

I just tried the MDIM routine and it didn't work correctly. I did a bit of digging and found one called DPL but it didn't quite do what I want it to. This DMP routine seems the closest I have found I just need to figure out how to tweak it a little. Thanks so much for the heads-up. I will keep digging and see what else I can find. 

Message 17 of 54
Anonymous
in reply to: Kent1Cooper

Hi Kent,

I managed to get the DMP routine that Fatty wrote to do what I wanted it to do. There was a comment "change extline length" which made it simple, I just didn't see it right away.

What I want to know is, is there a way to make the extline length equal to negative the current text height? For example, if the current text height is 1.5, the extline length would be -1.5.

I am able to modify the routine based on what I need that value to be, but it would be nice if I didn't have to change it every time.

Thanks for any help you can give me.

Message 18 of 54
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

... is there a way to make the extline length equal to negative the current text height? For example, if the current text height is 1.5, the extline length would be -1.5.

....


Rather than using a negative distance, I would suggest subtracting 90 degrees from the local angle, rather than adding it.  Try changing this:

(polar x (+ dop (angle y z) (/ pi 2)) 8.);change extline length

 

to this:

 

(polar x (- dop (angle y z) (/ pi 2)) (* (getvar 'dimscale) (getvar 'dimtxt)))

 

That assumes the text style assigned to the current Dimension Style is not of fixed height.  If it is, that will determine the height, rather than the combination of the dimension style's text height and the dimension-scale variable.

 

I tried DMP [with that new distance determination, and m_ibis's correction for arc segments], and found it inconsistent about both inside-out-side-ness and, at least along some non-orthogonal line segments, distance from segment to dimension.  I'm playing around with a different approach, which I'll post if it works out.

Kent Cooper, AIA
Message 19 of 54
Anonymous
in reply to: Kent1Cooper

WOW! This works perfectly for what I need.

Thanks so much for the help!

Message 20 of 54
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
.... 

I tried DMP [with that new distance determination, and m_ibis's correction for arc segments], and found it inconsistent about both inside-out-side-ness and, at least along some non-orthogonal line segments, distance from segment to dimension.  I'm playing around with a different approach, which I'll post if it works out.


I also found that if the closing segment of a closed Polyline is an arc segment, DMP gives the wrong length for it [because of the way it gets the length, the result is that of the entire Polyline minus that last segment, rather than the that of the closing segment].

 

Attached is my approach, DimPolyInside.lsp with its DPI command, which overcomes the problems mentioned, and has some other tweaks.  Be sure to put in the right Layer name, and consider some of the other suggestions in comments.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost