Jump to content

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


Recommended Posts

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

 

 

Lee, new code worked here on AA.txt file (AC 2008 vanilla).

Steve

  • Replies 75
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    32

  • goldy2000

    27

  • tagkelas

    5

  • stevesfr

    3

Posted

Ok, this should be right then:

 

(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 (cadr line) (caddr line) (cadddr line))))
       (vla-put-layer
         (vla-AddPoint spc (vlax-3D-point pt)) "TOCKA")
       (Make_Text pt (last line) 0.0 "KOD" 0 2)  ; CODE
       (Make_Text pt (car line) 0.0 "BROJ TOCKE" 0 0)  ; POINT NUMBER
       (Make_Text pt (cadddr line) 0.0 "VISINA" 0 3)))  ; Z VALUE
   (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

and txt height should be 1.6, and for layer VISINA (Z axis) text obliquing is 15 degrees, is it possible?? THX MAN a lot, you really saved me a lot!!!!:shock::shock::D

 

I forgot to ask, is there a way to start lisp with COORD, and in the text file delimiters are 3 places or it can be comma or something else (like 1 free space, or more)??

Posted
Lee, new code worked here on AA.txt file (AC 2008 vanilla).

Steve

 

Thanks for testing it Steve - it was the triple spaces that threw the original code off. :thumbsup:

Posted

Try this for changes to text height and obliquing :)

 

(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 (cadr line) (caddr line) (cadddr line))))
       (vla-put-layer
         (vla-AddPoint spc (vlax-3D-point pt)) "TOCKA")
       (Make_Text pt (last line) 0.0 "KOD" 0 2 0)  ; CODE
       (Make_Text pt (car line) 0.0 "BROJ TOCKE" 0 0 0)  ; POINT NUMBER
       (Make_Text pt (cadddr line) 0.0 "VISINA" 0 3 (* pi (/ 15 180.)))))  ; Z VALUE
   (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 obl)
 (entmake
   (list
     (cons 0 "TEXT")
     (cons 8  lay)
     (cons 10 pt)
     (cons 40 1.6)
     (cons 1  val)
     (cons 50 rot)
     (cons 51 obl)
     (cons 7  (getvar "TEXTSTYLE"))
     (cons 71 0)
     (cons 72 |72)
     (cons 73 |73)
     (cons 11 pt))))

Posted

THX a lot LEE MAC and STEVE, dont know how to make up to you really:D

Posted

HAve to go home now, see you soon online...

Posted
THX a lot LEE MAC and STEVE, dont know how to make up to you really:D

 

No problem - I'm glad it saves you some time :D

Posted
Thanks for testing it Steve - it was the triple spaces that threw the original code off. :thumbsup:

 

Lee, just a programming question. Why are the insertion points of the three "texts" that comprise one set of data different. i.e. 1) on top, 2) in middle, 3) on bottom ?? maybe they could be separated by at least half the text height to be more "readable".. they overlap here.

 

of course its not my initial post, if original poster is happy, so be it.

Steve

Posted
Lee, just a programming question. Why are the insertion points of the three "texts" that comprise one set of data different. i.e. 1) on top, 2) in middle, 3) on bottom ?? maybe they could be separated by at least half the text height to be more "readable".. they overlap here.

 

of course its not my initial post, if original poster is happy, so be it.

Steve

 

I figured this would be the quickest way to lay out the three different text elements - without having to work out text spacing.

 

If the OP wants it changed, I'd be more than happy to do so :)

Posted
I've got one that will read coordinates and populate the drawing with blocks of your choosing. It will also populate the attributes of the block in the order they appear in your excel/text file.

 

Example:

 

X coord y coord attribute1 attribute 2

 

Do you want me to send it or is it not compatible with your designs?

 

 

Wannabe, I think your file would be extremely useful for my scenario. Would you mind posting it here? Thanks.

Posted

Give this a shot buddy:

 

