Jump to content

Auto dimesioning polyline


VaKaDi

Recommended Posts

Hello all.

I am looking (for quite a while now) for a way to automatically dimension (aligned dimensioning) a polyline. Unfotunately i can not find any way or any LISP tool to do this for me.

Is there any way to dimension a polyline?

 

PS: I am sorry if such a thread already exists but i did not find it!

Link to comment
Share on other sites

What are you considering a polyline to be???

a single segment or multiple segments...

 

Also what do you mean by auto dimension??

Do you just want to draw a line than when your done have a dimension magically appear??

Link to comment
Share on other sites

Is there no Quick Dimension option in 2005?

 

Hi. There is ofcourse but i am looking for the option of align dimensioning, with text going above each vertex (or line if you prefer)...

What are you considering a polyline to be??? a single segment or multiple segments... Also what do you mean by auto dimension?? Do you just want to draw a line than when your done have a dimension magically appear??
I consider polyline to be an object with many lines in it. What i want is to dimension (measure and appear the text) each line of the polyline, like choosing Dimension->aligned from autocad and place the text exactly above that line (like aligned dimension does)... I just do it manually selecting Dimension->aligned every time for each vertex which is taking too long. So i was considering for a way to this faster (maybe like selecting the polyline and it would get all of it's lines dimensioned)! Hope i answered your questions. Sorry for not being clear of what i want! And thanks for the reply! Really appreciate it!o:)
Link to comment
Share on other sites

It easy task for lisp programing:

 

(defun c:pdim(/ plSet pLlst vLst oldOsn cAng cDis cPt)
 (princ "\n<<< Select LwPolyline for dimensioning >>> ")
 (if(setq plSet(ssget '((0 . "LWPOLYLINE"))))
   (progn
     (setq pLlst(vl-remove-if 'listp
                        (mapcar 'cadr(ssnamex plSet))))
     (setvar "OSMODE" 0)(setvar "CMDECHO" 0)
     (foreach pl pLlst
(setq vLst(mapcar 'cdr
	    (vl-remove-if-not
	      '(lambda(x)(= 10(car x)))(entget pl)))
      oldOsn(getvar "OSMODE")
      ); end setq
(while(< 1(length vLst))
  (setq cAng(angle(car vLst)(cadr vLst))
	cDis(/(distance(car vLst)(cadr vLst))2)
	cPt(polar(polar(car vLst)cAng cDis)
		 (+ cAng(/ pi 2))(* 2(getvar "DIMTXT")))
	); end setq
  (command "_.dimaligned"(car vLst)(cadr vLst) cPt)
  (setq vLst(cdr vLst))
  ); end while
); end foreach
     (setvar "OSMODE" oldOsn)(setvar "CMDECHO" 1)
     ); end progn
   ); end if
 (princ)
 ); end of c:pdim

 

Dimension line offet distance equals 2 * Dimension Text Size (DIMTEXT variable) If you want to change it, please find and change (* 2(getvar "DIMTXT")) expression.

 

Edit: Do you want LwPolyline or 3dPolyline dimensioning?

Link to comment
Share on other sites

It easy task for lisp programing:

.

.

.

.

Dimension line offet distance equals 2 * Dimension Text Size (DIMTEXT variable) If you want to change it, please find and change (* 2(getvar "DIMTXT")) expression.

 

Edit: Do you want LwPolyline or 3dPolyline dimensioning?

 

Thank you ASMI! That is what i was looking for! But i spotted 1 problem. When i close a polyline (using c option), the lasts line dimension doesn't appear. Will try to fix this myself but if you could show a way i would be thankful! Also is there a way for them to appear just over the line? Changing the line offset gives strange results! For example putting 0.5* makes some lines appear ok and most appear in the line. Putting it 1* has almost the same result!

I really thank you for your help :D

 

PS: I was looking for the Lwpolyline. I mostly use PLINE anyway!

Link to comment
Share on other sites

It was too fast (trial) coding and many defects. Here an improved version:

 

(defun c:pdim(/ plSet pLlst vLst oldOsn cAng cDis cPt)
 (princ "\n<<< Select LwPolyline for dimensioning >>> ")
 (if(setq plSet(ssget '((0 . "LWPOLYLINE"))))
   (progn
     (setq pLlst(vl-remove-if 'listp
                        (mapcar 'cadr(ssnamex plSet)))
    oldOsn(getvar "OSMODE")
    ); end if
     (setvar "OSMODE" 0)(setvar "CMDECHO" 0)
     (command "_.undo" "_be")
     (foreach pl pLlst
(setq vLst(mapcar '(lambda(x)
	   (trans x 0 1))(mapcar 'cdr
	     (vl-remove-if-not
	       '(lambda(x)(= 10(car x)))(entget pl))))
      ); end setq
(if(equal '(70 . 1)(assoc 70(entget pl)))
  (setq vLst(append vLst(list(car vLst))))
  ); end if
(while(< 1(length vLst))
  (setq cAng(angle(car vLst)(cadr vLst))
        cDis(/(distance(car vLst)(cadr vLst))2))
  (if(>=(caar vLst)(caadr vLst))
    (setq cAng(- cAng pi))
    ); end if
  (setq cPt(polar
	     (polar(car vLst)cAng cDis)
	     (+ cAng(* 0.5 pi))(* 1.0(getvar "DIMTXT")))
	); end setq
  (command "_.dimaligned"(car vLst)(cadr vLst) cPt)
  (setq vLst(cdr vLst))
  ); end while
); end foreach
     (command "_.undo" "_e")
     (setvar "OSMODE" oldOsn)(setvar "CMDECHO" 1)
     ); end progn
   ); end if
 (princ)
 ); end of c:pdim

 

Now it works with UCS, has group UNDO and all dimension texts do not cross polyline.

pdim.gif

Link to comment
Share on other sites

It was too fast (trial) coding and many defects. Here an improved version:

.

.

.

.

Now it works with UCS, has group UNDO and all dimension texts do not cross polyline.

 

Thank you so much ASMI.Actually this one does work way better!

Thank you for all your trouble!:)

 

PS: I think this lisp should get known! Many people will find it useful...

Link to comment
Share on other sites

For some reason this lisp doesn't work for me.

Attached is an example and I'm using Acad2004.

 

It because your DIMASSOC system variable equals 0 (broken dimensions) set it to 1 or 2. Here is latest version with associative dimensioning:

 

;; ============================================================	;;
;;                                                              ;;
;;  PDIM.LSP - This lisp for dimensioning of several            ;;
;;             LwPolylines simultaneously. The program works    ;;
;;             with current dimensional style. The distance of  ;;
;;             the dimensional text from a polyline is equal    ;;
;;             to multiplication of height of the dimensional   ;;
;;             text (DIMTEXT system variable) on a variable     ;;
;;             'tOff'. You can change value of 'tOff' in the    ;;
;;             program beginning, after note.                   ;;
;;                                                          	;;
;; ============================================================	;;
;;                                                            	;;
;;  Command(s) to call: PDIM                         		;;
;;                                                          	;;
;;  Select LwPolylines and press Enter.	                        ;;
;;                                                            	;;
;; ============================================================	;;
;;                                                             	;;
;;  THIS PROGRAM AND PARTS OF IT MAY REPRODUCED BY ANY METHOD	;;
;;  ON ANY MEDIUM FOR ANY REASON. YOU CAN USE OR MODIFY THIS	;;
;;  PROGRAM OR PARTS OF IT ABSOLUTELY FREE.                 	;;
;;                                                              ;;
;;  THIS PROGRAM PROVIDES THIS PROGRAM 'AS IS' WITH ALL FAULTS	;;
;;  AND SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF		;;
;;  MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.            ;;
;;                                                            	;;
;; ============================================================	;;
;;                                                              ;;
;;  V1.2, 9th Okt 2008, Riga, Latvia                            ;;
;;  © Aleksandr Smirnov (ASMI)                          	;;
;;  For AutoCAD 2000 - 2008 (isn't tested in a next versions)	;;
;;                                                              ;;
;;                                 http://www.asmitools.com   	;;
;;                                                            	;;
;; ============================================================ ;;

(defun c:pdim(/ tOff plSet pLlst vLst oldDss cAng cDis cPt)

; NOTE 
;                                                                 
;  The distance of the text from a LwPolyline line is equal       
;  of multiplication of system variable 'DIMTXT' (height of       
;  the dimensional text) on a variable 'tOff'. Change this        
;  variable for change this distance.                             

 (setq tOff 1.0)
 
 (princ "\n<<< Select LwPolyline for dimensioning >>> ")
 (if(setq plSet(ssget '((0 . "LWPOLYLINE"))))
   (progn
     (setq pLlst(vl-remove-if 'listp
                        (mapcar 'cadr(ssnamex plSet)))
    oldDss(getvar "DIMASSOC")
    ); end if
     (setvar "CMDECHO" 0)
     (command "_.undo" "_be")
     (setvar "DIMASSOC" 2)
     (foreach pl pLlst
(setq vLst(mapcar '(lambda(x)
	   (trans x 0 1))(mapcar 'cdr
	     (vl-remove-if-not
	       '(lambda(x)(= 10(car x)))(entget pl))))
      ); end setq
(if(equal '(70 . 1)(assoc 70(entget pl)))
  (setq vLst(append vLst(list(car vLst))))
  ); end if
(while(< 1(length vLst))
  (setq cAng(angle(car vLst)(cadr vLst))
        cDis(/(distance(car vLst)(cadr vLst))2))
  (if(>=(caar vLst)(caadr vLst))
    (setq cAng(- cAng pi))
    ); end if
  (setq cPt(polar
	     (polar(car vLst)cAng cDis)
	     (+ cAng(* 0.5 pi))(* 1.0(getvar "DIMTXT")))
	); end setq
  (command "_.dimaligned" "_end" (car vLst)
	   "_end" (cadr vLst) "_none" cPt)
  (setq vLst(cdr vLst))
  ); end while
); end foreach
     (setvar "DIMASSOC" oldDss)
     (command "_.undo" "_e")
     (setvar "CMDECHO" 1)
     ); end progn
   ); end if
 (princ)
 ); end of c:pdim

(princ "\n*** Type PDIM for multiple LwPolyline dimensioning *** ")

Link to comment
Share on other sites

  • 5 months later...

Hi,

Is that possible that make this lisp also works on block dims(associate),not just polyline?

 

And it would be good that can choose the dimension sides.for example when I dim a window,normally I only need to dims two side(right side and top side),but when I use the PDIM command,choose the window,it will automatically give four dims.

tks

Link to comment
Share on other sites

Maybe this:

 

(defun c:dimblk (/ blk Minpt Maxpt cRds)
 (vl-load-com)
 (if (and (setq blk (car (entsel "\nSelect Block to Dimension...")))
      (eq "INSERT" (cdadr (entget blk))))
   (progn
     (vla-getBoundingBox
   (vlax-ename->vla-object blk) 'Minpt 'Maxpt)
     (setq cRds (mapcar 'vlax-safearray->list (list Minpt Maxpt)))
     (command "_dimlinear" (car cRds)
          (polar (car cRds) (/ pi 2) (- (cadadr cRds) (cadar cRds)))
          (polar (car cRds) pi (* 2 (getvar "DIMTXT"))))
     (command "_dimlinear" (car cRds)
          (polar (car cRds) 0 (- (caadr cRds) (caar cRds)))
          (polar (car cRds) (/ (* 3 pi) 2) (* 2 (getvar "DIMTXT")))))
   (princ "\n<!> No Block Selected <!>"))
 (princ))

Link to comment
Share on other sites

The above only works on blocks, but really, I think it could work on anything:

 

(defun c:dimobj (/ ent Minpt Maxpt cRds)
 (if (setq ent (car (entsel "\nSelect Something to Dimension...")))
   (progn
     (vla-getBoundingBox
   (vlax-ename->vla-object ent) 'Minpt 'Maxpt)
     (setq cRds (mapcar 'vlax-safearray->list (list Minpt Maxpt)))
     (command "_dimlinear" (car cRds)
          (polar (car cRds) (/ pi 2) (- (cadadr cRds) (cadar cRds)))
          (polar (car cRds) pi (* 2 (getvar "DIMTXT"))))
     (command "_dimlinear" (car cRds)
          (polar (car cRds) 0 (- (caadr cRds) (caar cRds)))
          (polar (car cRds) (/ (* 3 pi) 2) (* 2 (getvar "DIMTXT")))))
   (princ "\n<!> No Object Selected <!>"))
 (princ))

 

As in ASMI's code, the offset is 2x the DIMTXT size. - this can be modified if need be.

Link to comment
Share on other sites

Hi Lee Mac,

Thanks for the lisp,but the properites of the dimension is not associate.we really need assiciate.One more request,is that possible to choose several objects/blocks to make dims at the same time and make the dims text have specific distance from the objects?see the attached smaple.

 

thanks in advance

sample.dwg

Link to comment
Share on other sites

Maybe this?

 

(defun c:dimobj     (/ ss vlst ovar obj minpt maxpt crds)
 (if (setq ss (ssget))
   (progn
     (setq vlst '("CMDECHO" "OSMODE" "DIMASSOC")
       ovar (mapcar 'getvar vlst))
     (mapcar 'setvar vlst '(0 0 2))
     (foreach obj  (mapcar 'vlax-ename->vla-object
               (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
   (vla-getboundingbox obj 'minpt 'maxpt)
   (setq crds (mapcar 'vlax-safearray->list (list minpt maxpt)))
   (command "_dimlinear" (car crds)
        (polar (car crds) (/ pi 2) (- (cadadr crds) (cadar crds)))
        (polar (car crds) pi (* 2 (getvar "DIMTXT"))))
   (command "_dimlinear" (car crds)
        (polar (car crds) 0 (- (caadr crds) (caar crds)))
        (polar (car crds) (/ (* 3 pi) 2) (* 2 (getvar "DIMTXT")))))
     (mapcar 'setvar vlst ovar))
   (princ "\n<!> No Object Selected <!>"))
 (princ))

 

What offset would you like? A prompt for an offset?

Link to comment
Share on other sites

Sorry ,still not associative:(,see the attachment.

Can I have the distance dialog everytime ,so that I can decide different ditance for different situation.

 

Thanks

 

Maybe this?

 

(defun c:dimobj     (/ ss vlst ovar obj minpt maxpt crds)
 (if (setq ss (ssget))
   (progn
     (setq vlst '("CMDECHO" "OSMODE" "DIMASSOC")
       ovar (mapcar 'getvar vlst))
     (mapcar 'setvar vlst '(0 0 2))
     (foreach obj  (mapcar 'vlax-ename->vla-object
               (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
   (vla-getboundingbox obj 'minpt 'maxpt)
   (setq crds (mapcar 'vlax-safearray->list (list minpt maxpt)))
   (command "_dimlinear" (car crds)
        (polar (car crds) (/ pi 2) (- (cadadr crds) (cadar crds)))
        (polar (car crds) pi (* 2 (getvar "DIMTXT"))))
   (command "_dimlinear" (car crds)
        (polar (car crds) 0 (- (caadr crds) (caar crds)))
        (polar (car crds) (/ (* 3 pi) 2) (* 2 (getvar "DIMTXT")))))
     (mapcar 'setvar vlst ovar))
   (princ "\n<!> No Object Selected <!>"))
 (princ))

What offset would you like? A prompt for an offset?

associative.jpg

Link to comment
Share on other sites

This will include a prompt for offset distance - I can't work out the dimension associativity though... I've set the DIMASSOC to 2, and even when I have finished the LISP and try to dimension myself manually, the dims are associative, so not sure whats going on here...

 

(defun c:dimobj     (/ ss off vlst ovar obj minpt maxpt crds)
 (if (and (setq ss (ssget))
      (not (initget 7))
      (setq off (getdist "\nSpecify Offset Distance: ")))
   (progn
     (setq vlst '("CMDECHO" "OSMODE" "DIMASSOC")
       ovar (mapcar 'getvar vlst))
     (mapcar 'setvar vlst '(0 0 2))
     (foreach obj  (mapcar 'vlax-ename->vla-object
               (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
   (vla-getboundingbox obj 'minpt 'maxpt)
   (setq crds (mapcar 'vlax-safearray->list (list minpt maxpt)))
   (command "_dimlinear" (car crds)
        (polar (car crds) (/ pi 2) (- (cadadr crds) (cadar crds)))
        (polar (car crds) pi off))
   (command "_dimlinear" (car crds)
        (polar (car crds) 0 (- (caadr crds) (caar crds)))
        (polar (car crds) (/ (* 3 pi) 2) off)))
     (mapcar 'setvar vlst ovar))
   (princ "\n<!> No Object Selected <!>"))
 (princ))

  • Like 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...