Hi All
I have been searching for a way of exporting multiple polyline or spline coordinates to txt file and all I can find is ones that write out as a single continuous list of coordinates with nothing denoting which one is which.
I really need it to be able to export each polyline as a group, and I would also love for it to be able to include the number of points and name of the layer eg:
polyline 'number of points' 'layername'
0.0 0.0 0.0
1.0 1.0 0.0
2.0 2.0 0.0
polyline 'number of points' 'layername'
0.0 0.0 0.0
1.0 4.0 0.0
2.0 8.0 0.0
and so on.....
Any help with this would be much appreciated
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
@yorke67 wrote:Hi All
I have been searching for a way of exporting multiple polyline or spline coordinates to txt file and all I can find is ones that write out as a single continuous list of coordinates with nothing denoting which one is which.
I really need it to be able to export each polyline as a group, and I would also love for it to be able to include the number of points and name of the layer eg:
polyline 'number of points' 'layername'
0.0 0.0 0.0
1.0 1.0 0.0
2.0 2.0 0.0
polyline 'number of points' 'layername'
0.0 0.0 0.0
1.0 4.0 0.0
2.0 8.0 0.0
and so on.....
Any help with this would be much appreciated
ff there are two or more polyline on the same layer will they be group together?
polyline 'number of points' 'layername1'
0.0 0.0 0.0
1.0 1.0 0.0
2.0 2.0 0.0
polyline 'number of points' 'layername2'
0.0 0.0 0.0
1.0 4.0 0.0
2.0 8.0 0.0
polyline 'number of points' 'layername2"
0.0 0.0 0.0
1.0 1.0 0.0
2.0 2.0 0.0
polyline 'number of points' 'layername3'
0.0 0.0 0.0
1.0 4.0 0.0
2.0 8.0 0.0
It matters wether to write the poitns to a file for every entity or collect all data/sort/then write.
will that be two decimal places? 2.00 or more 2.0000?
@pbejse wrote:write the points to a file for every entity or collect all data/sort/then write.will that be two decimal places? 2.00 or more 2.0000?
Anyhoo:
(defun c:epl ( / fn ss of data) (vl-load-com) (defun AT:GetVertices (e / p l) ;; Return point at each vertex of curve ;; e - curve to evaluate (Arc, Line, *Polyline, Spline) ;; Alan J. Thompson, 09.30.10 (if e (if (eq (setq p (vlax-curve-getEndParam e)) (fix p)) (repeat (setq p (1+ (fix p))) (setq l (cons (vlax-curve-getPointAtParam e (setq p (1- p))) l)) ) (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)) ) ) ) (defun _rtos (v) (rtos v 2 4)) (setq data nil fn (strcat (getvar 'Dwgprefix) (vl-filename-base (getvar 'Dwgname)) ".txt")) (if (setq ss (ssget '((0 . "*POLYLINE")))) (progn (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i)))) (setq data (cons (list (strcat (Itoa (length (setq p (AT:GetVertices e)))) " ") (cdr (assoc 8 (entget e))) (append (mapcar '(lambda (k) (strcat "\n" (_rtos (car k)) " " (_rtos (cadr k)) " " (_rtos (last k)))) p) (list "\n"))) data)) ) (setq of (open fn "w")) (foreach itm_ (vl-sort data '(lambda (l1 l2) (< (cadr l1) (cadr l2))) ) (princ (car itm_) of) (princ (cadr itm_) of) (foreach itm (last itm_) (princ itm of)) ) (close of) (princ (strcat "\n" (itoa (length data)) " Points Extracted ")) (startapp "Notepad" fn) ) (princ "\nNo Polylines Found:") ) (princ) )
We can sort it by number of points rather tahn layer name,
(lambda (l1 l2) (< (cadr l1) (cadr l2)))
to
(lambda (l1 l2) (< (atoi (car l1)) (atoi (car l2))))
precision from 4
(defun _rtos (v) (rtos v 2 4))
to
(defun _rtos (v) (rtos v 2 2))
HTH
Thank you Pbejse that's brilliant!!!
To answer your questions:
- They can be grouped either way as it doesn't affect the results, so long as each polyline is there.
- 2 decimal places is all I really need so I'll make the adjustment you mentioned thanks.
One thing I didn't think about though, is that the software I'm importing into uses flipped Y-Z coordinates, so is it possible to write out the coordinates : X Z Y as a simple way of getting around it? And it also requires a fixed value at the end, eg. 300.
Sorry I should have been more descriptive in my first post which would have been more helpful, I guess I was just checking if it was achievable at that stage.
Here is an example of the input required:
polyline 6 layername
[28915.3 0 11351.9 300]
[28775 0 18893.1 300]
[27149.8 0 19937.8 300]
[16340.3 0 19834.8 300]
[15175.2 0 18456 300]
[15125.7 0 13593.9 300]
Thanks again
@yorke67 wrote:Thank you Pbejse that's brilliant!!!
To answer your questions:
- They can be grouped either way as it doesn't affect the results, so long as each polyline is there.
- 2 decimal places is all I really need so I'll make the adjustment you mentioned thanks.
One thing I didn't think about though, is that the software I'm importing into uses flipped Y-Z coordinates, so is it possible to write out the coordinates : X Z Y as a simple way of getting around it? And it also requires a fixed value at the end, eg. 300.
Sorry I should have been more descriptive in my first post which would have been more helpful, I guess I was just checking if it was achievable at that stage.
Here is an example of the input required:
polyline 6 layername
[28915.3 0 11351.9 300]
[28775 0 18893.1 300]
[27149.8 0 19937.8 300]
[16340.3 0 19834.8 300]
[15175.2 0 18456 300]
[15125.7 0 13593.9 300]
Thanks again
But of course it can be done, but what of the last value <00 >? fix you say? constant that is.
and Z value as integer if 0 and real number with 2 decimals places if not?
and the square bracket "[" as litereral string?
(defun c:epl ( / fn ss i e of data) (vl-load-com) (defun AT:GetVertices (e / p l) ;; Return point at each vertex of curve ;; e - curve to evaluate (Arc, Line, *Polyline, Spline) ;; Alan J. Thompson, 09.30.10 (if e (if (eq (setq p (vlax-curve-getEndParam e)) (fix p)) (repeat (setq p (1+ (fix p))) (setq l (cons (vlax-curve-getPointAtParam e (setq p (1- p))) l)) ) (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)) ) ) ) (defun _rtos (v) (rtos v 2 2)) (setq data nil fn (strcat (getvar 'Dwgprefix) (vl-filename-base (getvar 'Dwgname)) ".txt")) (if (setq ss (ssget '((0 . "*POLYLINE")))) (progn (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i)))) (setq data (cons (list (cdr (assoc 0 (entget e))) (strcat " " (Itoa (length (setq p (AT:GetVertices e)))) " ") (cdr (assoc 8 (entget e))) (append (mapcar '(lambda (k) (strcat "\n[" (_rtos (car k)) " " (if (zerop (last k)) "0" (_rtos (last k))) " " (_rtos (cadr k)) " " "300" "]")) p) (list "\n"))) data)) ) (setq of (open fn "w")) (foreach itm_ (vl-sort data '(lambda (l1 l2) (< (caddr l1) (caddr l2))) ) (princ (car itm_) of) (princ (cadr itm_) of) (princ (caddr itm_) of) (foreach itm (last itm_) (princ itm of)) ) (close of) (princ (strcat "\n" (itoa (length data)) " Points Extracted ")) (startapp "Notepad" fn) ) (princ "\nNo Polylines Found:") ) (princ) )
HTH
That's fantastic!
The last value will almost always be 300 however I would like the abilitiy to change it if need be, which I assume I can just change within the comment "300". Also it would be good if we change the word "LWPOLYLINE" at the start to "spline" if possible? as it turns out it needs to read spline and doesnt like anything else. I looked through and couldn't find a comment "__" for it, so I assume it curently just outputs what type of object it is?
That's correct it can just be 0, or 2 decimal places if not 0.
And sorry not sure what 'literal string' means? but the brackets are correct.
Is it possible to get the spacing before them to match?
4 spaces before the "spline" and 8 spaces before the [ ...]
eg:
spline 2 layername
[28915.3 0 11351.9 300]
[28775 0 18893.1 300]
Thanks again for all your help!
@yorke67 wrote:That's fantastic!
Also it would be good if we change the word "LWPOLYLINE" at the start to "spline" if possible? as it turns out it needs to read spline and doesnt like anything else.
Thanks again for all your help!
So what if its not a Spline? do you want an option for that too? or it will constantly be "Spline" what ever type of pline it is?
BTW: the 300 suffix value, will it always ne a number?
Anyhooo..
i expect you would know what to change within the code to suit your needs, if not just holler
Cheers
See attached file
Thank you so much! it works perfectly!!!!!
I really need to learn how to write these because they make life so much easier.
From what I can tell it only likes the word spline no matter what type of pline it is, and also I like they way you added the option to adjust the 300 value, that may well come in handy some times.
Thanks again, you've really encouraged my intest in customisation.
Oh no, my cheating work around idea of switching the X Y Z for X Z Y has come up bad! I completely overlooked the fact that the flipped Y Z axis give different +/- values.
So I guess it really needs a command at the start that switches the UCS and then returns to 'previous UCS' at the end, and then just outputs the coordinates in normal X Y Z order. Oh why can't all software just use the same UCS system!
@yorke67 wrote:Oh no, my cheating work around idea of switching the X Y Z for X Z Y has come up bad! I completely overlooked the fact that the flipped Y Z axis give different +/- values.
So I guess it really needs a command at the start that switches the UCS and then returns to 'previous UCS' at the end, and then just outputs the coordinates in normal X Y Z order. Oh why can't all software just use the same UCS system!
Not sure what you mean. , attached a partial cad drawing here <2007 version>
Run the routine,Show me your desired result and the current result
Sorry for the confusion, I've attached a simple polyline drawing and here are the current and desired results:
Current Output:
Spline 2 0.1
[4700 0 0 300]
[0 0 0 300]
Spline 2 0.2
[0 0 4700 300]
[0 0 0 300]
Spline 3 0.3
[0 0 0 300]
[3348.98 0 983.58 300]
[4706.63 0 1959.82 300]
Spline 4 0.4
[0 0 0 300]
[2080.38 0 -1735.17 300]
[3895.84 0 -2268.65 300]
[4700 0 -3691.24 300]
Spline 3 0.5
[0 0 0 300]
[-2340.23 0 -1762.6 300]
[-4700 0 -2780.16 300]
Spline 4 0.6
[0 0 0 300]
[-1880.31 0 1545.99 300]
[-4017.27 0 1526.56 300]
[-4700 0 1933.89 300]
Desired Output:
Spline 2 0.1
[4700 0 0 300]
[0 0 0 300]
Spline 2 0.2
[0 0 -4700 300]
[0 0 0 300]
Spline 3 0.3
[0 0 0 300]
[3348.98 0 -983.58 300]
[4706.63 0 -1959.82 300]
Spline 4 0.4
[0 0 0 300]
[2080.38 0 1735.17 300]
[3895.84 0 2268.65 300]
[4700 0 3691.24 300]
Spline 3 0.5
[0 0 0 300]
[-2340.23 0 1762.6 300]
[-4700 0 2780.16 300]
Spline 4 0.6
[0 0 0 300]
[-1880.31 0 -1545.99 300]
[-4017.27 0 -1526.56 300]
[-4700 0 -1933.89 300]
I have also attached the same drawing with a rotated UCS to match the coordinate system of the software the results are being brought into, hopefully that will help explain it better.
@yorke67 wrote:
Desired Output:
Spline 2 0.1
[4700 0 0 300]
[0 0 0 300]
Spline 2 0.2
[0 0 -4700 300]
[0 0 0 300]
Spline 3 0.3
[0 0 0 300]
[3348.98 0 -983.58 300]
[4706.63 0 -1959.82 300]
Spline 4 0.4
[0 0 0 300]
[2080.38 0 1735.17 300]
[3895.84 0 2268.65 300]
[4700 0 3691.24 300]
Spline 3 0.5
[0 0 0 300]
[-2340.23 0 1762.6 300]
[-4700 0 2780.16 300]
Spline 4 0.6
[0 0 0 300]
[-1880.31 0 -1545.99 300]
[-4017.27 0 -1526.56 300]
[-4700 0 -1933.89 300]
I have also attached the same drawing with a rotated UCS to match the coordinate system of the software the results are being brought into, hopefully that will help explain it better.
Trans and UCS
While were at it:
Trans Lesson <---- fresh off the press 😉
Thank you so much for all your help, it works fantastically!!!