list automation

list automation

Anonymous
Not applicable
1,450 Views
27 Replies
Message 1 of 28

list automation

Anonymous
Not applicable

Dear Sirs,

 

I'm now starting to learn how to code lisps.

 

I need to create a process to read a polyline or 3dpolyline nodes coordinates and export them to a .xls file. I can do it using LIST command, but as i have a large number of examples i would like to optimize my work with a lisp.

 

Second Step:

 

Write the coordinates in this format:

 

poly[0][0] :=VEC(-10.3545,-1.9963,0);
poly[0][1] :=VEC(-10.3488,-1.8242,0);
poly[0][2] :=VEC(-10.3258,-1.6521,0);

.

.

.

 

 

 

 

 

 

0 Likes
Accepted solutions (2)
1,451 Views
27 Replies
Replies (27)
Message 2 of 28

Sea-Haven
Mentor
Mentor

Any of the pline get co-ordinates lisp out there will do what you want, did you google ? There are so many examples look for a answer with write to CSV.

0 Likes
Message 3 of 28

pbejse
Mentor
Mentor
Accepted solution

As suggested by @Sea-Haven 

(defun c:ToCSV ( / AT:GetVertices CoordFileData _rtos i inc pts CoordList ss)
(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 (s)(rtos s 2 4))
(if (and
      (setq ss (ssget '((0 . "*POLYLINE"))))      
      (setq CoordFileData
	       (getfiled "Enter Input Filename"
					 (strcat (getvar 'dwgprefix)
				 (vl-filename-base (getvar 'dwgname)) ".csv") "csv" 1)
	       )
      )
  (progn
    (setq i 0 opf (open CoordFileData "w"))
	  (repeat (sslength ss)
	    (setq pts (AT:GetVertices (ssname ss 0)) inc -1)
		(mapcar '(lambda (v)  
			(write-line
			  (strcat  "poly[" (itoa i) "][" (itoa (setq inc (1+ inc))) "] :=VEC("
		     		(_rtos (car v)) "," (_rtos (cadr v)) "," (_rtos (caddr v)) ")") opf)
		  		 ) pts)
	    (ssdel (ssname ss 0) ss)
	    (setq i (1+ i))
	    )
	    (Close opf)
	    (startapp "explorer" CoordFileData)
    	)
  )
(princ)
  )

Command: Tocsv

poly[0][0] :=VEC(2948.9594,1434.6542,50)
poly[0][1] :=VEC(3451.3304,1846.2241,0)
poly[0][2] :=VEC(3731.9653,1448.4885,65)
poly[1][0] :=VEC(3908.9104,1790.9503,0)
poly[1][1] :=VEC(4359.0421,2282.2788,0)
poly[1][2] :=VEC(5120.8035,1728.6692,0)
poly[1][3] :=VEC(5962.2036,2219.9977,0)

HTH

 

0 Likes
Message 4 of 28

Anonymous
Not applicable

Perfect. Thank you.

 

 

0 Likes
Message 5 of 28

pbejse
Mentor
Mentor

@Anonymous wrote:

Perfect. Thank you.


Good to know that it helps.

Cheers

 

 

0 Likes
Message 6 of 28

Anonymous
Not applicable

Sorry, i'm a noob on this subjet.

 

I need de special carater ; in the end of each line.

 

I guess that i must put it here, but it don't work:

 

......(strcat "poly[" (itoa i) "][" (itoa (setq inc (1+ inc))) "] :=VEC("
(_rtos (car v)) "," (_rtos (cadr v)) "," (_rtos (caddr v)) ");") opf).....

0 Likes
Message 7 of 28

pbejse
Mentor
Mentor

@Anonymous wrote:

I guess that i must put it here, but it don't work:


I dont see any obvious reason why it should'nt work with that additional character,

Can you tell me what "but it dont work"  actually means?  in what way? 

 

0 Likes
Message 8 of 28

Anonymous
Not applicable

The special character ; does not appear on the excel. I'm sure that the problem is mine because any change i make on any field it has no effect on the final result. 

 

I already deleted the .lsp file, loaded it again...

0 Likes
Message 9 of 28

ВeekeeCZ
Consultant
Consultant
Accepted solution

it's in conflict with the csv definition - semicolons are column delimiters. you need to wrap the entire cell content into quotes.

 

(strcat  "\"poly[" (itoa i) "][" (itoa (setq inc (1+ inc))) "] :=VEC("
	 (_rtos (car v)) "," (_rtos (cadr v)) "," (_rtos (caddr v)) ");\"") opf)

 

Message 10 of 28

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

..... (_rtos (car v)) "," (_rtos (cadr v)) "," (_rtos (caddr v)) ");") opf).....


Stab-in-the-dark here....  Does it work if you do it this way?

..... (_rtos (car v)) "," (_rtos (cadr v)) "," (_rtos (caddr v)) ")" (chr 59)) opf).....

