Getfiled to read file and make a pline
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Getfiled to read file and make a pline

 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization
Author Message
Rogerio_Brazil
Guest





Posted: Mon Dec 27, 2004 8:39 pm    Post subject: Getfiled to read file and make a pline Reply with quote

Hello,

How to use a function getfiled to read a .txt file and draw a pline with the points?

Sample getfiled function:

(set fname (getfiled "Points file to read:" "C:\\" "txt" 4))

Sample .txt file:
2 coordinates

1,4
2,5
3,1

or
3 coordinates:

1,4,0
2,5,0
3,1,0

Thanks in advance,

Rogerio

Back to top
pablorico21
Guest





Posted: Mon Dec 27, 2004 8:59 pm    Post subject: Re: Getfiled to read file and make a pline Reply with quote

Tomorrow I will bring some idea for you.

Pablo
Back to top
T.Willey
Guest





Posted: Mon Dec 27, 2004 9:23 pm    Post subject: Re: Getfiled to read file and make a pline Reply with quote

Use these to read your file once you have it.

(defun PointsFromFile (FileName / PtList temp1 temp2)

(setq Opned (open FileName "r"))
(while (setq temp1 (read-line Opned))
(setq temp2 (mapcar 'read (StrParse temp1 ",")))
(setq PtList (cons temp2 PtList))
)
(close Opned)
(reverse PtList)
)

(defun StrParse (String Seperator / Pos1 Pos2 NewStrList)
;|
Seperator a string (making a list of stings) at a given
string value
ie: (StrParse "1,1,0" ",")
returns: ("1" "1" "0")
Written when I couldn't find it on the web
By: Tim Willey 11/15/2004
|;

(setq Pos2 1)
(while (setq Pos1 (vl-string-search Seperator String Pos1))
(if (= Pos2 1)
(setq NewStrList (cons (substr String Pos2 Pos1) NewStrList))
(setq NewStrList (cons (substr String Pos2 (- (1+ Pos1) Pos2)) NewStrList))
)
(setq Pos2 (1+ (+ (strlen Seperator) Pos1)))
(setq Pos1 (+ Pos1 (strlen Seperator)))
)
(reverse (setq NewStrList (cons (substr String Pos2) NewStrList)))
)

Then you can issue the pline command like
(command "_.pline")
(mapcar 'command temp1)
; where temp1 is the list returned by PointsFromFile
(command "")

Hope that helps.
Tim

Back to top
T.Willey
Guest





Posted: Mon Dec 27, 2004 9:25 pm    Post subject: Re: Getfiled to read file and make a pline Reply with quote

Or just issue the command like

(command "pline" (mapcar 'command temp1))

Tim
Back to top
Rogerio_Brazil
Guest





Posted: Mon Dec 27, 2004 10:48 pm    Post subject: Re: Getfiled to read file and make a pline Reply with quote

Thank very much, Pablo and Tim.

Rogerio
Back to top
T.Willey
Guest





Posted: Mon Dec 27, 2004 11:04 pm    Post subject: Re: Getfiled to read file and make a pline Reply with quote

Glad it works for you.
Happy to help.

Tim
Back to top
pablorico21
Guest





Posted: Tue Dec 28, 2004 4:42 pm    Post subject: Re: Getfiled to read file and make a pline Reply with quote

;;MAKE PLINE FROM TXT POINTS
;;By Pablo Barbosa
;;e-mail:pablorico21@yahoo.com.br
;;date:27/12/04


;|OBS.:
TAKE WITH YOUR COORDINATE FORMAT.
THE "," SEPARATE X Y Z, and "." SEPARATE DECIMALS
ex.: 1.5,2.6,0.0 -> correct format
1,5,2,6,0,0 -> wrong format
|;
;;TASTE THIS ROUTINE, IT WORK FINE.
(defun C:MKPLINE (/ OPENFILE LINEINFILE LENVERTICE filename ENDLIST2P ENDLIST2 ENDLIST)
(SETQ ECHOMKPLINE (GETVAR "CMDECHO"))
(SETVAR "CMDECHO" 0)

;GET FILENAME
(SETQ FILENAME (getfiled "Points file to read:" "c:\\" "txt" 4))
(IF FILENAME
(PROGN
;;OPEN FILE
(SETQ ENDLIST NIL)
(SETQ OPENFILE (OPEN FILENAME "R"))
;;WHILE HAVE LINES FOR READ..
(WHILE (SETQ LINEINFILE (READ-LINE OPENFILE))
(SETQ ENDLIST (APPEND (LIST LINEINFILE) ENDLIST))
)
;;CLOSE FILE
(CLOSE OPENFILE)
;|
CONVERT STRINGLIST IN LIST
SEE GETCONVERTLIST FUNCTION AFTER THIS ROUTINE FOR MORE DETAILS...
|;
(SETQ ENDLIST2P (MAPCAR 'GETCONVERTLIST ENDLIST))
;;ADD 10 DXF CODE FOR MAKE PLINE LIST CORDINATES
(SETQ ENDLIST2 (MAPCAR '(LAMBDA (X) (APPEND '(10) X)) ENDLIST2P))
;; VERTICE NUMBER
(SETQ LENVERTICE (LENGTH ENDLIST2))
;;IF YOU NEED, CHANGE FOR 3DPOLY...
;;FINALLY...MAKING PLINE
(entmake
(APPEND
(LIST (cons 0 "lwpolyline"))
;;2dpoly
(LIST (cons 100 "AcDbEntity"))
(LIST (cons 100 "AcDbPolyline"))
(LIST (cons 90 LENVERTICE))
ENDLIST2

)
)

(princ "\nBy Pablo Barbosa - pablorico21@yahoo.com.br - 27/12/04."))
(progn
;;IF THE USER CANCEL THE GETFILED
(princ "\nMKPLINE COMMAND WAS CANCELED!")
(SETVAR "CMDECHO" ECHOMKPLINE)
(PRINC)
(VL-EXIT-WITH-VALUE nil))
)
(SETVAR "CMDECHO" ECHOMKPLINE)
(PRINC)
)



;;convert list originating from of the strings
;;EX:
;;2d (mapcar 'GETCONVERTLIST '("0,1" "1,2" "0,3"))->((0 1) (1 2) (0 3))
;;or 3d (mapcar 'GETCONVERTLIST '("0,1,1" "1,2,1" "0,3,1"))->((0 1 1) (1 2 1) (0 3 1))
;;IF You need, substitute the "," for other character.

;;and so, the magic function...
(DEFUN GETCONVERTLIST (PSEUDOLISTT / RESULT)
;;{(STRCAT "("...} make a string result: "0,2,0" -> "(0,2,0)"
(SETQ RESULT
(STRCAT "("(VL-STRING-TRANSLATE "," " " PSEUDOLISTT)")")
)
;;...andprint list result
(READ RESULT)
)


;;excuse for my poor English, I promise improve it!,But my lisp...
;;I will post it in Autolisp.com.br too.



;|«Visual LISP© Format Options»
(90 2 1 0 nil "end of " 90 9 0 0 2 nil T nil T)
;*** DO NOT add text below the comment! ***|;
Back to top
Rogerio_Brazil
Guest





Posted: Tue Dec 28, 2004 4:49 pm    Post subject: Re: Getfiled to read file and make a pline Reply with quote

In portuguese language:

Pablo, como o mundo é pequeno.

Sou eu, o Rogério do www.autolisp.com.br.

Postei aqui porque sempre tem boas alternativas.

Valeu pela ajuda. De verdade.

Um abraço. Thank you!

Rogério
Back to top
pablorico21
Guest





Posted: Tue Dec 28, 2004 9:26 pm    Post subject: Re: Getfiled to read file and make a pline Reply with quote

Oi Rogerio, coloquei essa rotina no Autolisp.com.br
Tchau. o Fórum aqui é muito bom.
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Contact Us
Powered by phpBB