Jump to content

Lisp to import coords and code from txt/xls file...


Recommended Posts

Posted
hmmm...cannot figure what is wrong, just took your lisp and put it in notepad and upload application..totaly strange, I see that you use ACAD 2010, maybe this is a problem??

 

There is nothing in this LISP that I have written that would be affected by versions that I can think of.

 

Would you be able to attach the notepad file you are using?

 

Thanks,

 

Lee

  • Replies 75
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    32

  • goldy2000

    27

  • tagkelas

    5

  • stevesfr

    3

Posted

Here is example file...it can be with comma or space for delimiters

AA.TXT

Posted
There is nothing in this LISP that I have written that would be affected by versions that I can think of.

 

Would you be able to attach the notepad file you are using?

 

Thanks,

 

Lee

 

Lee, your code doesn't like the spaces in the space delimited file.

 

in the lines of the code below;

VAR_6 6478734.443 5021743.861 141.46 STRANG

VAR_6001 6478740.330 5021743.133 141.436 STRANG

 

code doesn't like the length of the first field, nor the length of the field before "strang"

 

copy the first line to a separate file, it will run

copy the second line to another separate file, it won't run.

 

everyone has to get on the "same page" for field lengths and "spaces" for delimited text input file.

 

hope this doesn't drive you to drinkin'

Steve

Posted

Hmmm, hope you're right Steve, it would be good if field length for code could be up to 15 letters, and for number of points about up to 10, hope it is solvable...

Posted

My LISP extracts the information from each line by detecting a space between the different terms.

 

You have 3 spaces between each term in the text file - I was unaware of this.

 

I'll see if I can modify the LISP slightly to account for 3 spaces :)

Posted

If my theory is correct, this should work:

 

(defun c:goldy (/ doc spc file nl lst pt)
 (vl-load-com)

 (setq doc (vla-get-ActiveDocument
             (vlax-get-Acad-Object))
       spc (if (zerop (vla-get-activespace doc))
             (if (= (vla-get-mspace doc) :vlax-true) ; Vport
               (vla-get-modelspace doc)
               (vla-get-paperspace doc))
             (vla-get-modelspace doc)))

 (or (tblsearch "LAYER" "TOCKA")
   (vla-add (vla-get-layers doc) "TOCKA"))
 (if (setq file (getfiled "Select Text File"
                       (if *load$file* *load$file* "") "txt" )
   (progn
     (setq *load$file* file file (open file "r"))
     (while (setq nl (read-line file))
       (setq lst (cons (StrBrk nl 32) lst)))
     (close file)
     (foreach line lst
       (setq pt
         (mapcar 'distof
           (list (caddr line) (cadr line) (cadddr line))))
       (vla-put-layer
         (vla-AddPoint spc (vlax-3D-point pt)) "TOCKA")
       (Make_Text pt (last line) 0.0 "KOD" 1 2)
       (Make_Text pt (car line) 0.0 "BROJ TOCKE" 1 0)
       (Make_Text pt (cadddr line) 0.0 "VISINA" 1 3)))
   (princ "\n<!> No File Selected <!>"))
 (princ))


(defun StrBrk (str chrc / pos lst)
 (while (setq pos (vl-string-position chrc str))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 4))))
 (reverse (cons str lst)))

(defun Make_Text  (pt val rot lay |72 |73)
 (entmake
   (list
     (cons 0 "TEXT")
     (cons 8  lay)
     (cons 10 pt)
     (cons 40 (getvar "TEXTSIZE"))
     (cons 1  val)
     (cons 50 rot)
     (cons 7  (getvar "TEXTSTYLE"))
     (cons 71 0)
     (cons 72 |72)
     (cons 73 |73)
     (cons 11 pt))))

Posted

Hey Lee Mac, thx for trying this..You can try better to make lisp that in txt file exist comma better than free spaces

Posted

1,6500000.000,6512452.000,132.222,ROAD -->>example

Posted

Did my new code work for you on your attached text file?

Posted

No, it says: ; error: bad argument type: FILE nil

Posted

Never mind, dont bother with that any more, you already done too much!!!

Posted

Is it working at your CAD??

Posted
Is it working at your CAD??

 

Yes, it works on my machine.

 

Try saving the file in a different location - not on desktop or in Search path.

Posted

Command: _ai_selall Selecting objects...; error: Exception occurred: 0xC0000005

(Access Violation)

; warning: unwind skipped on exception

; error: Exception occurred: 0xC0000005 (Access Violation)

 

This shows me when want to select all in drawing

Posted
Command: _ai_selall Selecting objects...; error: Exception occurred: 0xC0000005

(Access Violation)

; warning: unwind skipped on exception

; error: Exception occurred: 0xC0000005 (Access Violation)

 

This shows me when want to select all in drawing

 

The LISP should not require you to select anything.. . :unsure:

Posted

hey it works!!!

Posted
hey it works!!!

 

Great! - is it working how you want it to? Or are there modifications that need doing?

Posted

I closed everything and started new job and it worked, THX MAN, can you fix it so text would be on left alignment, and to switch places X and Y (X axis in geodesy is Y in CAD, and inversly)

Posted

txt file would be the same as I send you, but in CAD to do it inversly

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...