+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Full Member
    Using
    not specified
    Join Date
    Apr 2006
    Location
    Philippines
    Posts
    61

    Default Lisp for dimensioning

    Registered forum members do not see this ad.

    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.

  2. #2
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    here is one for lines:

    Code:
    (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)

  3. #3
    Full Member
    Using
    not specified
    Join Date
    Apr 2006
    Location
    Philippines
    Posts
    61

    Default

    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.
    Attached Files

  4. #4
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    this works for lines, i'll see if i can find time later for arcs.
    Code:
    (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)

  5. #5
    Full Member
    Using
    not specified
    Join Date
    Apr 2006
    Location
    Philippines
    Posts
    61

    Default

    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?
    Attached Files

  6. #6
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    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)
    Last edited by wizman; 19th Oct 2008 at 05:03 pm. Reason: code update no.3

  7. #7
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    updated code above.........:-)



    -wiz

  8. #8
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    here's the latest version...'-)

    -wiz
    Attached Images
    Attached Files
    Last edited by wizman; 19th Oct 2008 at 06:17 pm.

  9. #9
    Full Member
    Using
    not specified
    Join Date
    Apr 2006
    Location
    Philippines
    Posts
    61

    Default

    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.

  10. #10
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    Registered forum members do not see this ad.

    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.

Similar Threads

  1. VBA dimensioning
    By smed in forum Autodesk Inventor
    Replies: 1
    Last Post: 1st Oct 2007, 02:47 pm
  2. Replies: 10
    Last Post: 24th Aug 2007, 05:34 pm
  3. 3D Dimensioning Help!?^%$
    By apache73 in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 23rd May 2007, 03:46 pm
  4. Dimensioning
    By aintgotone in forum AutoCAD Drawing Management & Output
    Replies: 0
    Last Post: 3rd Aug 2005, 01:41 pm
  5. Lisp for dimensioning to the centre of a wall?
    By victoreric in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 21st Feb 2005, 02:08 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts