guyzen2004 Posted October 15, 2008 Posted October 15, 2008 Can you please provide me a lisp wherein when you make a line, arc or a circle, the dimension is already incorporated into it. The dimension lines should be located at 7mm above or below the line. Thanks. Quote
wizman Posted October 16, 2008 Posted October 16, 2008 here is one for lines: (defun c:DLine (/ line_pt1 line_pt2) (if (and (setq line_pt1 (getpoint ">>>...Pick First Point...>>>:")) (setq line_pt2 (getpoint line_pt1 ">>>...Pick next point...>>>: ")) ) (progn (vl-cmdf "._line" line_pt1 line_pt2 "") (while line_pt2 (command "._dimaligned" line_pt1 line_pt2 (polar line_pt2 (+ (angle line_pt1 line_pt2) (/ pi 2)) 7 ) ) (setq line_pt1 line_pt2 line_pt2 '() ) (if (and line_pt1 (setq line_pt2 (getpoint line_pt1 ">>>...Pick next point...>>>: ")) ) (vl-cmdf "._line" line_pt1 line_pt2 "") ) ) ) ) (princ) ) (princ) Quote
guyzen2004 Posted October 17, 2008 Author Posted October 17, 2008 Hi Wizman, Thanks for the lisp file. It's the lisp that I'm looking for. But I apologize that I didn't give you a detailed explanation on the lisp that suits my needs. Actually I needed a lisp that could dimension a kind of reinforcing bar bending lenght. And I draw it into different scales (1/30, 1/20) but mostly 1/50 scale. The 7 mm distance of the dimension line is the actual distance from the rebar when you plot it to a given scale. So for a 1/50 scale the distance should be 350 mm, 1/30 is 210 mm and 1/20 is 140 mm. I hope you'll find time to send me another lisp. Thanks you very much. P.S. Could you make the layer of the dimension separated from the rebar. Drawing.dwg Quote
wizman Posted October 17, 2008 Posted October 17, 2008 this works for lines, i'll see if i can find time later for arcs. (defun c:DLine (/ line_pt1 line_pt2 dline_scale dline_curlay dline_scale_dist *error* ) (defun *error* (msg) (setvar 'clayer dline_curlay) (Setvar 'cmdecho 1) ) ;_ end_defun (Setvar 'cmdecho 0) (setq dline_curlay (getvar "clayer")) (command "Layer" "on" "DIMS" "unlock" "DIMS" "thaw" "DIMS" "m" "DIMS" "c" "6" "DIMS" "" ) ;_ end_command ;_ end_command ;;user input function by Cab (while (progn (setq dline_scale (cond ((getint "\nEnter the drawing scale [20/30/50] <50>: ")) (50) ) ;_ end_cond ) ;_ end_setq (if (not (vl-position dline_scale '(20 30 50))) (not (prompt "\nChoose only from 20 30 & 50, please re-enter.") ) ;_ end_not ) ;_ end_if ) ;_ end_progn ) ;_ end_while (cond ((= dline_scale 20) (setq dline_scale_dist 140)) ((= dline_scale 30) (setq dline_scale_dist 210)) ((= dline_scale 50) (setq dline_scale_dist 350)) ) ;_ end_cond (if (and (setq line_pt1 (getpoint "\n>>>...Pick First Point...>>>: " ) ;_ end_getpoint ) ;_ end_setq (setq line_pt2 (getpoint line_pt1 "\n>>>...Pick next point...>>>: " ) ;_ end_getpoint ) ;_ end_setq ) ;_ end_and (progn (setvar 'clayer dline_curlay) (vl-cmdf "._line" line_pt1 line_pt2 "") (while line_pt2 (setvar 'clayer "DIMS") (command "._dimaligned" "non" line_pt1 "non" line_pt2 "non" (polar line_pt2 (+ (angle line_pt1 line_pt2) (/ pi 2)) dline_scale_dist ) ;_ end_polar ) ;_ end_command (setvar 'clayer dline_curlay) (setq line_pt1 line_pt2 line_pt2 '() ) ;_ end_setq (if (and line_pt1 (setq line_pt2 (getpoint line_pt1 "\n>>>...Pick next point...>>>: " ) ;_ end_getpoint ) ;_ end_setq ) ;_ end_and (vl-cmdf "._line" line_pt1 line_pt2 "") ) ;_ end_if ) ;_ end_while ) ;_ end_progn ) ;_ end_if (*error* "") (princ) ) ;_ end_defun (prompt "\n>>>...dline.lsp is now loaded. Type dline to run...<<<" ) ;_ end_prompt (princ) Quote
guyzen2004 Posted October 17, 2008 Author Posted October 17, 2008 Thanks Wizman, It works perfectly. Would it be possible for a lisp in such a way that when you pick a polyline (please see attachment) it will execute the same mode of dimensioning? Drawing.dwg Quote
wizman Posted October 17, 2008 Posted October 17, 2008 update no. 3 ;|*********************************************************************************** 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) Quote
wizman Posted October 19, 2008 Posted October 19, 2008 here's the latest version...'-) -wiz mdim.lsp Quote
guyzen2004 Posted October 20, 2008 Author Posted October 20, 2008 Hi, I downloaded the mdim.lsp file but I can't make it work.When you pick on the polyline, an option for editing a polyline will just pop out. I tried it on both model space and paper space but just the same. I'm using Autocad 2007 and I don't know if it has an effect on that. As I see on your attached drawing it's a powerfull tool with regards to my line of work because it reduces my time putting dimensions on all the rebar outlines that I'm making of. I hope you still find time to go through this file.Thanks you. Quote
wizman Posted October 20, 2008 Posted October 20, 2008 i'll try take a look at it later today... try making a new an open pline with minimum of 3 segments first, then run mdim on that pline. let me know whats the result. Quote
guyzen2004 Posted October 20, 2008 Author Posted October 20, 2008 I tried the lisp file to Autocad2006 and it worked but with some discrepancy. I also made a polyline with 3 segments using autocad2007 but it didn't work either. Drawing.dwg Quote
wizman Posted October 20, 2008 Posted October 20, 2008 can you please try this...'-) -wiz Mdim-Wiz1.LSP Quote
guyzen2004 Posted October 22, 2008 Author Posted October 22, 2008 Hi Wizman, I downloaded your latest lisp file and it worked in Autocad 2006. I tried different kinds of closed polyline and closed polylines with radius at each corners and my officemates were amazed when I showed it to them. But there is one problem, It didn't work on a closed polyline with radius at each corners using autocad 2007. The same option for editing a polyline will just pop out. Thank you very much for making our work less laborious and I hope you wont get tired to make it work on a higher version. Attached is file using Autocad2006 Drawing.dwg Quote
wizman Posted October 22, 2008 Posted October 22, 2008 you're welcome guyzen, This is working fine here using '08 & '09. download and try this one. Mdim-Wiz1.LSP 1 Quote
guyzen2004 Posted October 22, 2008 Author Posted October 22, 2008 It's now working in autocad 2007. I can now share it to my co workers compliments of Mr. Wizman. Thanks again and don't stop sharing your knowledge to those who are less fortunate to understand lisp programming. P.S. Are we both born in the same island, and you're just working in a foreign land? Quote
wizman Posted October 22, 2008 Posted October 22, 2008 P.S. Are we both born in the same island, and you're just working in a foreign land? yes im also from philippines, im glad its now working for your purpose. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.