update no. 3
Code:
;|***********************************************************************************
PROGRAM CREATED FOR POLYLINE(with multiple segments) DIMENSIONING
DATE: OCTOBER 19, 2008
CREATED BY: WIZMAN
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|;
(defun c:mdim
(/ ent_layer
mdim_curdimscal mdim_curlay
mdim_curluprec mdim_curosmode
mdim_enttemp mdim_enttemp2
mdim_pline_ent mdim_pline_ent_vla
mdim_pline_pts mdim_pt1
mdim_pt2 mdim_x
mdim_x1 mdim_y
mdim_y1 x
*error* 2ND_POINT
DERIV_AT_POINT ENT_CLOSED
ENT_ENTGET ENT_LAYER
ENT_TEMP_OPEN LINE_PT1
LINE_PT2 MDIM_CLOCKTEST
MDIM_COUNTER MDIM_CURDIMSCAL
MDIM_CURLAY MDIM_CURLUPREC
MDIM_CUROSMODE MDIM_DAN
MDIM_ENTTEMP MDIM_ENTTEMP2
MDIM_PLINE_ENT MDIM_PLINE_ENT_VLA
MDIM_PLINE_PTS MDIM_PT1
MDIM_PT2 MDIM_SCALE
MDIM_SCALE_DIST MDIM_X
MDIM_X1 MDIM_Y
MDIM_Y1 MIDPOINT_AT_CURVE
PARAM_AT_POINT RON1
RON2 X
)
(vl-load-com)
(defun
*error*
(msg)
(setvar 'clayer mdim_curlay)
(setvar 'dimscale mdim_curdimscal)
(setvar 'luprec mdim_curluprec)
(command "._undo" "_end")
(setvar 'cmdecho 1)
(setvar 'osmode mdim_curosmode)
) ;_ end_defun
(defun
mdim_revpoly
(selected_pline)
(setq mdim_pt1
(vlax-curve-getendpoint
(vlax-ename->vla-object selected_pline)
) ;_ end_vlax-curve-getendpoint
) ;_ end_setq
(setq mdim_y (cadr mdim_pt1))
(setq mdim_x (car mdim_pt1))
(setq mdim_x1 (+ mdim_x 100))
(setq mdim_y1 (+ mdim_y 100))
(setq mdim_pt2 (list mdim_x mdim_y1))
(setvar 'clayer ent_layer)
(command "line" "NON" mdim_pt2 "NON" mdim_pt1 "")
(setq mdim_enttemp (entlast))
(command "pedit" mdim_enttemp "y" "j" selected_pline "" "")
(setq mdim_enttemp2 (entlast))
(command "break" mdim_enttemp2 "NON" mdim_pt1 "NON" mdim_pt1) ;_ end of command
;_ end of command
;_ end of command
(entupd mdim_enttemp2)
(command "erase" mdim_enttemp2 "")
(setq mdim_pline_ent (entlast))
(setq mdim_pline_pts
(mapcar
'(lambda (x) (trans x 0 1))
(mapcar
'cdr
(vl-remove-if-not
'(lambda (x) (= 10 (car x)))
(entget
mdim_pline_ent
) ;_ end_entget
) ;_ end_vl-remove-if-not
) ;_ end_mapcar
) ;_ end_mapcar
) ;_ end_setq
(defun
clockwise-p
(p1 p2 p3)
(< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)
) ;_ end_defun
(setq mdim_pline_ent_vla
(vlax-ename->vla-object mdim_pline_ent)
;(command "._regen")
) ;_ end_setq
) ;_ end_defun
(setvar 'cmdecho 0)
(command "._undo" "_end")
(command "._undo" "_begin")
(setq mdim_curlay (getvar 'clayer))
(setq mdim_curdimscal (getvar 'dimscale))
(setq mdim_curluprec (getvar 'luprec))
(setq mdim_curosmode (getvar 'osmode))
(command
"Layer" "m" "DIMS" "unlock" "DIMS" "thaw" "DIMS" "on" "DIMS" "c" "6" "DIMS" "") ;_ end_command
;_ end_command
;_ end_command
;_ end_command
;;user input function by Cab
(while
(progn
(setq mdim_scale
(cond ((getint "\nEnter the drawing scale [20/30/50] <50>: "))
(50)
) ;_ end_cond
) ;_ end_setq
(if (not (vl-position mdim_scale '(20 30 50)))
(not
(prompt "\nChoose only from 20 30 & 50, please re-enter.")
) ;_ end_not
) ;_ end_if
) ;_ end_progn
) ;_ end_while
(cond
((= mdim_scale 20) (setq mdim_scale_dist 140))
((= mdim_scale 30) (setq mdim_scale_dist 210))
((= mdim_scale 50) (setq mdim_scale_dist 350))
) ;_ end_cond
(setvar 'dimscale mdim_scale)
(while
(not
(setq
mdim_pline_ent
(ssget ":E:S" '((0 . "LWPOLYLINE")))
) ;_ end_setq
) ;_ end_not
(princ "\nMISSED....PICK AGAIN")
) ;_ end_while
;;; (command "._break" (ssname mdim_pline_ent 0) (vlax-curve-getendpoint (vlax-ename->vla-object (ssname mdim_pline_ent 0)))
;;; (vlax-curve-getendpoint (vlax-ename->vla-object (ssname mdim_pline_ent 0)))))
(setq ent_layer (cdr (assoc 8 (entget (ssname mdim_pline_ent 0)))))
(setq mdim_pline_pts
(mapcar
'(lambda (x) (trans x 0 1))
(mapcar
'cdr
(vl-remove-if-not
'(lambda (x) (= 10 (car x)))
(entget
(ssname mdim_pline_ent 0)
) ;_ end_entget
) ;_ end_vl-remove-if-not
) ;_ end_mapcar
) ;_ end_mapcar
) ;_ end_setq
(if (and
(= (setq ent_closed (cdr (assoc 70 (entget (ssname mdim_pline_ent 0))))) 1)
(not (Setq mdim_clocktest
(clockwise-p
(car mdim_pline_pts)
(cadr mdim_pline_pts)
(caddr mdim_pline_pts)
) ;_ end_clockwise-p
) ;_ end_Setq
) ;_ end_not
) ;_ end_and
(progn
(setq ent_entget (entget (ssname mdim_pline_ent 0)))
(entmod (subst (cons 70 0) (assoc 70 ent_entget) ent_entget))
(setq ent_temp_open t)
) ;_ end_progn
) ;_ end_if
(if (not mdim_clocktest
;_ end_Setq
) ;_ end_not
(mdim_revpoly (ssname mdim_pline_ent 0))
(setq mdim_pline_ent_vla
(vlax-ename->vla-object (ssname mdim_pline_ent 0))
) ;_ end_setq
;_ end_setq
) ;_ end_if
(setvar 'osmode 0)
(setq mdim_counter 0)
(while
(< mdim_counter
(fix
(vlax-curve-getendparam mdim_pline_ent_vla)
) ;_ end_fix
) ;_ end_<
(setq line_pt1
(vlax-curve-getpointatparam mdim_pline_ent_vla mdim_counter)
) ;_ end_setq
(setq line_pt2
(vlax-curve-getpointatparam
mdim_pline_ent_vla
(1+ mdim_counter)
) ;_ end_vlax-curve-getpointatparam
) ;_ end_setq
(command "._layer" "s" "DIMS" "")
(if (= (vla-getbulge mdim_pline_ent_vla mdim_counter) 0.0)
(progn
(princ "\nstraight")
(command
"._dimaligned"
"non"
line_pt1
"non"
line_pt2
"non"
(polar
line_pt2
(+ (angle line_pt1 line_pt2) (/ pi 2))
mdim_scale_dist
) ;_ end_polar
) ;_ end_command
) ;_ end_progn
(progn
(princ "\ncurve")
(setq midpoint_at_curve
(vlax-curve-getpointatdist
mdim_pline_ent_vla
(+
(*
(-
(vlax-curve-getdistatparam
mdim_pline_ent_vla
(1+ mdim_counter)
) ;_ end of vlax-curve-getdistatparam
(vlax-curve-getdistatparam
mdim_pline_ent_vla
mdim_counter
) ;_ end of vlax-curve-getdistatparam
) ;_ end of -
0.5
) ;_ end of *
(vlax-curve-getdistatparam mdim_pline_ent_vla mdim_counter)
) ;_ end of +
) ;_ end of vlax-curve-getpointatdist
) ;_ end of setq
(setq param_at_point
(vlax-curve-getparamatpoint
mdim_pline_ent_vla
midpoint_at_curve
) ;_ end of vlax-curve-getparamatpoint
) ;_ end of setq
(setq deriv_at_point
(vlax-curve-getfirstderiv
mdim_pline_ent_vla
param_at_point
) ;_ end of vlax-curve-getfirstderiv
) ;_ end of setq
(setq 2nd_point (mapcar '+ midpoint_at_curve deriv_at_point))
(command
"._dimangular"
""
(osnap (vlax-curve-getpointatparam
mdim_pline_ent_vla
param_at_point ;(1+ mdim_counter)
) ;_ end_vlax-curve-getpointatparam
"_cen"
) ;_ end_osnap
line_pt1
line_pt2
"non"
(polar
midpoint_at_curve
(+ (angle midpoint_at_curve 2nd_point) (/ pi 2))
mdim_scale_dist
) ;_ end_polar
) ;_ end_command
(setq mdim_dan (vlax-ename->vla-object (entlast)))
;(setvar 'luprec 0)
(vla-put-TextOverride
mdim_dan
(rtos
(- (Setq ron1 (vlax-curve-getdistatparam
mdim_pline_ent_vla
(1+ mdim_counter)
) ;_ end_vlax-curve-getdistatparam
) ;_ end_vlax-curve-getdistatparam
(Setq ron2 (vlax-curve-getdistatparam
mdim_pline_ent_vla
mdim_counter
) ;_ end of vlax-curve-getdistatparam
) ;_ end of Setq
) ;_ end_-
2
0
) ;_ end_-
) ;_ end_-
) ;_ end_vla-put-TextOverride
) ;_ end_progn
(setq mdim_counter (1+ mdim_counter))
) ;_ end_while
(if ent_temp_open
(progn
(entmod (subst (cons 70 1) (assoc 70 (entget mdim_pline_ent)) (entget mdim_pline_ent)))
(command
"._dimaligned"
"non"
(vlax-curve-getpointatparam
mdim_pline_ent_vla
(1- (vlax-curve-getendparam mdim_pline_ent_vla))
) ;_ end_vlax-curve-getpointatparam
"non"
(vlax-curve-getpointatparam mdim_pline_ent_vla (vlax-curve-getendparam mdim_pline_ent_vla))
"non"
(polar
(vlax-curve-getpointatparam
mdim_pline_ent_vla
(vlax-curve-getendparam mdim_pline_ent_vla)
) ;_ end_vlax-curve-getpointatparam
(+ (angle (vlax-curve-getpointatparam
mdim_pline_ent_vla
(1- (vlax-curve-getendparam mdim_pline_ent_vla))
) ;_ end_vlax-curve-getpointatparam
(vlax-curve-getpointatparam
mdim_pline_ent_vla
(vlax-curve-getendparam mdim_pline_ent_vla)
) ;_ end_vlax-curve-getpointatparam
) ;_ end_angle
(/ pi 2)
) ;_ end_+
mdim_scale_dist
) ;_ end_polar
) ;_ end_command
) ;_ end_progn
) ;_ end_if
(*error* "")
(princ)
) ;_ end_defun
(prompt ">>>...mdim.lsp is now loaded. Type 'mdim' to run command...<<<")
(princ)
Bookmarks