Ordinate dim Alignment program add text misplacement

Ordinate dim Alignment program add text misplacement

Anonymous
Not applicable
920 Views
2 Replies
Message 1 of 3

Ordinate dim Alignment program add text misplacement

Anonymous
Not applicable

Sorry , My English is not good

As I do not yet know how to code properly in LISP
Can help me add text misplacement?

Same as the picture

thank very much!!!

 

snap310.pngsnap411.png

 

joselggalan LISP:

(defun C:OrdinateDimAlign (/ OSPRE eDimBase ENTS Filter XorY XorY-Txt
			     ;|Functions|; GetX GetY jlgg-SSToList GetDimOrdinateType AlignTextDims
			  )
        ;;-------------------------- jlgg-SSToList -------------------------------
	;; selection set to list of entities                                      
	;;------------------------------------------------------------------------
	(defun jlgg-SSToList (ss / ssl n)
	 (if (and ss (= (type ss) 'PICKSET))
	  (repeat (setq n (sslength ss))
	   (setq ssl (cons (ssname ss (setq n (1- n))) ssl))))
	);c.defun
  	;;;_______________________________________________________________________________________________________
	;; Returns "HOR" value of a point from an entities data record  
	(defun GetX (eDimBase ANUM) (cadr (assoc ANUM (entget eDimBase))))
  	;;;_______________________________________________________________________________________________________
	;; Returns "VER" value of a point from an entities data record
	(defun GetY (eDimBase ANUM) (caddr (assoc ANUM (entget eDimBase)))) 
        ;;;_______________________________________________________________________________________________________
	;;; Determines if dims are horizontal or vertical
	(defun GetDimOrdinateType (eDimBase / Code70)
	 (setq Code70 (cdr (assoc 70 (entget eDimBase))))
	 (if (= 64 (logand 64 Code70))
	  (setq XorY 64 XorY-Txt "Abscissa")
	  (setq XorY 0  XorY-Txt "Ordinate")
	 )
	)
	;;;_______________________________________________________________________________________________________
	;;; Aligns dims
        (defun AlignTextDims (LstCotas / )
	 (mapcar
	   (function
	     (lambda (eDim / NewPt EntLst)
	      (setq NewPt
		     (cond
		       ((= XorY 0 ) (list 14 (GetX eDimBase  14) (GetY eDim 14) 0.0))
		       ((= XorY 64) (list 14 (GetX eDim 14) (GetY eDimBase  14) 0.0))
		     )
	      )
	      ;(princ "\nPT = ")(princ NewPt)
	      (setq EntLst (entget eDim))	; Sets EntLst to data record of ENTA
	      ;(princ "\nENTLST = ")(princ EntLst)
	      (setq EntLst (subst NewPt (assoc 14 (entget eDim)) EntLst)) ; Substitutes new point for DXF# 14
	      ;(princ "\nENTLST = ")(princ EntLst)
	      (entmod EntLst) ; Submits list to modify entity name contained in the list
	     )
	   )
	   LstCotas
	 )
	);defun

  ;;-------------------------- MAIN --------------------------
  (command "CMDECHO" 0)
  (setq OSPRE (getvar "OSMODE"))
  (setq Filter (list '(0 . "DIMENSION"))) 
  ;;Imputs user:
  (while (not eDimBase)
   (prompt "\nSelect base Ordinate dimension to align to: ")
   (cond
    ((and (setq eDimBase (ssget "_:S:E" Filter))
	  (setq eDimBase (ssname eDimBase 0))
	  (= 6 (logand 6  (cdr (assoc 70 (entget eDimBase))))) ;; = OrdinateDimension
	  ;;(vl-some (function (lambda (x) (= (cdr x) "AcDbOrdinateDimension"))) (entget eDimBase)))
     )
    )
    (T
     (prompt "\nNot selected Ordinate dimension..")
     (setq eDimBase nil)
    )
   )
  )
  
  ;;; Determines if dims are horizontal or vertical:
  (GetDimOrdinateType eDimBase)
  
  ;;_______________________________________________________
  ;; Selects dimensions to align to base
  (while (not ENTS)
   (prompt (strcat "\nSelect dimensions (" XorY-Txt ") to align: "))
   (setq ENTS (ssget Filter))
   (cond
    ((and
       (setq ENTS (jlgg-SSToList ENTS))
       (setq ENTS
	(vl-remove-if-not
	 (function
	   (lambda (eDim / Code70)
	    (setq Code70 (cdr (assoc 70 (entget eDim))))
	    (and (= 6    (logand 6  Code70))
		 (= XorY (logand 64 Code70)))
	   )
	 )
	 ENTS
        )
       )
      )
    )
    (T
     (prompt (strcat "\nNot Selected dimensions (" XorY-Txt ") to align: "))
     (setq ENTS nil)
    )
   ) 
  );; while
  
  (command "OSMODE" 0)
  
  ;;Aling Dims:
  (AlignTextDims ENTS)

  (command "OSMODE" OSPRE)
(princ)
)

 

0 Likes
Accepted solutions (1)
921 Views
2 Replies
Replies (2)
Message 2 of 3

dbhunia
Advisor
Advisor
Accepted solution

Hi,

 

Try this......(lightly tested)....

 

(defun C:OrdinateDimAlign (/ OSPRE eDimBase ENTS Filter XorY XorY-Txt
			     ;|Functions|; GetX GetY jlgg-SSToList GetDimOrdinateType AlignTextDims
			  )
(setq LST nil)
(setq BP_lst nil)
        ;;-------------------------- jlgg-SSToList -------------------------------
	;; selection set to list of entities                                      
	;;------------------------------------------------------------------------
	(defun jlgg-SSToList (ss / ssl n)
	 (if (and ss (= (type ss) 'PICKSET))
	  (repeat (setq n (sslength ss))
	   (setq ssl (cons (ssname ss (setq n (1- n))) ssl))))
	);c.defun
  	;;;_______________________________________________________________________________________________________
	;; Returns "HOR" value of a point from an entities data record  
	(defun GetX (eDimBase ANUM) (cadr (assoc ANUM (entget eDimBase))))
  	;;;_______________________________________________________________________________________________________
	;; Returns "VER" value of a point from an entities data record
	(defun GetY (eDimBase ANUM) (caddr (assoc ANUM (entget eDimBase)))) 
        ;;;_______________________________________________________________________________________________________
	;;; Determines if dims are horizontal or vertical
	(defun GetDimOrdinateType (eDimBase / Code70)
	 (setq Code70 (cdr (assoc 70 (entget eDimBase))))
	 (if (= 64 (logand 64 Code70))
	  (setq XorY 64 XorY-Txt "Abscissa")
	  (setq XorY 0  XorY-Txt "Ordinate")
	 )
	)
	;;;_______________________________________________________________________________________________________
	;;; Aligns dims
        (defun AlignTextDims (LstCotas / )
	 (mapcar
	   (function
	     (lambda (eDim / NewPt EntLst)
	      (setq NewPt
		     (cond
		       	((= XorY 0 ) (list 14 (GetX eDimBase  14) (GetY eDim 14) 0.0))
		       	((= XorY 64) (list 14 (GetX eDim 14) (GetY eDimBase  14) 0.0))
		     )
	      )
	      ;(princ "\nPT = ")(princ NewPt)
	      (setq EntLst (entget eDim))	; Sets EntLst to data record of ENTA
	      ;(princ "\nENTLST = ")(princ EntLst)
	      (setq EntLst (subst NewPt (assoc 14 (entget eDim)) EntLst)) ; Substitutes new point for DXF# 14
	      ;(princ "\nENTLST = ")(princ EntLst)
	      (entmod EntLst) ; Submits list to modify entity name contained in the list
		(setq Ent_BP (list (cdr (assoc -1 (entget eDim))) (cdr (assoc 14 (entget eDim)))))
		(setq BP (cdr (assoc 14 (entget eDim))))
		(setq LST (cons Ent_BP LST))
		(setq BP_lst (cons BP BP_lst))
	     )
	   )
	   LstCotas
	 )
	);defun

  ;;-------------------------- MAIN --------------------------
  (command "CMDECHO" 0)
  (setq OSPRE (getvar "OSMODE"))
  (setq Filter (list '(0 . "DIMENSION"))) 
  ;;Imputs user:
  (while (not eDimBase)
   (prompt "\nSelect base Ordinate dimension to align to: ")
   (cond
    ((and (setq eDimBase (ssget "_:S:E" Filter))
	  (setq eDimBase (ssname eDimBase 0))
	  (= 6 (logand 6  (cdr (assoc 70 (entget eDimBase))))) ;; = OrdinateDimension
	  ;;(vl-some (function (lambda (x) (= (cdr x) "AcDbOrdinateDimension"))) (entget eDimBase)))
     )
    )
    (T
     (prompt "\nNot selected Ordinate dimension..")
     (setq eDimBase nil)
    )
   )
  )
  
  ;;; Determines if dims are horizontal or vertical:
  (GetDimOrdinateType eDimBase)
  
  ;;_______________________________________________________
  ;; Selects dimensions to align to base
  (while (not ENTS)
   (prompt (strcat "\nSelect dimensions (" XorY-Txt ") to align: "))
   (setq ENTS (ssget Filter))
   (cond
    ((and
       (setq ENTS (jlgg-SSToList ENTS))
       (setq ENTS
	(vl-remove-if-not
	 (function
	   (lambda (eDim / Code70)
	    (setq Code70 (cdr (assoc 70 (entget eDim))))
	    (and (= 6    (logand 6  Code70))
		 (= XorY (logand 64 Code70)))
	   )
	 )
	 ENTS
        )
       )
      )
    )
    (T
     (prompt (strcat "\nNot Selected dimensions (" XorY-Txt ") to align: "))
     (setq ENTS nil)
    )
   ) 
  );; while
  
  (command "OSMODE" 0)
  
  ;;Aling Dims:
  (AlignTextDims ENTS)
  (Rearrange_Dim)
  (command "OSMODE" OSPRE)
(princ)
)
(defun Rearrange_Dim (/);Put temp variables.....
(setq DIMO nil)
(cond
	((= XorY 0 ) 
		(setq BP_lst (vl-sort BP_lst (function (lambda (e1 e2) (> (cadr e1) (cadr e2))))))
		(setq ang (/ (* pi 3) 2))
	);;Sort_Y
	((= XorY 64) 
		(setq BP_lst (vl-sort BP_lst (function (lambda (e1 e2) (< (car e1) (car e2))))))
		(setq ang 0)
	);;Sort_X
)
(repeat (setq N (length BP_lst))
	(setq BP_lst_P1 (nth (setq N (- N 1)) BP_lst))
	(setq DIS_lst nil)
	(repeat (setq N1 (length LST))
		(setq LST_1 (nth (setq N1 (- N1 1)) LST))
	    	(setq LST_P1 (nth 1 LST_1))
			(if (equal BP_lst_P1 LST_P1)
				(setq DIMO (cons (nth 0 LST_1) DIMO))
			)
	)
)
(setq L 0)
(setq DIMO_PT1 (cdr (assoc 14 (entget (nth 0 DIMO)))))
(setq TH_DIMO_PT1 (vla-get-TextHeight (vlax-ename->vla-object (nth 0 DIMO))))
(repeat (- (setq N2 (length DIMO)) 1)
	(setq DIMO_PT2 (cdr (assoc 14 (entget (nth (setq L (+ L 1)) DIMO)))))
	(setq TH_DIMO_PT2 (vla-get-TextHeight (vlax-ename->vla-object (nth L DIMO))))
		(cond
			((= XorY 0 ) (setq DIS (- (nth 1 DIMO_PT1) (nth 1 DIMO_PT2))));;Sort_Y
			((= XorY 64) (setq DIS (- (nth 0 DIMO_PT2) (nth 0 DIMO_PT1))));;Sort_X
		)
		(if (<= DIS (setq TG (* (/ (+ TH_DIMO_PT1 TH_DIMO_PT2) 2 ) 1.5)))
			(progn
				(entmod (subst (cons 14 (polar DIMO_PT1 ang TG)) (assoc 14 (entget (nth L DIMO))) (entget (nth L DIMO))))
				(setq DIMO_PT1 (polar DIMO_PT1 ang TG))
			)
			(progn
				(setq DIMO_PT1 DIMO_PT2)
			)
		)
)
(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 3

Anonymous
Not applicable

Choose middle
Can  separate left and right?
Same as the picture
Thank123.png

0 Likes