Jump to content

Recommended Posts

Posted

Hello, I am searching for a lisp that can export the lengths of all selected polylines and export them to either Excel or an AutoCad table.

 

I have found and tested around 20 lisps but so far cannot find the right one.

There were only 2 that look promising, maybe they could be modified?

One was by Lee Mac and the other Jimmy Bergmark. I can post the 2 Lisp if needed.

 

The lisp would need to have you select multiple polylines and give the total lengths of each polyline in the order that they were selected in. Then the data would either appear on an AutoCad table or Excel.

 

Thanks for any help that can be provided.

Posted

The lengths of each individual polyline or the total length?

Posted
The lengths of each individual polyline or the total length?

 

The lengths of each individual polyline.

Total is really not needed or can be added at the end of the table or excel if it is not to much trouble.

Posted

Try this program to export LWpolylines to Excel file with format csv.

 

(defun c:Test (/ s f o)
 ;; Tharwat 26. 08. 2015 ;
 (princ "\nSelect LWpolylines to export to Excel file :")
 (if (and (setq s (ssget '((0 . "LWPOLYLINE"))))
          (setq f (getfiled "Specify File Name" (getvar 'DWGPREFIX) "csv" 1))
          (setq o (open f "w"))
          )
   (progn
     ((lambda (r / e)
        (while (setq e (ssname s (setq r (1+ r))))
          (write-line (rtos (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) 2 4) o)
          ))
       -1)
     (close o)
     )
   )           
 (princ)
)

  • Like 1
Posted
Try this program to export LWpolylines to Excel file with format csv.

 

 

Looks good so far. I do have a few tweaks if possible.

Is there a way to have the values show up in feet only?

Is there a also a way to have it load up excel without having to save location first and then open?

Posted (edited)

Is there a way to have the values show up in feet only?

Is there a also a way to have it load up excel without having to save location first and then open?

 

Add the complete path of the Excel file and be aware that each time you run the program , the new data would replace the old once .

 

(defun c:Test (/ s f o)
 ;; Tharwat 26. 08. 2015 ;
 (princ "\nSelect LWpolylines to export to Excel file :")
 (if (and (setq s (ssget '((0 . "LWPOLYLINE"))))
          (setq f [color="red"]"C:\\New Folder\\Example.csv"[/color]) ;; [color="silver"]path of Excel path[/color]
          (setq o (open f "w"))
          )
   (progn
     ((lambda (r / e)
        (while (setq e (ssname s (setq r (1+ r))))
         (write-line (rtos (cvunit (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) "mm" "feet") 2 4) o)
          ))
       -1)
     (close o)
     )
   )           
 (princ)
)

Edited by Tharwat
Posted
Add the complete path of the Excel file and be aware that each time you run the program , the new data would replace the old once .

 

I could only get it to save to my thumb drive. It would not save to the local drive C:. Any idea of why this would be? Maybe trust issues? Does it have to save at all or can it just open excel?

Also, could you have the values show up in feet?

 

Thanks for all your help!

Posted
I could only get it to save to my thumb drive. It would not save to the local drive C:. Any idea of why this would be? Maybe trust issues? Does it have to save at all or can it just open excel?

 

Yeah , it might be a matte of security issue , anyway right click on the folder that you wan to safe the excel file in , then go to properties then from the show up dialog go to security tab and edit the group / user name to have a full access.

 

Also, could you have the values show up in feet?

 

If the program did not change the value to feet format from the latest posted program , and replace the number 3 to 4 and try again.

Posted
Yeah , it might be a matte of security issue , anyway right click on the folder that you wan to safe the excel file in , then go to properties then from the show up dialog go to security tab and edit the group / user name to have a full access.

 

If the program did not change the value to feet format from the latest posted program , and replace the number 3 to 4 and try again.

 

It is still not showing up in feet. Do you have any other ideas to get it to feet?

Posted
Add the complete path of the Excel file and be aware that each time you run the program , the new data would replace the old once .

 

(defun c:Test (/ s f o)
 ;; Tharwat 26. 08. 2015 ;
 (princ "\nSelect LWpolylines to export to Excel file :")
 (if (and (setq s (ssget '((0 . "LWPOLYLINE"))))
          (setq f [color="red"]"C:\\New Folder\\Example.csv"[/color]) ;; [color="silver"]path of Excel path[/color]
          (setq o (open f "w"))
          )
   (progn
     ((lambda (r / e)
        (while (setq e (ssname s (setq r (1+ r))))
         (write-line (rtos (cvunit (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) "inch" "feet") 2 4) o)
          ))
       -1)
     (close o)
     )
   )           
 (princ)
)

 

Awww, ok. That is much better, I had to change the "mm" to "inch" and that cleared it up.

One more thing, is there a way to have it open the excel file automatically without having it save anywhere? Or possibly export the data into an autocad table instead of excel?

Posted

Here is a table version, works for me as metric may need mods for inches re row sizes etc. Will only work in modelspace see curspace.

 

Tharwat stuffed up lambda please help any other suggestions welcome.

 

(defun c:Test (/ s x y doc objtable numrows rowheight pt1 colwidth curspace)
;; Tharwat 26. 08. 2015 ;
;; mods by BIGAL 29.08.2015 now as table

(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq curspace (vla-get-modelspace doc))
(setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table:  "))) 
(princ "\nSelect LWpolylines to export to a Table :")
(setq s (ssget '((0 . "LWPOLYLINE"))))
(if (/= s nil)
   (progn
 ; now do table 
   (setq numrows (+ 2 (sslength s)))
   (setq numcolumns 2)
   (setq rowheight 7)
   (setq colwidth 25)
   (setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth))
   (vla-settext objtable 0 0 "Pline lengths")
   (vla-setcolumnwidth objtable 0 10)
   (vla-setcolumnwidth objtable 1 25)
   (vla-settext objtable 1 0 "Pline") 
   (vla-settext objtable 1 1 "Length") 
   (vla-SetTextHeight Objtable (+ acDataRow acHeaderRow acTitleRow) 2.5)
   (vla-SetAlignment Objtable acDataRow acMiddleCenter)

   (setq x 1)
   (SETQ Y 2)
   (setq r -1)
   ;((lambda (r / e)
        (while (setq e (vlax-ename->vla-object(ssname s (setq r (1+ r)))))
        (vla-settext objtable Y 0 (rtos x 2 0))        
        (vla-settext objtable Y 1 (rtos (cvunit (vla-get-length e) "inch" "feet") 2 4))
        (setq x (1+ x ))
        (setq y (1+ Y ))
 ); while
    ; )) ;lambda
     )   ;progn
   (alert "You have not picked any plines run again")
   )     ; if      
 (princ)

) ; defun
(c:test)

  • Like 1
Posted
Here is a table version, works for me as metric may need mods for inches re row sizes etc. Will only work in modelspace see curspace.

 

Tharwat stuffed up lambda please help any other suggestions welcome.

 

 

Thanks, it worked great! Thanks Tharwat and BIGAL.

Posted
Here is a table version, works for me as metric may need mods for inches re row sizes etc. Will only work in modelspace see curspace.

 

Tharwat stuffed up lambda please help any other suggestions welcome.

 

 

 

BIGAL, I was testing the lisp and came across 3 issues. If you have time can you check them out below?

 

1.) When the lisp loads it wants to run immediately. Is there a way to have it only run when you enter the command for it?

 

2.) Is there a way to change the format of the table to have zero precision and show the length in feet. Example = 42'

 

3.) Is there a way to edit the text font and size the table uses?

Posted

1 remove last line (c:test)

2 rtos ... 2 0

3 vla-SetTextHeight ..... 2.5 change this & rowheight 7. mm settings

  • Like 1
  • 2 years later...
Posted (edited)

Hi, i have the following code

 

 

(defun c:Test (/ s x y doc objtable numrows rowheight pt1 colwidth curspace)
;; Tharwat 26. 08. 2015 ;
;; mods by BIGAL 29.08.2015 now as table

(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq curspace (vla-get-modelspace doc))
(setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table: "))) 
(princ "\nSelect LWpolylines to export to a Table :")
(setq s (ssget '((0 . "LWPOLYLINE"))))
(if (/= s nil)
(progn
; now do table 
(setq numrows (+ 2 (sslength s)))
(setq numcolumns 2)
(setq rowheight 7)
(setq colwidth 25)
(setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth))
(vla-settext objtable 0 0 "Pline lengths")
(vla-setcolumnwidth objtable 0 10)
(vla-setcolumnwidth objtable 1 25)
(vla-settext objtable 1 0 "Pline") 
(vla-settext objtable 1 1 "Length") 
(vla-SetTextHeight Objtable (+ acDataRow acHeaderRow acTitleRow) 2.5)
(vla-SetAlignment Objtable acDataRow acMiddleCenter)

(setq x 1)
(SETQ Y 2)
(setq r -1)
;((lambda (r / e)
(while (setq e (vlax-ename->vla-object(ssname s (setq r (1+ r)))))
(vla-settext objtable Y 0 (rtos x 2 0)) 
(vla-settext objtable Y 1 (rtos (cvunit (vla-get-length e) "inch" "feet") 2 4))
(setq x (1+ x ))
(setq y (1+ Y ))
); while
; )) ;lambda
) ;progn
(alert "You have not picked any plines run again")
) ; if 
(princ)

) ; defun
(c:test)

 

 

This code is used to extract the polyline length in autocad table.

I want to additionally add layers and polyline length in meter.

How can i add that please give some ideas...

Edited by SLW210
Added Code Tags
Posted

Not to hard look for matching lines in code above in most cases its add to the number an extra 1.

 

(setq numcolumns 3)
............
(vla-setcolumnwidth objtable 2 25)
.......
(vla-settext objtable 1 2 "Layer") 
........
(vla-settext objtable Y 1 (rtos (vla-get-length e) 2 3))
(vla-settext objtable Y 2 (vla-get-layer e) )

Posted
Hi, i have the following code

 

(defun c:Test (/ s x y doc objtable numrows rowheight pt1 colwidth curspace)

;; Tharwat 26. 08. 2015 ;

;; mods by BIGAL 29.08.2015 now as table

 

 

hi welcome, friendly msg , the code should be included in code tags

 

before

[NOPARSE]

your code here

[/NOPARSE]

 

after

your code here

Posted

Hi Bigal

 

Thank you for your quick reply & its worked awsome...

Once again thank you so much...

Posted

Next time i will do correctly...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...