[i][color=#990099];; Block Insertor by Lee McDonnell[/color][/i]
[i][color=#990099];; 03.06.2009[/color][/i]

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:blkIns [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] doc spc bdef blk file ofile ex lst iBlk line[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] doc [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-Acad-Object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       spc [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]zerop[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-activespace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]=[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-mspace[/color][/b] doc[b][color=RED])[/color][/b] :vlax-true[b][color=RED])[/color][/b] [i][color=#990099]; vPort[/color][/i]
               [b][color=RED]([/color][/b][b][color=BLUE]vla-get-modelspace[/color][/b] doc[b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]vla-get-paperspace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]vla-get-modelspace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] bdef [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"INSNAME"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] blk[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blk
     [b][color=RED]([/color][/b][b][color=BLUE]getstring[/color][/b] t
       [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\nSpecify Block to be Inserted <"[/color][/b] bdef [b][color=#ff00ff]">: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#ff00ff]""[/color][/b] blk[b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blk bdef[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]snvalid[/color][/b] blk[b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"BLOCK"[/color][/b] blk[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]snvalid[/color][/b] blk[b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]findfile[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] blk [b][color=#ff00ff]".dwg"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.insert"[/color][/b] blk[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]T[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"<!> Please Re-Select <!>"[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blk [b][color=BLUE]nil[/color][/b] bdef [b][color=#ff00ff]""[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] file [b][color=RED]([/color][/b][b][color=BLUE]getfiled[/color][/b] [b][color=#ff00ff]"Select File to Read"[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] *load$file* *load$file* [b][color=#ff00ff]""[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]"txt;csv"[/color][/b] [b][color=#009900]8[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *load$file* file ofile [b][color=RED]([/color][/b][b][color=BLUE]open[/color][/b] file [b][color=#ff00ff]"r"[/color][/b][b][color=RED])[/color][/b]
           ex [b][color=RED]([/color][/b][b][color=BLUE]vl-filename-extension[/color][/b] file[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] nl [b][color=RED]([/color][/b][b][color=BLUE]read-line[/color][/b] ofile[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lst [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=RED]([/color][/b]StrBrk nl [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] ex [b][color=#ff00ff]".txt"[/color][/b][b][color=RED])[/color][/b] [b][color=#009900]32[/color][/b] [b][color=#009900]44[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]close[/color][/b] ofile[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] line lst
       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] iBlk
         [b][color=RED]([/color][/b][b][color=BLUE]vla-InsertBlock[/color][/b] spc
           [b][color=RED]([/color][/b][b][color=BLUE]vlax-3D-point[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]distof[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] line[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cadr[/color][/b] line[b][color=RED])[/color][/b] [b][color=#ff00ff]"0.0"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
           blk [b][color=#009999]1.[/color][/b] [b][color=#009999]1.[/color][/b] [b][color=#009999]1.[/color][/b] [b][color=#009999]0.[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]      
       [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] :vlax-true [b][color=RED]([/color][/b][b][color=BLUE]vla-get-HasAttributes[/color][/b] iBlk[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] line [b][color=RED]([/color][/b][b][color=BLUE]cddr[/color][/b] line[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] att  [b][color=RED]([/color][/b][b][color=BLUE]vlax-safearray->list[/color][/b]
                         [b][color=RED]([/color][/b][b][color=BLUE]vlax-variant-value[/color][/b]
                           [b][color=RED]([/color][/b][b][color=BLUE]vla-getAttributes[/color][/b] iBlk[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] line
             [b][color=RED]([/color][/b][b][color=BLUE]vla-put-TextString[/color][/b] att [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] line[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] line [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] line[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<!> No File Selected <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] StrBrk [b][color=RED]([/color][/b]str chrc [b][color=BLUE]/[/color][/b] pos lst[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pos [b][color=RED]([/color][/b][b][color=BLUE]vl-string-position[/color][/b] chrc str[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lst [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]substr[/color][/b] str [b][color=#009900]1[/color][/b] pos[b][color=RED])[/color][/b] lst[b][color=RED])[/color][/b]
         str [b][color=RED]([/color][/b][b][color=BLUE]substr[/color][/b] str [b][color=RED]([/color][/b][b][color=BLUE]+[/color][/b] pos [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]reverse[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] str lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

Posted

Lee Mac,How about a similar code?

For example

Importing file in this format:

ID(CODE),X,Y,Z

or X,Y,Z

without printing Z as text (but printing ID(code) as text near the point)

ID(code) in spesific Layer (ex CODE) and the Point in other Layer (ex Points)

 

You helped me in the past for exporting Points

A sample of the previous code is

(setq points (ssget) i 0 p 0 separator ",")
So if i change this (",") to ("[tab]") I can export points to scv format

Can we put this choice in the routine I asked above?

Posted

Yes I should think I could do this - just an ACAD point and text above it yes?

Posted

Hey Lee Mac, I tried your lisp on 5 page, it worked on ACAD 2008 perfectly, but on ACAD 2004 had some troubles, it freezes when wanted to zoom/extents, do you know maybe reason???

 

THX for sode, appreciate very much...

 

Can you tell me something more, is it possible to make a version to be comma instead of 3 places in txt file, and to change start lisp with COORD??

Posted
Hey Lee Mac, I tried your lisp on 5 page, it worked on ACAD 2008 perfectly, but on ACAD 2004 had some troubles, it freezes when wanted to zoom/extents, do you know maybe reason???

 

To be honest, it is such a simple routine, there is not very much that can go wrong with it. - I wouldn't recommentd invoking command whilst the LISP is operating though.

 

 

Can you tell me something more, is it possible to make a version to be comma instead of 3 places in txt file, and to change start lisp with COORD??

 

Yes, making it command delimited is quite easy - I shall post the code in a min :)

Posted
Can you tell me something more, is it possible to make a version to be comma instead of 3 places in txt file, and to change start lisp with COORD??

 

Try this for comma delimited and "COORD" syntax:

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:coord [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] doc spc file nl lst pt[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] doc [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-Acad-Object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       spc [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]zerop[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-activespace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]=[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-mspace[/color][/b] doc[b][color=RED])[/color][/b] :vlax-true[b][color=RED])[/color][/b] [i][color=#990099]; Vport[/color][/i]
               [b][color=RED]([/color][/b][b][color=BLUE]vla-get-modelspace[/color][/b] doc[b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]vla-get-paperspace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]vla-get-modelspace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LAYER"[/color][/b] [b][color=#ff00ff]"TOCKA"[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]vla-add[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-layers[/color][/b] doc[b][color=RED])[/color][/b] [b][color=#ff00ff]"TOCKA"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] file [b][color=RED]([/color][/b][b][color=BLUE]getfiled[/color][/b] [b][color=#ff00ff]"Select Text File"[/color][/b]
                       [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] *load$file* *load$file* [b][color=#ff00ff]""[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]"txt"[/color][/b] [b][color=#009900]8[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *load$file* file file [b][color=RED]([/color][/b][b][color=BLUE]open[/color][/b] file [b][color=#ff00ff]"r"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] nl [b][color=RED]([/color][/b][b][color=BLUE]read-line[/color][/b] file[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lst [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=RED]([/color][/b]StrBrk nl [b][color=#009900]44[/color][/b][b][color=RED])[/color][/b] lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]close[/color][/b] file[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] line lst
       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pt
         [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]distof[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cadr[/color][/b] line[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]caddr[/color][/b] line[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cadddr[/color][/b] line[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]vla-put-layer[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]vla-AddPoint[/color][/b] spc [b][color=RED]([/color][/b][b][color=BLUE]vlax-3D-point[/color][/b] pt[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]"TOCKA"[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b]Make_Text pt [b][color=RED]([/color][/b][b][color=BLUE]last[/color][/b] line[b][color=RED])[/color][/b] [b][color=#009999]0.0[/color][/b] [b][color=#ff00ff]"KOD"[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#009900]2[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099]; CODE[/color][/i]
       [b][color=RED]([/color][/b]Make_Text pt [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] line[b][color=RED])[/color][/b] [b][color=#009999]0.0[/color][/b] [b][color=#ff00ff]"BROJ TOCKE"[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099]; POINT NUMBER[/color][/i]
       [b][color=RED]([/color][/b]Make_Text pt [b][color=RED]([/color][/b][b][color=BLUE]cadddr[/color][/b] line[b][color=RED])[/color][/b] [b][color=#009999]0.0[/color][/b] [b][color=#ff00ff]"VISINA"[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#009900]3[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=BLUE]pi[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] [b][color=#009900]15[/color][/b] [b][color=#009999]180.[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099]; Z VALUE[/color][/i]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<!> No File Selected <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]


[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] StrBrk [b][color=RED]([/color][/b]str chrc [b][color=BLUE]/[/color][/b] pos lst[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pos [b][color=RED]([/color][/b][b][color=BLUE]vl-string-position[/color][/b] chrc str[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lst [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]substr[/color][/b] str [b][color=#009900]1[/color][/b] pos[b][color=RED])[/color][/b] lst[b][color=RED])[/color][/b]
         str [b][color=RED]([/color][/b][b][color=BLUE]substr[/color][/b] str [b][color=RED]([/color][/b][b][color=BLUE]+[/color][/b] pos [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]reverse[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] str lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] Make_Text  [b][color=RED]([/color][/b]pt val rot lay |72 |73 obl[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]entmake[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#ff00ff]"TEXT"[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]8[/color][/b]  lay[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]10[/color][/b] pt[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]40[/color][/b] [b][color=#009999]1.6[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]1[/color][/b]  val[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]50[/color][/b] rot[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]51[/color][/b] obl[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]7[/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"TEXTSTYLE"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]71[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]72[/color][/b] |72[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]73[/color][/b] |73[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]11[/color][/b] pt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 
            

Posted
Lee Mac,How about a similar code?

For example

Importing file in this format:

ID(CODE),X,Y,Z

or X,Y,Z

without printing Z as text (but printing ID(code) as text near the point)

ID(code) in spesific Layer (ex CODE) and the Point in other Layer (ex Points)

 

You helped me in the past for exporting Points

A sample of the previous code is

So if i change this (",") to ("[tab]") I can export points to scv format

Can we put this choice in the routine I asked above?

 

Try this mate - I'm not sure what Text Size you want - so I have left it at 1.6.

 

(defun c:coord (/ 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" "POINTS")
   (vla-add (vla-get-layers doc) "POINTS"))
 (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 44) lst)))
     (close file)
     (foreach line lst
       (setq pt
         (mapcar 'distof
           (list (cadr line) (caddr line) (cadddr line))))
       (vla-put-layer
         (vla-AddPoint spc (vlax-3D-point pt)) "POINTS")
       (Make_Text pt (car line) 0.0 "CODE" 1 2 0.0)))
   (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 2))))
 (reverse (cons str lst)))

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

Posted

Yep, this is it, exactly what I was looking for, I had some old DOS software who do this but it took some time to make dxf...

THX man very much, you helped me a lot!! How come that you know a lot about programming LISPs??

Posted
Yep, this is it, exactly what I was looking for, I had some old DOS software who do this but it took some time to make dxf...

THX man very much, you helped me a lot!! How come that you know a lot about programming LISPs??

 

No problem Goldy - happy to help.

 

As for how I know a bit about programming:

I enjoyed writing a few simple ones when I was using AutoCAD in an old job I had, and, when I left the job and went to university, I kept it up and progressed. I have learnt most of what I know from the guys on this site though :P

 

Cheers,

 

Lee

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