export coordinates to text from schema

export coordinates to text from schema

bcddss
Enthusiast Enthusiast
534 Views
5 Replies
Message 1 of 6

export coordinates to text from schema

bcddss
Enthusiast
Enthusiast

I have this code :

 

(defun c:cgxml (/ *error* file sset ename lst i)
  (vl-load-com)
  (defun *error* (s)
    (if file
      (close file)
    )
    (cond
      ((not s))
      ((member s '("Function cancelled" "quit / exit abort")))
      ((princ (strcat "\n---->Error:" s)))
    )
    (princ)
  )
(setq point-id 1)
  (if (setq sset (ssget "_:L" '((0 . "LWPOLYLINE,POLYLINE"))))
    
(progn
      (if (setq file (open (strcat (getvar 'dwgprefix) "Lwpolyline Vertex List.txt") "w"))
(progn
(repeat 
(setq i (sslength sset))
        (write-line "" file)
(write-line (STRCAT "Polilinie " (ITOA I)) file)
(write-line "" file)
(setq ename (vlax-ename->vla-object (ssname sset (setq i (1- i)))))
(setq lst (vlax-safearray->list (vlax-variant-value (vla-get-coordinates ename))))
        (setq point-nr 1)
        (repeat (/ (length lst) 2)
        (write-line "<Points>" file)
        (write-line (strcat "  <POINTID>" (itoa point-id) "</POINTID>") file)
        (write-line "<IMMOVABLEID>1</IMMOVABLEID>" file) 
       ;(write-line "<BUILDINGID>1</BUILDINGID>" file)
        (write-line (strcat "  <NO>" (itoa point-nr) "</NO>") file)
        (write-line (strcat "  <X>" (rtos (car lst) 2 3) "</X>") file)
                (write-line (strcat "  <Y>" (rtos (cadr lst) 2 3) "</Y>") file)
                (setq point-id (1+ point-id))
(setq point-nr (1+ point-nr))
        (write-line "</Points>" file)
;(write-line "" file)
        (setq lst (cddr lst))
    )
  )
  (close file)
  (alert "\nVertex Points exported to txt file.")
  (alert (strcat "File saved in - " (getvar 'dwgprefix) "Lwpolyline Vertex List.txt")))
  (alert "\nTXT file Currenty running, Close it first.")
      )
    )
    (*error* "Nothing Selected.")
  )
  (*error* nil)
  (princ)
)
 
to export coordinates from polylines in selection set to file using schema. But the selected polyline is in reverse order and i need to be in order of selection by click. 
 
the result is a file with the result in reverse order
 

Polyline 3

<Points>
<POINTID>1</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>1</NO>
<X>726741.925</X>
<Y>393269.132</Y>
</Points>
<Points>
<POINTID>2</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>2</NO>
<X>726715.289</X>
<Y>393199.819</Y>
</Points>
<Points>
<POINTID>3</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>3</NO>
<X>726712.514</X>
<Y>393168.212</Y>
</Points>
<Points>
<POINTID>4</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>4</NO>
<X>726770.781</X>
<Y>393148.250</Y>
</Points>
<Points>
<POINTID>5</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>5</NO>
<X>726807.406</X>
<Y>393194.828</Y>
</Points>
<Points>
<POINTID>6</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>6</NO>
<X>726823.498</X>
<Y>393232.534</Y>
</Points>
<Points>
<POINTID>7</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>7</NO>
<X>726824.052</X>
<Y>393261.923</Y>
</Points>
<Points>
<POINTID>8</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>8</NO>
<X>726788.538</X>
<Y>393279.113</Y>
</Points>
<Points>
<POINTID>9</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>9</NO>
<X>726786.874</X>
<Y>393279.667</Y>
</Points>

Polyline 2

<Points>
<POINTID>10</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>1</NO>
<X>726888.177</X>
<Y>393160.916</Y>
</Points>
<Points>
<POINTID>11</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>2</NO>
<X>726864.012</X>
<Y>393054.384</Y>
</Points>
<Points>
<POINTID>12</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>3</NO>
<X>726862.591</X>
<Y>393017.453</Y>
</Points>
<Points>
<POINTID>13</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>4</NO>
<X>726893.863</X>
<Y>392970.579</Y>
</Points>
<Points>
<POINTID>14</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>5</NO>
<X>726945.037</X>
<Y>392979.101</Y>
</Points>
<Points>
<POINTID>15</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>6</NO>
<X>726980.574</X>
<Y>393060.066</Y>
</Points>
<Points>
<POINTID>16</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>7</NO>
<X>726980.574</X>
<Y>393122.564</Y>
</Points>

Polyline 1

<Points>
<POINTID>17</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>1</NO>
<X>726681.101</X>
<Y>393321.967</Y>
</Points>
<Points>
<POINTID>18</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>2</NO>
<X>726525.376</X>
<Y>392958.877</Y>
</Points>
<Points>
<POINTID>19</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>3</NO>
<X>726951.931</X>
<Y>392819.053</Y>
</Points>
<Points>
<POINTID>20</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>4</NO>
<X>727069.289</X>
<Y>393107.721</Y>
</Points>
<Points>
<POINTID>21</POINTID>
<IMMOVABLEID>1</IMMOVABLEID>
<NO>5</NO>
<X>726999.325</X>
<Y>393436.983</Y>
</Points>

 

How can I modify the selection set to be in order of selected polyline. Thank you.

Ahags
0 Likes
Accepted solutions (2)
535 Views
5 Replies
Replies (5)
Message 2 of 6

CodeDing
Advisor
Advisor
Accepted solution

@bcddss ,

 

Here's a quick & easy & not-very-efficient fix to try...

 

Change this line:

(setq ename (vlax-ename->vla-object (ssname sset (setq i (1- i)))))

To this:

(setq ename (vlax-ename->vla-object (ssname sset (- (sslength sset) (1+ (setq i (1- i)))))))

 

Best,

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

If I understand correctly, try changing this much:

(progn
  (repeat 
    (setq i (sslength sset))
      (write-line "" file)
      (write-line (STRCAT "Polilinie " (ITOA I)) file)
      (write-line "" file)
      (setq ename (vlax-ename->vla-object (ssname sset (setq i (1- i)))))

to this:

(progn
  (setq i 0)
  (repeat (sslength sset)
    (write-line "" file)
    (write-line (STRCAT "Polilinie " (ITOA (setq i (1+ i)))) file)
    (write-line "" file)
    (setq ename (vlax-ename->vla-object (ssname sset (1- i))))

 

Kent Cooper, AIA
0 Likes
Message 4 of 6

bcddss
Enthusiast
Enthusiast

Thank you. I try 2 days to write something like this, but not working. You are the best!

Ahags
0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

"In direction of pick" depends on the direction pline has been drawn, but you can pick near an end and compare start and end points distance to the pick point, so reverse pline for direction or use (reverse lst) a lisp supported function, will do just that reverse a list of points.

 

I use this for line points

 

 

(setq plent (entsel "\nPick pline "))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(princ co-ord)

 

 

0 Likes
Message 6 of 6

bcddss
Enthusiast
Enthusiast

Hi. Thank you, but I don't want to reverse the polyline vertices. But appreciated the answer. The solution has been made by Kent. Thank you again 

Ahags
0 Likes