・ LWPOLYLINEの頂点座標を取得する

LWPOLYLINEの頂点座標のエンティティーデータのグループコードは 10 ですが、頂点の数だけデータも現れます。

頂点座標のリストを取得するには、Jof_pt_list のようにします。

(defun Jof_pt_list ()
  (setq ent (nentsel "\nLWPOLYLINEを選択")) 
  (setq ed (entget (car ent)))
  (while (setq pt (assoc 10 ed)) ; 頂点座標リストを取得
    (setq pt_list (append pt_list (list pt)))
    (setq ed (cdr (member pt ed))) ; 取得した以降のエンティティーデータ
    )
  pt_list
  )

n番目の頂点のデータが欲しい場合は、(member) で分割して調べます。

(defun Jo_nth_pt ( / ed pt_list n ed_list pt_data
                     Jof_pt_list Jof_ed_list Jof_pt_data )

  ; サブルーチン pt_listの取得 ;
  (defun Jof_pt_list ( ed / pt pt_list )
    (while (setq pt (assoc 10 ed))
      (setq pt_list (append pt_list (list pt)))
      (setq ed (cdr (member pt ed)))
      )
    pt_list
    )

  ; サブルーチン n番目の頂点座標のデータでedを2つのリストに分割 ;
  (defun Jof_ed_list ( ed n / pt ed_1 ed_2 ed_3 ed_4 i c c_list ed_list )
    (setq ed_3 (cdr ed))
    (repeat n
      (setq pt (assoc 10 ed_3))
      (setq ed_2 (member pt ed_3))
      (setq c (1+ (- (length ed_3) (length ed_2))))
      (setq c_list (append c_list (list c)))
      (setq ed_3 (cdr ed_2))
      )
    (setq pt (assoc 10 ed_3))
    (setq ed_4 (member pt ed_3))
    (if ed_4
      (progn
        (setq c (1+ (- (length ed_3) (length ed_4))))
        (setq c_list (append c_list (list c)))
        (setq c_list (append c_list (list (length ed_4))))
        )
      (progn
        (setq c (last c_list))
        (setq c_list (append c_list (list c)))
        (setq c_list (append c_list (list (1+ (- (length ed_3) c)))))
        )
      )
    (setq i 0)
    (repeat (- (length ed)(length ed_2))
      (setq ed_1 (append ed_1 (list (nth i ed))))
      (setq i (1+ i))
      )
    (if (= (length ed) (apply '+ c_list))
      (setq ed_list (list ed_1 ed_2 c_list))
      (progn
        (princ "\nエラー:チェックサム不整合<Jof_ed_list>")
        (princ (strcat "\ned:" (itoa (length ed))))
        (princ "\n")
        (princ c_list)
        (exit)
        )
      )
    ed_list
  )

  ;サブルーチン n番目のデータを返す;
  (defun Jof_pt_data ( ed_list n / ed_2 c i pt_data)
    (setq ed_2 (cadr ed_list))
    (setq c (nth n (caddr ed_list)))
    (setq i 0)
    (repeat c
      (setq pt_data (append pt_data (list (nth i ed_2))))
      (setq i (1+ i))
      )
    pt_data
    )

  ; メインルーチン ;
  (setq ed (entget (car (entsel "\nLWPOLYLINEを選択"))))
  (if (/= "LWPOLYLINE" (cdr (assoc 0 ed)))
    (exit)
    )
  (setq pt_list (Jof_pt_list ed))
  (while (not n)
    (initget 7)
    (setq n (getint (strcat "\n何番目の頂点のデータが必要ですか<1〜" (itoa (length pt_list)) ">:")))
    (if (< (length pt_list) n)
      (setq n nil)
      )
    )
  (setq ed_list (Jof_ed_list ed n))
  (setq pt_data (Jof_pt_data ed_list n))
  (mapcar 'print pt_data)
  (princ)
  )