Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to prevent attribute stacking, after programatically rotating.

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
bhull1985
416 Views, 3 Replies

How to prevent attribute stacking, after programatically rotating.

Hey everyone , i'm using an attribute rotation function to rotate attributes if a block is rotated. they would be rotated orthogonally only, and i think this picture will explain best.

 

rot.jpg

 

Here is the rotation function.

(defun ssvla (selection-set / index vla-list)
  (setq	index (if selection-set
		(1- (sslength selection-set))
		-1
	      )
  )
  (while (>= index 0)
    (setq vla-list (cons (vlax-ename->vla-object
			   (ssname selection-set index)
			 )
			 vla-list
		   )
	  index	   (1- index)
    )
  )
  vla-list
);; ssvla


(defun HORIZ (/ ss)
  (if (setq ss (ssget "_L" '((0 . "INSERT"))))
    (foreach obj (ssvla ss)
      (foreach att (vlax-safearray->list
		     (vlax-variant-value (vla-getattributes obj))
		   )
	(vla-put-rotation att 0.0)
      )
    )
  )
  (princ)

 and where it is being called, for completeness.

(defun MySub (a1 a2 a3 insertpt1 / OBJ P2 P3 doc)						;subfunction
(vl-load-com)										;load vlisp functions
;(setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (if (= objx 1)									;if objx is 1, ent=line or pline
    (progn										;preform these actions
(setvar "osmode" 0)									;first turn off osnap
  (princ)
(if (> a2 0.0)										;if trim dist is greater than 0.0 preform
(progn											;these actions
(setq obj (vlax-ename->vla-object name))						;get entity object
(if (eq (vla-get-ObjectName obj) "AcDbPolyline")					;if it is a LwPolyline
     (setq p3 insertpt1									;get first break point

	   p2 (angle insertpt1  (vlax-curve-getpointatparam obj  
		(fix (vlax-curve-getparamatpoint obj 
		(vlax-curve-getClosestPointTo obj insertpt1 T))))))	     
(setq p3 insertpt1									;and second break point
      p2 (angle (vlax-curve-getStartpoint obj) (vlax-curve-getEndPoint obj)))
)											;if
(command "break" name (polar p3 p2 a2) (polar p3 p2 a3))
(command "_insert" a1 insertpt1 "" "" pause)						;insert into space
;(vla-sendcommand doc (strcat "horiz" " " "L" " " " "))					;break line
(HORIZ)
)											;progn
(princ "\n......Selected....\n......Breaking Lines....")				;status

)											;if
)	
(progn		
  (command "_insert" a1 insertpt1 "" "" pause)						;insert onto line
 ;(vla-sendcommand doc (strcat "horiz" " " "L" " " " "))
  (HORIZ)
 (princ)
)
)											;if
(princ "\n......Insertion Completed!")							;princ
(princ)
;(ARXUNLOAD "AT_CUSTDB" "DBX")											;print clear
(setq name nil)
)											;MySub

 Would I need to establish a check to see if the rotation is a 90 or 270 and then if so have each attribute moved by a value of the text height? first att moved up second att moved down? How would I go about this, properly, and with the ability to incorporate into the existing code?

Any help, as always, is greatly appreciated.

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
3 REPLIES 3
Message 2 of 4
bhull1985
in reply to: bhull1985

Was my thinking-out-loud method correct?

Or does just nobody know how to do this? 😕

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 3 of 4
bhull1985
in reply to: bhull1985

Can anyone let me know if the move method is the best way to accomplish this or if there is a vla command that would seperate stacked attributes?

Thank you, still having this problem 😕

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 4 of 4
bhull1985
in reply to: bhull1985

Answer provided by the amazing mr henrique

(defun MyHor (/ data ent flag h l p1 pts r typ)
  (setq	data (entget (setq ent (entlast)))
	r    (cdr (assoc 50 data))
  )
  (if (or (equal r (/ pi 2.0) 1e-8)
	  (equal r (* pi 1.5) 1e-8)
      )
    (setq flag T)
  )

  (cond
    ((and (eq 1 (cdr (assoc 66 data))) (not flag))
     (while (/= "SEQEND" (setq typ (cdr (assoc 0 data))))
       (cond
	 ((eq "ATTRIB" typ)
	  (entmod (subst (cons 50 0.0) (assoc 50 data) data))
	 )
       )
       (setq data (entget (setq ent (entnext ent))))
     )
     (entupd (entlast))
    )

    ((and (eq 1 (cdr (assoc 66 data))) flag)
     (while (/= "SEQEND" (setq typ (cdr (assoc 0 data))))
       (cond
	 ((eq "ATTRIB" typ)
	  (setq	pts (setq l (cons (cdr (assoc 11 data)) pts))
		h   (cdr (assoc 40 data))
	  )
	 )
       )
       (setq data (entget (setq ent (entnext ent))))
     )
     (setq p1 (midpt pts)
	   p1 (mapcar '+ p1 (list 0.0 (* 1.25 h) 0.0))
     )
     (setq data (entget (setq ent (entlast))))
     (while (/= "SEQEND" (setq typ (cdr (assoc 0 data))))
       (cond
	 ((eq "ATTRIB" typ)
	  (entmod (setq data (subst (cons 11 p1) (assoc 11 data) data)))
	  (entmod (subst (cons 50 0.0) (assoc 50 data) data))
	  (setq p1 (mapcar '- p1 (list 0.0 (* 1.25 h) 0.0)))
	 )
       )
       (setq data (entget (setq ent (entnext ent))))
     )
    )
    (entupd (entlast))
  )
  (princ)
)


(defun midpt (ptlst / a b)
  (mapcar '(lambda (a b) (/ (+ a b) 2))
	  (apply 'mapcar (cons 'min ptlst))
	  (apply 'mapcar (cons 'max ptlst))
  )
)

 Close enough, shows a way to do it and this thread wants closing. Done!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost