Author Topic: Place Text from Notepad avaiable origin point 9Delimited with Semi colon)  (Read 2070 times)

0 Members and 1 Guest are viewing this topic.

chvnprasad

  • Guest

Hi
I need a lisp to place text as per given data in notepad. In notepad Coordinates and Text is delimited with Semicolon ; symbol. Need to read from notepad and place text as per Coordinate.

Thanks in Advance.

owenwengerd

  • Bull Frog
  • Posts: 451
Please post your code and explain what you're having trouble with.

chvnprasad

  • Guest
I have taken original code from www.pixelgraphicsinc.com and modified my requirementt. but is is not working

Code: [Select]
  ;========================================================================
  ;=  Function  PARSE_NUMS (string)
  ;=    Arguments: string - Text string to be comma parsed
  ;=    Returns:   A list of the elements of the string converted to numbers
  ;=    Copyright Jeff Winship 2003. All rights reserved.
  ;=    www.pixelgraphicsinc.com
  ;===============================================================3/30/2003
(defun parse_nums (st / a k lst)
  (setq k 1)
  (setq a "")
  (setq lst nil)
  (repeat (strlen st)
    (if (= (substr st k 1) ";")
      (progn
        (setq lst (append lst (list (atof a))))
        (setq a "")
      )
      (setq a (strcat a (substr st k 1)))
    )
    (setq k (+ k 1))
  )
  (setq lst (append lst (list (atof a))))
)

(defun c:placetext ()
  (setq f (open "D:/Prasad-Test/sample.txt" "r")) ;-Open the data file
  (setq dataline (read-line f)) ;-Read the header line
  (setq dataline (read-line f)) ;-Read the 1st data line
  (while (/= dataline "EOF") ;-Loop until end of file
    (setq dataline (parse_nums dataline)) ;-Parse the data line

    (command "DTEXT" car (dataline) , "2" , "0" ,cdr (dataline) "") ;-place text
    (setq dataline (read-line f)) ;-Read the next data line
  )
  (close f) ;-Close the file!!!
)

Edit: CAB - Code tags added
« Last Edit: July 21, 2014, 02:58:37 PM by CAB »

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Try this .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ f o Deconstruct_String cm st l)
  2.   (if (and (setq f (getfiled "Select Txt file " "" "txt" 16))
  3.            (setq o (open f "r"))
  4.       )
  5.     (progn
  6.       (defun Deconstruct_String (st delimiter / p l)
  7.         ;;      Tharwat 01. Nov. 2012   ;;
  8.         (while (setq p (vl-string-search delimiter st 0))
  9.           (setq l  (cons (substr st 1 p) l)
  10.                 st (substr st (+ p 2) (strlen st))
  11.           )
  12.         )
  13.         (if st
  14.           (setq l (cons st l))
  15.         )
  16.         (setq l (reverse l))
  17.       )
  18.       (setq cm (getvar 'CMDECHO))
  19.       (setvar 'CMDECHO 0)
  20.       (while (setq st (read-line o))
  21.         (setq l (Deconstruct_String st ";"))
  22.         (if (and l (vl-string-search "," (car l)) (eq (length l) 2))
  23.           (vl-cmdf "_.TEXT" (car l) (getvar 'TEXTSIZE) "0." (cadr l))
  24.         )
  25.       )
  26.       (setvar 'CMDECHO cm)
  27.       (close o)
  28.     )
  29.   )
  30.   (princ)
  31. )
  32.  

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
copyright?   interesting

Be your Best


Michael Farrell
http://primeservicesglobal.com/

owenwengerd

  • Bull Frog
  • Posts: 451
copyright?   interesting

From the Pixel Graphics web site:
Quote
All program code on this site was written by me, so if you decide to use some of the code fragments and examples
in your own work, please respect the work and keep my copyright info in the code. A link from your site would be
appreciated as well.

chvnprasad

  • Guest
Thanks Tharwat, This code is working perfect.
In this code every time i need to select notepad manually. I required to set notepad path as static.

Thanks

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Thanks Tharwat, This code is working perfect.

Thanks

You're welcome .  :-)

In this code every time i need to select notepad manually. I required to set notepad path as static.

If you don't want to select the txt file anytime you use the routine , just replace the following part from the code and put the complete path of the notepad file .

Replace this .
Code - Auto/Visual Lisp: [Select]
  1. (setq f (getfiled "Select Txt file " "" "txt" 16))
  2.  
With this .

Code - Auto/Visual Lisp: [Select]
  1. (setq f (c:\\MyFolder\\MyFile.txt))
  2.  
Or like this with forward slash .
Code - Auto/Visual Lisp: [Select]
  1. (setq f (c:/MyFolder/MyFile.txt))
  2.  

chvnprasad

  • Guest
I have replaced path, it is showing below error:

; error: no function definition: c:/MyFolder/MyFile

ronjonp

  • Needs a day job
  • Posts: 7529
I have replaced path, it is showing below error:

; error: no function definition: c:/MyFolder/MyFile


Code: [Select]
(setq f "c:/MyFolder/MyFile.txt")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC