;CANAL-Tx-EditPname.lsp

;測点名編集
;EditPname

;**********************;Dec.20.2025
(defun C:EditPname (/ )
;**********************

	(princ "\n旗上げ座標オブジェクトを選択")
	(setq Obj (ssget (list (cons 0 "MTEXT"))))
	;(setq Obj (ssget '((0 . "MTEXT"))));<---これでもOK
	;----------------------
	(if (not(= Obj nil));選択されていたら・・・
		(progn
			(setq 測点名 (getenv "測点名"))
      
			(setq cnt 0)
			(setq num (sslength Obj))

    
      (princ)(princ  num);!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
			(while (< cnt num)
				(setq MyEnt (ssname Obj cnt))
				(setq Ent (entget MyEnt))
				(setq MyHandle  (cdr (assoc 5 Ent)));ハンドル名
				;+++++
				(setq  Orgtxt (Cdr(Assoc 1 Ent)))
				(setq MyVal "")
        (princ)(princ Orgtxt);!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
				;+++++ Pname
        ;(setq  Result "FALSE")
        (setq MyValx (vl-string-search "X=" Orgtxt));検索
        (if (>= MyValx 0)(setq  MyVal MyValx))
        (setq MyValx (vl-string-search "\PX=" Orgtxt));検索
        (if (>= MyValx 0)(setq MyVal (+ MyValx 1)))
				(setq MyValx (vl-string-search "X1=" Orgtxt));検索
        (if (>= MyValx 0)(setq  MyVal MyValx))
        (setq MyValx (vl-string-search "X2=" Orgtxt));検索
        (if (>= MyValx 0)(setq  MyVal MyValx))   
        (setq MyValx (vl-string-search "XK=" Orgtxt));検索
        (if (>= MyValx 0)(setq  MyVal MyValx))
        (setq MyValx (vl-string-search "XCL=" Orgtxt));検索
        (if (>= MyValx 0)(setq  MyVal MyValx))  
        (setq MyValx (vl-string-search "XD=" Orgtxt));検索
        (if (>= MyValx 0)(setq  MyVal MyValx))
     
     
     
        ;(princ Result);!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     
        (princ)(princ MyVal);!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


        (if (> MyVal 0)(setq  Orgtxt (substr Orgtxt (+ MyVal 1))))
				(if (>= MyVal 0);
					(progn
            ;(command "select" (handent MyHandle) "")
            ;-------------
            ;(setq Obj (ssget "_P"));直前選択
            ;(setq MyEnt (ssname Obj 0))
            ;(setq Ent (entget MyEnt))
            ;-------------
       
       
       
       
       
            ;(setq  Orgtxt (substr Orgtxt MyVal))
            (Setq  Newtxt (Strcat 測点名 "\\P" Orgtxt))
            (princ Newtxt);!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            (setq Ent ;書き直したDXF図形情報のリストをEntに入れ直し
              (subst ;入れ替える
                (cons 1 Newtxt) ; 新しい値
                (assoc 1 Ent) ; 古い値
              Ent) ;Entに入っているDXF図形情報のリストを
            );setq
            (entmod Ent) ;DXF図形情報を図形に反映
					);progn	
					
				);if
				;+++++

        (setq cnt (1+ cnt))
			);while
		);progn 
		(alert "選択エラー");ポリラインが選択されていなかったら・・・  
	);if
  (princ)
);

