Hi,
Early this year Lee_Mac presented at Exporting list of objects message the following code:
;; ExportPline - Lee Mac - www.lee-mac.com (defun c:ExportPline ( / f i o s ) (if (and (setq s (ssget '((0 . "LWPOLYLINE")))) (setq f (getfiled "Create Output File" "" "txt" 1)) (setq f (open f "w")) ) (progn (repeat (setq i (sslength s)) (setq o (vlax-ename->vla-object (ssname s (setq i (1- i))))) (write-line (apply 'strcat (vl-list* (itoa (vla-get-objectid o)) "\t" (rtos (vla-get-constantwidth o)) "\t" ( (lambda ( a ) (a (vlax-get o 'coordinates))) (lambda ( b ) (if b (cons (strcat (rtos (car b)) "," (rtos (cadr b)) "\t") (a (cddr b)) ) ) ) ) ) ) f ) ) (close f) ) ) (princ) ) (vl-load-com) (princ)
This function exports the following items from a selection of plines:
- ObjectID;
- Start Point;
- End Point;
- Vertex Points;
- and Width.
Now I need something similar that acts like this:
- I call the funtion;
- It asks me to select a pline;
- It asks me to select a text;
- It asks me for a filename to export to;
- it writes on the file the selected text;
- It writes on the file the start, mid and final points (i.e. vertexes) of the pline as the routine above.
Thanks in advance.
Solved! Go to Solution.
Solved by aabfm. Go to Solution.
@aabfm wrote:....
Now I need something similar that acts like this:
....
- It writes on the file the start, mid and final points (i.e. vertexes) of the pline as the routine above.
....
Shouldn't be difficult [add a few elements, take out a few], but first, a question:
What do you mean by the "mid" point of a Polyline? Will there always be a vertex that is the middle one? If there might not be [e.g. an open Polyline with 4 vertices or a closed one with 3], what point would you want for the middle? The nearest vertex to halfway? If two are equidistant from there, which one? The always-rounded-up or -rounded-down vertex from halfway, even if another vertex might be closer? Or if you might not always want an actual vertex location, the actual mid-point of the overall length, wherever that falls in relation to vertices? The midpoint of the Polyline segment between the two vertices that split the middle count-wise, regardless of where that falls in relation to the overall length? Etc.
Actualy I just want something that simply returns all the vertex from that pline and afterwards some selected text.
I'm trying to edit the code like this...
(Still haven't finished/tested yet)
(defun c:zi1 ( / f i o s OBJ) (if (and (setq s (ssget '((0 . "LWPOLYLINE")))) (setq f (getfiled "Create Output File" "" "txt" 1)) (setq f (open f "w")) ) (progn (repeat (setq i (sslength s)) (setq o (vlax-ename->vla-object (ssname s (setq i (1- i))))) (princ (apply 'strcat (vl-list* ( (lambda ( a ) (a (vlax-get o 'coordinates))) (lambda ( b ) (if b (cons (strcat "+"(rtos (car b)) "," (rtos (cadr b)) "\t") (a (cddr b)) ) ) ) ) "\t"gostei da li ) ) f ) ) (prompt "n\Select text to export... ") (setq OBJ (ENTSEL)) (setq OBJDATA (entget (CAR OBJ))) (setq TXT (cdr (ASSOC 1 OBJDATA))) (write-line TXT F) (close f) ) ) (princ) ) (vl-load-com) (princ)
I've tried this but without any success
(defun c:zi1 ( / f i o s OBJ OBJDATA TXT nomebase) (setq nomebase (getstring "\nInsira nome base:")) (setq f (strcat "d:\" nomebase "_zi.txt")) (prompt "n\Seleccione o nome da ZI... ") (setq OBJ (ENTSEL)) (setq OBJDATA (entget (CAR OBJ))) (setq TXT (cdr (ASSOC 1 OBJDATA))) (if (and (setq s (ssget '((0 . "LWPOLYLINE")))) (setq f (getfiled "Create Output File" "" "txt" 1)) (setq f (open f "w")) ) (progn (repeat (setq i (sslength s)) (setq o (vlax-ename->vla-object (ssname s (setq i (1- i))))) (princ (apply 'strcat "\n" (vl-list* ( (lambda ( a ) (a (vlax-get o 'coordinates))) (lambda ( b ) (if b (cons (strcat "+"(rtos (car b)) "," (rtos (cadr b)) "\t") (a (cddr b)) ) ) ) ) ) ) f ) (princ TXT f) ) (close f) ) ) (princ) ) (vl-load-com) (princ)
Any idea?...
Just got the solution:
(defun c:zi2 ( / f i o s obj objdata texto texto_f nomebase nome_zi) (setq nomebase (getstring "\nType filename:")) (setq nome_zi (strcat nomebase "_zi.txt")) (setq obj (entsel "\nSelect text to export: ")) (setq objdata (entget (car obj))) (setq texto (cdr (assoc 1 objdata))) (if (and (setq s (ssget '((0 . "LWPOLYLINE")))) (setq f (open nome_zi "w")) ) (progn (repeat (setq i (sslength s)) (setq o (vlax-ename->vla-object (ssname s (setq i (1- i))))) (princ (apply 'strcat (vl-list* "\n" ( (lambda ( a ) (a (vlax-get o 'coordinates))) (lambda ( b ) (if b (cons (strcat "+"(rtos (car b)) "," (rtos (cadr b)) "\t") (a (cddr b)) ) ) ) ) ) ) f ) ) (setq texto_f (strcat "\n=" texto)) (princ texto_f f) (close f) ) ) (princ) ) (vl-load-com) (princ)