Polyline autodim lisp editting

Polyline autodim lisp editting

holyhexor0o0
Contributor Contributor
1,343 Views
7 Replies
Message 1 of 8

Polyline autodim lisp editting

holyhexor0o0
Contributor
Contributor

Hi all, I found this great lisp that does all the things needed,however there is a slight problem of the dim distance.

 

The distance is set in the script as
(* 3(getvar "DIMTXT")))

which is 3 times the Dim txt height. Every time that a different drawing needs a different distance, the script needs to be  changed

 

Can anyone edit this so it would jump out a prompt and we can type out the distance ourselves, or type out the type out the X amount of times of Dim txt height or smth.

0 Likes
Accepted solutions (3)
1,344 Views
7 Replies
Replies (7)
Message 2 of 8

komondormrex
Mentor
Mentor
Accepted solution

hey,

maybe like that

(defun c:pdim(/ plSet pLlst vLst oldOsn cAng cDis cPt times)
 (if (null init_list) (setq init_list '(3)))
 (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")
	 times (getint (strcat "Times DimTxt dimension distance <" (itoa (nth 0 init_list)) ">: "))
	 times (if (null times) (nth 0 init_list) times)
    ); 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))(* times (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)
	 (setq init_list (list times))
     ); end progn
   ); end if
 (princ)
 )
0 Likes
Message 3 of 8

holyhexor0o0
Contributor
Contributor

thanks, it sure works

0 Likes
Message 4 of 8

holyhexor0o0
Contributor
Contributor

Hi komondormrex,

First of all, thank you very much for your help. This Lisp is well used by my colleagues.

However the distance is sometimes a problem because it requires value of an interger.

 

Could you please edit this lisp to enter absolute number instead ?

0 Likes
Message 5 of 8

komondormrex
Mentor
Mentor
Accepted solution

hey there,

sure

(defun c:pdim(/ plSet pLlst vLst oldOsn cAng cDis cPt times)
 (if (null init_list) (setq init_list '(3.0)))
 (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")
	 times (getreal (strcat "Times DimTxt dimension distance <" (rtos (nth 0 init_list) 2 1) ">: "))
	 times (if (null times) (nth 0 init_list) times)
    ); 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))(* times (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)
	 (setq init_list (list times))
     ); end progn
   ); end if
 (princ)
 )
0 Likes
Message 6 of 8

holyhexor0o0
Contributor
Contributor

Thank you it works with non interger numbers now, however sorry for not making myself clear.

What i meant regarding "absolute number" it the number where you offset from polyline, not the number of "multiple for text height".

E.G Dimal 4 units from polyline (instead of 2 times of text height 2)

 

0 Likes
Message 7 of 8

komondormrex
Mentor
Mentor
Accepted solution

sorry, the following uses absolute dimension offset number.

(defun c:pdim (/ plSet pLlst vLst oldOsn cAng cDis cPt offset)
 	(if (null init_list) (setq init_list '(3.0)))
 	(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")
	 	  	  	  offset (getreal (strcat "Absolute dimension offset distance <" (rtos (nth 0 init_list) 2 1) ">: "))
	 	  	  	  offset (if (null offset) (nth 0 init_list) offset)
	 	  	); 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))
									 offset
							  )
	 	  			); 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)
	 	  	(setq init_list (list offset))
	 	  ); end progn
	); end if
 	(princ)
 )

 

0 Likes
Message 8 of 8

holyhexor0o0
Contributor
Contributor

Thank you very much mister superman

0 Likes