리습 강좌 - 문자 수정을 캐드화면에서 바로 수정하기 명령.


본 강좌는 아키오피스(김희태)에 의해 만들어 졌으며 어떠한 웹이나
출판물에 아키오피스(김희태)의 동의없이 올리는 것을 허락하지 않습니다.

 

이 예제는 ddedit 시 문자수정할때 다이얼로그상에서 문자를 수정해야 했는데
이런 것보다는 캐드화면에서 바로 수정하는게 어떤 사용자에서는 더 편할수 있습니다.

단 기능의 단점은 수정모드에서 커서가 항상 문자맨 뒤에 가있음.(마치 text 명령과 똑같음)
오토캐드 2000 버전이상에서 작동하고 LT 버전은 제외.

vla-sendcommand 함수를 사용한 이유는 command 함수로는
아래 그림처럼 수정모드가 되지 않기 때문입니다.




Command:tedit (명령실행) => 문자 선택 => 문자 수정모드


코드

  
  (defun get_text_Align_string (tDxf / t72 t73 restr)
    (setq t72 (cdr (assoc 72 tDxf))
	  t73 (cdr (assoc 73 tDxf))
    )
    (cond
      ((or (and (= t72 0) (= t73 0)) (and (= t72 0) (= t73 nil)))
       (setq restr "")
      )
      ((and (= t72 1) (= t73 0)) (setq restr "j c ") )
      ((and (= t72 2) (= t73 0)) (setq restr "j r ") )
      ((and (= t72 4) (= t73 0)) (setq restr "j m ") )
      ((and (= t72 5) (= t73 0)) (setq restr "j f ") )
      ((and (= t72 3) (= t73 0)) (setq restr "j a ") )
      ((and (= t72 0) (= t73 3)) (setq restr "j tl ") )
      ((and (= t72 1) (= t73 3)) (setq restr "j tc ") )
      ((and (= t72 2) (= t73 3)) (setq restr "j tr ") )
      ((and (= t72 0) (= t73 2)) (setq restr "j ml ") )
      ((and (= t72 1) (= t73 2)) (setq restr "j mc ") )
      ((and (= t72 2) (= t73 2)) (setq restr "j mr ") )
      ((and (= t72 0) (= t73 1)) (setq restr "j bl ") )
      ((and (= t72 1) (= t73 1)) (setq restr "j bc ") )
      ((and (= t72 2) (= t73 1)) (setq restr "j br ") )
    )
    restr
  )

  (defun conv-point->str (pt / )
    (strcat (rtos (car pt) 2 8) "," (rtos (cadr pt) 2 8) )
  )

  (defun rtd (a)(/ (* a 180.0) pi))

  (defun c:tedit ( / tss tDxf tstyle tAlign tPt11 tPt10 tLayer tHeight tAngle tText runstr)
    (vl-load-com)
    (setq tss (ssget ":S" '((0 . "text"))))
    (if tss
      (progn
        (setq tDxf (entget (ssname tss 0))
              tstyle  (strcat "s " (cdr (assoc 7 tDxf)) "\r")
              tAlign  (get_text_Align_string tDxf)
              tHeight (strcat (rtos (cdr (assoc 40 tDxf)) 2 8) "\r")
              tAngle  (strcat (rtos (rtd (cdr (assoc 50 tDxf))) 2 8) "\r")
              tText   (cdr (assoc 1 tDxf))
              tLayer  (cdr (assoc 8 tDxf))
              tPt10   (strcat (conv-point->str (cdr (assoc 10 tDxf))) "\r")
              tPt11   (if (cdr (assoc 11 tDxf)) (strcat (conv-point->str (cdr (assoc 11 tDxf))) "\r"))
        )
        (cond
          ((= tAlign "j a ") (setq runstr (strcat "text " tstyle tAlign tPt10 tPt11 tText)))
          ((= tAlign "j f ") (setq runstr (strcat "text " tstyle tAlign tPt10 tPt11 tHeight tText)))
          ((= tAlign "")     (setq runstr (strcat "text " tstyle tAlign tPt10 tHeight tAngle tText)))
          (t                 (setq runstr (strcat "text " tstyle tAlign tPt11 tHeight tAngle tText)))
        )
        (setvar "clayer" tLayer)
        (command "erase" (ssname tss 0) "")
        (vla-sendcommand
          (vla-get-activedocument (vlax-get-acad-object))
          runstr
        )
      )
    )
  )