Jump to content

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


Recommended Posts

Posted

What does this string exactly?

(setq lst (cons (StrBrk nl 44) lst)))

 

I notice a difference with the previous rutine

44 or 32?

 

And how can I change it for tab delimited?

  • Replies 75
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    32

  • goldy2000

    27

  • tagkelas

    5

  • stevesfr

    3

Posted
What does this string exactly?

(setq lst (cons (StrBrk nl 44) lst)))

 

I notice a difference with the previous rutine

44 or 32?

 

And how can I change it for tab delimited?

 

 

This calls the sub-function StrBrk which cuts up the string into sections delimited by the character code specified - i.e. 44 = comma; 32 = space.

 

So for TAB:

 

[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]9[/color][/b][b][color=RED])[/color][/b] lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])

 

 

[/color][/b]

Posted

Thanks a lot Lee Mac (one more time)

Posted

Lee,

again this line

(setq lst (cons (StrBrk nl 44) lst)))

 

Can we make it a litlle difficult?

 

How can we make this line with "if" function?

example

strbrk nl 9 (but if do not find "tab") then 44

 

So in dialog box i can choose either txt or xls file.

 

--------------

 

Posted
Lee,

again this line

(setq lst (cons (StrBrk nl 44) lst)))

 

Can we make it a litlle difficult?

 

How can we make this line with "if" function?

example

strbrk nl 9 (but if do not find "tab") then 44

 

So in dialog box i can choose either txt or xls file.

 

--------------

 

 

ooo Dialog Boxes... get you :P

 

Check my LISP above, posted for JimJones #52. I used an IF statement in there :thumbsup:

Posted

Thanks Lee Mac.

I don't have much time right now to check it,

but I will....

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

Thanks for this code Lee..works as well..now i have a little request regarding this code i just wanna ask you to removed the "Z" value see the attachment..

 

thank you and more power..

:)

AA1.txt

Posted

Try this Oliver:

 

(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) "0.0")))
       (vla-put-layer
         (vla-AddPoint spc (vlax-3D-point pt)) "TOCKA")
       (Make_Text pt (car line) 0.0 "BROJ TOCKE" 0 0 0)))  ; POINT NUMBER
   (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

thanks a lot Lee..its done..but just a little problem..about point style could fix and also the limits.

 

thanks.

 

oliver

Posted
.but just a little problem..about point style could fix and also the limits.

 

I don't understand what you are requesting here?

Posted

original display..

originalw.jpg

 

fix with drawing limits

drawinglimits.jpg

 

original point

originalpt.jpg

 

with this point style

originalptf.jpg

 

sorry for my bad english..

 

oliver

Posted

That is just your setting of PDMODE :)

 

I could add the code to the LISP, its just:

 

(setvar "PDMODE" )

 

This can be added anywhere, and its just as easy for you to change it :)

  • 4 years later...
Posted

Dear Lee,

 

I modified your code for my purpose.

I worked fine with my previous work such as DPOINT3 DATA SAMPLE.txt

 

But It failed with DPOINT3 DATA SAMPLE 1.txt

 

Colud you possibly help me to rectify?

 

Thanks,

Miquan

 

;Draw point from txt data
;Txt data: Point ID,Point X-coord,Point Y-coord,Point Z-coord,Text
;If you want to use tab for delimite data, replace 44 by 32 in code
;http://www.cadtutor.net/forum/showthread.php?37830-Draw-polyline-from-file-coords-excel
(defun c:dp3 (/ doc spc file nl lst pt)
 (vl-load-com)
 (setvar "PDMODE" 35) ; Format point number PDMODE paramater

 (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" "S-Notes")
   (vla-add (vla-get-layers doc) "S-Notes"))
 (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)) "S-Notes")
       (Make_Text pt (last line) 0.0 "S-25Text-VN" 0 2 0)  ; CODE
       (Make_Text pt (car line) 0.0 "S-Dim" 0 0 0)  ; POINT NUMBER
       (Make_Text pt (cadddr line) 0.0 "S-Hatch" 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 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 (getvar "dimtxt")); Height of Text = height of dim text
     (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))))

DPOINT3 DATA SAMPLE.txt

DPOINT3 DATA SAMPLE 1.txt

  • 2 years later...
Posted

Hey Lee, i tried your code and its works like a charm. I want to make a few changes to suit me, i tried but im failing everytime im trying.

I want to make it simplier like POINT,X,Y

Also i can you change the names of the layers back to english?

Thnx in advance

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