Kent Cooper, AIA
Message 11 of 28

pbejse
Mentor
Mentor

@Anonymous wrote:

The special character ; does not appear on the excel. I'm sure that the problem is mine because any change i make on any field it has no effect on the final result. 

 


I'm guessing your PC's default dilimeter for Excel file is set to ";"  I dont have that problem since  i had it mine set to none. I had that issue with one request not long ago

 

Short of changing the settings on your or in any other PC for that matter, we can just write directly to "Xlsx" file.

 

Command:ToXls

Data exported as C:\Download\Some|RandomGuy.xlsx

 

Is it just me? For some reason, I cannot attach any file as the option for dragging files into the conversation is gone. and i keep get an error message in RED not long after i sign in.  

 

pbejse_0-1628250334182.png

 

I'll post the code later then.

 

HTH

 

EDIT: Guess i dont need to post the code anymore @Anonymous  We have two great solutions for the missing character from @ВeekeeCZ and @Kent1Cooper .

 

0 Likes
Message 12 of 28

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

you need to wrap the entire cell content into quotes.


That actually works ! I did not know that.

Good one @ВeekeeCZ 

 

 

0 Likes
Message 13 of 28

pbejse
Mentor
Mentor

@Kent1Cooper wrote:

Stab-in-the-dark here....  Does it work if you do it this way?

..... (_rtos (car v)) "," (_rtos (cadr v)) "," (_rtos (caddr v)) ")" (chr 59)) opf).....


 

It does work @Kent1Cooper , and there's me thinking maybe a unicode string would work.

Good find.

 

BTW: I can see you signature now, you may give @john.uhden a heads up, John's still coming up as "not found" 😊

0 Likes
Message 14 of 28

ВeekeeCZ
Consultant
Consultant

CSV fun test

 

"CellA1,;Line1
CellA1,;Line2";"CellB1,;Line1
CellB1,;Line2"
"CellA2,;Line1
CellA2,;Line2";"CellB2,;Line1
CellB2,;Line2"

 

Z9E3zK5E_0-1628251063814.png

 

0 Likes
Message 15 of 28

ВeekeeCZ
Consultant
Consultant

@pbejse wrote:

@Kent1Cooper wrote:

Stab-in-the-dark here....  Does it work if you do it this way?

..... (_rtos (car v)) "," (_rtos (cadr v)) "," (_rtos (caddr v)) ")" (chr 59)) opf).....


 

It does work @Kent1Cooper , ...

 


 

It does not here. We Europeans need quotes.

0 Likes
Message 16 of 28

pbejse
Mentor
Mentor

@Anonymous wrote:

The special character ; does not appear on the excel. I'm sure that the problem is mine because any change i make on any field it has no effect on the final result. 


 

Another way is. following the "wrapping with quotes" approach

(vl-prin1-to-string
  (strcat  "poly[" (itoa i) "][" (itoa (setq inc (1+ inc))) "] :=VEC("
	(_rtos (car v)) "," (_rtos (cadr v)) "," (_rtos (caddr v)) ");"  ))

HTH

 

0 Likes
Message 17 of 28

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

..It does not here. We Europeans need quotes.


There's always something with you Europeans 

 

Lol.png

 

0 Likes
Message 18 of 28

Anonymous
Not applicable

Perfect. thank you

0 Likes
Message 19 of 28

ВeekeeCZ
Consultant
Consultant

@pbejse wrote:

@ВeekeeCZ wrote:

..It does not here. We Europeans need quotes.


There's always something with you Europeans 

 

Lol.png

 


 

Yes, that's the thing. Not clear to me why we use *.csv, call it comma-separated... if we actually use semicolons?! I'll be perfectly happy with *.ssv.

0 Likes
Message 20 of 28

Anonymous
Not applicable

Hi again,

 

Can you please tell me if there is a way to list the points in inverse order, in other words, the list of the points is written in counter clockwise, now i would like to create another list in clockwise. Outer line is always counter clockwise, inner line is always clockwise.

 

fft_0-1628499129260.png

 

0 Likes