Jump to content

Recommended Posts

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    16

  • SSA

    14

  • JohnM

    3

Top Posters In This Topic

Posted

this is my text format, as in x y r

 

10 10 1

20 20 2

30 30 3

40 40 4

 

thanks

Posted
this is my text format, as in x y r

 

10 10 1

20 20 2

30 30 3

40 40 4

 

thanks

 

Are they separated by spaces or tabs?

 

I say this, as, if you have copied it straight from Excel, they will be most likely separated by "tabs" and not "spaces".

 

If it is indeed Tabs, then my LISP in #14 should work.

Posted
If you have copied the contents of the Excel file straight into a txt file, and the format of the data in the Excel file is:

 

x y r

 

as you previously mentioned, then this may work:

 

(defun c:CirMake (/ *error* vlst ovar file nl lst)
 (vl-load-com)

 (defun *error* (msg)
   (if ovar (mapcar 'setvar vlst ovar))
   (if (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\n<< Error: " msg " >>")))
   (princ))

 (setq vlst '("CMDECHO" "OSMODE")
       ovar (mapcar 'getvar vlst))
 (mapcar 'setvar vlst '(0 0))
 (if (setq file (getfiled "Select Text File to Read" "" "txt" )
   (progn
     (setq file (open file "r"))
     (while (setq nl (read-line file))
       (setq lst (StrBrk nl 9))
       (command "_.circle"
                (list (distof (car lst))
                      (distof (cadr lst)) 0.0) (caddr lst)))
     (close file))
   (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)))

 

ok. I've copied exactly from excel and yes it's separated by tab.

 

When I load the file, this is how it looks like

: _APPLOAD

Loading C:\Auto Files trial\CirMake.lsp

: STRBRK

 

is it supposed to be like that?

what should I save the text file name as?

 

Thanks

Posted

Hmm... it loads fine for me :unsure:

 

It doesn't matter what the text file is named as - as the user will select this.

 

What are you typing to invoke the command?

Posted

I went to tools, load lisp or SDS application, add file, and load

 

what does this mean?

: _APPLOAD

Loading C:\Auto Files trial\CirMake.lsp

: STRBRK

 

Thanks

Posted

I'm not sure... are you sure that you have copied the whole thing?

 

Try this (I have added another line to the error handler):

 

(defun c:CirMake (/ *error* vlst ovar file nl lst)
 (vl-load-com)

 (defun *error* (msg)
   (if ovar (mapcar 'setvar vlst ovar))
   (if (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\n<< Error: " msg " >>"))
     (princ "\n<< Function Cancelled >>"))
   (princ))

 (setq vlst '("CMDECHO" "OSMODE")
       ovar (mapcar 'getvar vlst))
 (mapcar 'setvar vlst '(0 0))
 (if (setq file (getfiled "Select Text File to Read" "" "txt" )
   (progn
     (setq file (open file "r"))
     (while (setq nl (read-line file))
       (setq lst (StrBrk nl 9))
       (command "_.circle"
                (list (distof (car lst))
                      (distof (cadr lst)) 0.0) (caddr lst)))
     (close file))
   (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)))

Posted

Lee Mac,

 

I see what's the problem is. I'm using intelliCAD, maybe it's not compatible (I found that usually commands in autoCAD works in intelliCAD)

 

I just tried it in autoCAD and it works!! :)

Sorry I confused you.

One thing, do you know how to put each circle in a different layer?

Posted
Lee Mac,

 

I see what's the problem is. I'm using intelliCAD, maybe it's not compatible (I found that usually commands in autoCAD works in intelliCAD)

 

I just tried it in autoCAD and it works!! :)

Sorry I confused you.

One thing, do you know how to put each circle in a different layer?

 

Ahh... I hadn't thought of compatibility issues - its great that it works though!

 

I shall post a subsequent code to put each circle on a new layer :)

Posted

Perhaps this?

 

[untested]

 

(defun c:CirMake (/ *error* lay vlst ovar cnt file nl lst)
 (vl-load-com)

 (defun *error* (msg)
   (if ovar (mapcar 'setvar vlst ovar))
   (if (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\n<< Error: " msg " >>"))
     (princ "\n<< Function Cancelled >>"))
   (princ))

 (setq lay (vla-get-layers
             (vla-get-ActiveDocument
               (vlax-get-acad-object))))

 (setq vlst '("CLAYER" "CMDECHO" "OSMODE")
       ovar (mapcar 'getvar vlst) cnt 1.)
 (mapcar 'setvar (cdr vlst) '(0 0))
 (if (setq file (getfiled "Select Text File to Read" "" "txt" )
   (progn
     (setq file (open file "r"))
     (while (setq nl (read-line file))
       (setq lst (StrBrk nl 9))
       (vla-add lay (strcat "Circ-" (rtos cnt 2 0)))
       (setvar "CLAYER" (strcat "Circ-" (rtos cnt 2 0)))
       (command "_.circle"
                (list (distof (car lst))
                      (distof (cadr lst)) 0.0) (caddr lst))
       (setq cnt (1+ cnt)))
     (close file))
   (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)))

Posted

You're a genius!!

It works!! Thank you so much!!

 

by the way.. I'm trying to understand the code (I'm still learning and not planning to blindly use the code as a black box).

what's the best way to understand this? Do you mind explaining it to me?

Thanks

Posted

Thanks, I'm glad we finally got there :D

 

If you already have some idea about the structure of LISP programs, i.e. how they are defined, how to set variables etc (most of this you can get from tutorial sites), then I think the best way to understand code is to break it down and dissect it, step by step - as if you are evaluating it in much the same way as a computer would.

 

So, I would first copy this into the Visual LISP Editor in ACAD (VLIDE at command line, File> New File, then paste), you will see the colour coded functions. Then, when stepping through the program, if there is a function you do not understand, double click on it and click on the help icon to bring up the help file on it.

 

I could also comment each line of the code for you to help you understand things better.

 

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