Hallo zusammen,
nach langer Suche der verzweifelte Versuch hier zum Ziel zu kommen (leider bin ich selbst nicht der LISP-Programmierung mächtig ).
Folgende Aufgabe ist zu bewältigen:
1.Koordinaten der Eckpunkte einer markierten Polylinie (ohne Berücksichtigung von Kurven)
in die Zwischenablage schreiben
X-Wert Tab Y-Wert Zeilenumbruch {1. Punkt}
X-Wert Tab Y-Wert Zeilenumbruch {2. Punkt}
2.Aus Koordinaten (Form s.o.) in der Zwischenablage eine Polylinie im aktuellen Layer
erstellen.
Hierzu habe ich bereits separate LISP´s für Teilaufgaben gefunden, bin aber nicht in der Lage diese zusammen zu führen.
Evtl. wurde ein ähnliches Problem schon gelöst oder jemand hat eine Idee. Wäre mega.
Vielen Dank für eure Unterstützung.
Viele Grüße,
CK
Hier mal die gefundenen lisp-Routinen:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; www.cad-huebner.de erstellt von Udo Hübner ;;
;; Achtung folgende Verbesserungen müssen geprüft bzw. eingearbeitet werden ;;
;; Prüfung auf locked Layers, und evt. Behandlung von Gruppen wie text + wipeout ;;
;; 15.09.98 ansonsten von 1.0 auf 1.1 nur windows umlaute eingesetzt. ;;
;; Update 01.03.2004 - nur Kommentare eingepflegt ;;
;; Die Textbeschriftung erfolgt rechts oberhalb vom Punkt, der Versatz beträgt ;;
;; 75% der Texthöhe ;;
;; Es ist keine Error-Routine eingebaut. ;;
;; das Abschalten des permanenten Objektfangs zu Laufzeit wäre sinnvoll, ;;
;; der neugesetzte Text nicht auf ein naheliegendes Objekt einrastet ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(DEFUN C:Z2TXT ( / ANZAW1 ANZH AW1 ENTINSERT EPKT I TEMP Z)
(PROMPT
(STRCAT "\nZ2TXT.lsp - Objekte mit Höhentext/Z-Koordinate) versehen - V1.2 1999-2004"
"\n(c) Ing.- Büro Hübner, info@CAD-Huebner.de"
"\nTEXTSIZE = " (RTOS (GETVAR "TEXTSIZE"))
) ;_ Ende von STRCAT
) ;_ Ende von PROMPT
(SETQ AW1 (SSGET) ; Objekte wählen
Anzaw1 (SSLENGTH AW1) ; Anzahl der Objekte in AW1
AnzH 0 ; Anzahl der geänderten Elemente
I 0 ; Zähler
) ;_ Ende von SETQ
(INITGET 6)
(Prompt "\nAugenblick, ich ich prüfe Objekte...")
(while (> Anzaw1 0)
(setq temp (ssname AW1 (setq AnzAw1 (1- AnzAW1)))
entinsert (entget temp)
epkt (cdr (assoc 10 entinsert))
z (RTOS (NTH 2 epkt) 2 2)
) ;_ Ende von setq
(PRINC ".")
(COMMAND "_MTEXT"
(LIST (+ (* 0.75 (GETVAR "TEXTSIZE")) (NTH 0 epkt))
(+ (* 0.75 (GETVAR "TEXTSIZE")) (NTH 1 epkt))
0.0
) ;_ Ende von LIST
"_justif"
"_ML" ; Positionierung Mitte zentriert
"_WID"
10.0 ; konstante Textfeldbreite - ist einfacher zu picken
z
""
) ;_ Ende von COMMAND
) ; ende while
(princ " Objekte beschriftet. ")
(princ "Z2TXT beendet.")
(PRIN1)
) ; ende defun
;--------------------------------------------------------------------
(PROMPT "\nZ2TXT.lsp geladen. Start mit Z2TXT")
(PRIN1)
-----------------------------------------------------------------------------------------------------------
ACAD LISP - Versuch, LISP-Routinen zu finden, mit denen eine Polylinie aus Wertepaaren in der Zwischenablage erstellt wird bzw. Wertepaare einer Polylinie in die Zwischenablage eingefügt werden
Beispiel für Export Polylinie in Textdatei
-----------------------------------------------------------------------------------------------------------
(defun c line_to_file (/ theobj thelist n xval yval fname fn)
(vl-load-com)
(setq theobj (car (entsel "\nPolylinie auswählen: ")))
(setq theobj (vlax-ename->vla-object theobj))
(if (= (vlax-get-property theobj 'ObjectName) "AcDbPolyline")
(progn
(setq thelist (vlax-get-property theobj 'coordinates))
(setq thelist (vlax-safearray->list (variant-value thelist)))
(setq n 0)
(setq fname "D:/pline_to_file.txt")
(setq fn (open fname "w"))
(repeat (/ (length thelist) 2)
(setq xval (rtos (nth n thelist)))
(setq n (1+ n))
(setq yval (rtos (nth n thelist)))
(write-line (strcat xval "," yval) fn)
(setq n (1+ n))
)
(close fn)
(Princ
"\nDatei \"Punktkoordinaten.txt\" auf dem Laufwerk D abgespeichert."
)
)
(alert "Das ist keine Polylinie !")
)
(princ)
)
(princ)
----------------------------------------------------------------------------------
Beispiel für Export Polylinie in Textdateidurch Anhängen der Daten
----------------------------------------------------------------------------------
(defun c line_to_file (/ wa thePL antw)
(initget "Anhängen Neu")
(setq antw (getkword "\nDaten an vorhandene Datei [Anhängen/Neu]<N>: ")
wa (if (= antw "Anhängen")
"a"
"w")
)
(setq thePL (car (entsel "\nPolylinie auswählen: "))
thePL (if (and thePL
(= (vlax-get-property (setq thePL (vlax-ename->vla-object thePL)) 'ObjectName) "AcDbPolyline"))
thePL
)
)
(while thePL
(pline_to_file wa thePL)
(setq wa "a")
(setq thePL (car (entsel "\nPolylinie auswählen: "))
thePL (if (and thePL
(= (vlax-get-property (setq thePL (vlax-ename->vla-object thePL)) 'ObjectName) "AcDbPolyline"))
thePL
)
)
)
(princ)
)
(defun pline_to_file (sa theobj / thelist fname fn)
(setq thelist (vlax-get-property theobj 'coordinates)
thelist (vlax-safearray->list (variant-value thelist))
fname "C:/pline_to_file.txt"
fn (open fname sa)
)
(write-line "NEWLINE" fn)
(write-line (substr (apply 'strcat
(mapcar '(lambda (E)
(strcat","(rtos E))
)
thelist)
)
2)
fn)
(close fn)
(Princ
"\nDatei \"Punktkoordinaten.txt\" auf dem Laufwerk C abgespeichert."
)
)
(vl-load-com)
-----------------------------------------------------------------------------------------------------------
Lisp to draw polyline from xls, csv or txt file?
4176 Views, 7 Replies 10-15-2008 06:05 AM
Greetings!
I did a search for this, but didn't find anything that resembled what I needed.
I am looking for a lisp routine that would draw a polyline using the data from a xls, csv or txt file. Here is a sample clip from the csv or txt file:
1955373.01,113249.903
1955397.07,112794.949
1955349.88,112381.173
1955164.02,112070.843
1954880.94,111755.906
1954556.00,111473.025
1954197.84,111229.825
1953858.95,111054.971
where the first line is the starting point - the string of numbers before the comma represents "x" and the string after the comma represents "y", then the second line is the next point on the polyline, etc.
I know this is possible and should be a simple request. Problem is I am not a lsp writer.
Any of you GURU's what to give it a try?
Thanks,
Bradley Edited by: papabradley on Oct 15, 2008 8:05 AM
Re: Lisp to draw polyline from xls, csv or txt file?
10-15-2008 08:47 AM in reply to: papabradley
papabradley,
Here's a simple lisp to import your x,y values from a .csv file format....
-----------------------------------------------------------------------------------------------------------
;; poly_from_csv.lsp
(defun C:GO ( / CSV_name ifil Field x i c px py px_lst py_lst p_lst p1 p2 )
(command "_limits" "off")
;; Browse box to pick the .csv file
(setq CSV_name "")
(setq CSV_name (getfiled "Select Point List .csv file" "" "csv" 2))
;; Read-in the values to X & Y lists
(setq ifil (open CSV_name "r")); open the file
(while (setq rd-line (read-line ifil))
(setq x (strlen rd-line))
(setq i 1 Field 1 Px "" Py "")
(repeat x
(setq c (substr rd-line i 1)); read a character
(if (or (= c ",")(= c " "))
(progn
(setq Field (+ Field 1))
(setq c "")
); end progn
); end if
(if (and (/= c "")(= Field 1))
(setq Px (strcat Px c)); stack first point
); end if
(if (and (/= c "")(= Field 2))
(setq Py (strcat Py c)); stack second point
); end if
(setq i (+ i 1))
); end repeat
(if Px
(progn
(setq Px_lst (cons Px Px_lst))
(setq Py_lst (cons Py Py_lst))
); progn
); if
); while
(close ifil)
;; Draw the Polyline
(if (and (> (length Px_lst) 1)(> (length Py_lst) 1))
(progn
(setq Px_lst (reverse Px_lst))
(setq Py_lst (reverse Py_lst))
(setq C 0)
(repeat (length Px_lst)
(setq Px (atof (nth C Px_lst)))
(setq Py (atof (nth C Py_lst)))
(setq P_lst (cons (list Px Py 0.0) P_lst))
(setq C (+ C 1))
); repeat
(setq P_lst (reverse P_lst))
(setq P1 (nth 0 P_lst)); start point
(setvar "lastpoint" P1)
(setq P_lst (cdr P_lst)); strip 1st point
(setq C 1)
(repeat (length P_lst)
(setq P1 (getvar "lastpoint"))
(setq P2 (nth C P_lst))
(if (and (/= P1 nil)(/= P2 nil))
(command "_pline" P1 "_W" "0.50" "0.50" P2 ""); width as desired
); if
(setq C (+ C 1))
); repeat
); end progn
); end if
;; Exit
(princ)
); function GO
(princ); silent load
-----------------------------------------------------------------------------------------------------------
Copy to the clipboard via lisp
« Reply #2 on: March 06, 2008, 11:16:30 am »
Hi
An example
-----------------------------------------------------------------------------------------------------------
(defun GetClipText(/ html result)
(setq html (vlax-create-object "htmlfile")
result (vlax-invoke (vlax-get (vlax-get html 'ParentWindow) 'ClipBoardData) 'GetData "Text")
)
(vlax-release-object html)
result
)
----------------------------------------------------------------------------------
« Reply #4 on: March 07, 2008, 10:19:28 am »
----------------------------------------------------------------------------------
;;copy str to the clipboard
(defun setClipText(str / html result)
(if (= 'STR (type str))
(progn
(setq html (vlax-create-object "htmlfile")
result (vlax-invoke (vlax-get (vlax-get html 'ParentWindow) 'ClipBoardData) 'setData "Text" str)
)
(vlax-release-object html)
str
)
);end if
)
-----------------------------------------------------------------------------------------------------------
« Reply #7 on: March 07, 2008, 01:27:14 pm »
Thanks to Patrick_35 and XShrimp, this has gone into my library --
-----------------------------------------------------------------------------------------------------------
(defun _SetClipBoardText ( text / htmlfile result )
;; Caller's sole responsibility is to pass a
;; text string. Anything else? Pie in face.
;; Attribution: Reformatted version of
;; post by XShrimp at theswamp.org.
;;
;; See http://tinyurl.com/2ngf4r.
(setq result
(vlax-invoke
(vlax-get
(vlax-get
(setq htmlfile (vlax-create-object "htmlfile"))
'ParentWindow
)
'ClipBoardData
)
'SetData
"Text"
text
)
)
(vlax-release-object htmlfile)
text
)
----------------------------------------------------------------------------------
and ...
----------------------------------------------------------------------------------
(defun _GetClipBoardText( / htmlfile result )
;; Attribution: Reformatted version of
;; post by Patrick_35 at theswamp.org.
;;
;; See http://tinyurl.com/2ngf4r.
(setq result
(vlax-invoke
(vlax-get
(vlax-get
(setq htmlfile (vlax-create-object "htmlfile"))
'ParentWindow
)
'ClipBoardData
)
'GetData
"Text"
)
)
(vlax-release-object htmlfile)
result
)
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP