Jump to content

Beginner Question


Mezalaja

Recommended Posts

Hello everyone,

 

Well, as a result of AlanJT's gentle encouragement, :lol: I am diving into the world of writing my own lisp routines. As a start, I've read (and partially understood) the LISP tutorial posted on this website. I have a couple of quick newbie questions:

 

1. Should you be cutting and pasting the lisp routines that you intend to use into the Acad20xx.doc file so that they load up every time you start a new drawing or should you be loading up each one on an individual basis?

 

2. And if it is the latter... can you group all the routines together into one big lisp file so you only have to load it up once?

 

3. I have read the tutorial but I am still a bit fuzzy on when to use:

 

(defun drawline (/ pntl pnt2)

 

as opposed to:

 

(defun C:drawline (/ pntl pnt2)

 

4. Should a lisp that runs in 2008 run in AutoCAD 2010 and 2011?

 

Any help would be appreciated... and I apologize now if I am posting this in the wrong forum.

 

M

Link to comment
Share on other sites

Hello everyone,

 

Well, as a result of AlanJT's gentle encouragement, :lol: I am diving into the world of writing my own lisp routines. As a start, I've read (and partially understood) the LISP tutorial posted on this website. I have a couple of quick newbie questions:

 

1. Should you be cutting and pasting the lisp routines that you intend to use into the Acad20xx.doc file so that they load up every time you start a new drawing or should you be loading up each one on an individual basis?

 

2. And if it is the latter... can you group all the routines together into one big lisp file so you only have to load it up once?

 

3. I have read the tutorial but I am still a bit fuzzy on when to use:

 

(defun drawline (/ pntl pnt2)

 

as opposed to:

 

(defun C:drawline (/ pntl pnt2)

 

4. Should a lisp that runs in 2008 run in AutoCAD 2010 and 2011?

 

Any help would be appreciated... and I apologize now if I am posting this in the wrong forum.

 

M

You should not edit the Acad20xx.lsp at all. Do not get this confused with the ACADDOC.lsp

Those are two different files. You will want to create a ACADDOC.lsp

Link to comment
Share on other sites

Well, I'm not much farther along than you, but I think I can answer your questions.

 

1. Best practice is not to use the ACAD20??.lsp file as this technically belongs to ACAD and they can overwrite it at will, besides the fact that every time you get a new version you have to migrate last years to this years. Lots of people do use the ACADyear file though.

 

The ACADDOC.LSP file is dedicated to the user and should not be overwritten and stays the same regardless of what version you are using.

 

2. Yes you can append multiple LISPs into the ACADDOC.lsp file (once you have them working!) and CAD will load them every time you open a new drawing.

 

3. LISP's are generally forward compatible. New commands occasionally get added, so if you use a 2010 command that isn't available in 2008, the LISP will have problems with backward compatability.

 

4. I THINK that the difference is that the defun C: allows the function to be called from CAD at the command line. defun ... functions are only callable from within the LISP that they are defined in.

 

Good luck getting better acquainted with LISP, and welcome to the forum.

 

Glen

Link to comment
Share on other sites

4. Should a lisp that runs in 2008 run in AutoCAD 2010 and 2011?

 

To avoid compatibility issues it is recommended to build entities by their associated lists instead of using COMMAND statement.

 

Regarding the backward compatibility, both lines of code below are working (the prompts of TEXT command changed over time):

 

(command "_TEXT" "_J" "_MC" '(0.0 0.0) 5.0 0 "Hello World!")
(command "_TEXT" "_MC" '(0.0 0.0) 5.0 0 "Hello World!")

 

And this is the associated list approach:

 

(entmake (list '(0 . "TEXT")
              (cons '10 '(0.0 0.0 0.0))
              (cons '11 '(0.0 0.0 0.0))
              (cons '1 "Hello World!")
              '(40 . 5.0)
              '(72 . 1)
              '(73 . 2)))

 

Regards,

Link to comment
Share on other sites

To avoid compatibility issues it is recommended to build entities by their associated lists instead of using COMMAND statement.

 

Regarding the backward compatibility, both lines of code below are working (the prompts of TEXT command changed over time):

 

(command "_TEXT" "_J" "_MC" '(0.0 0.0) 5.0 0 "Hello World!")
(command "_TEXT" "_MC" '(0.0 0.0) 5.0 0 "Hello World!")

 

And this is the associated list approach:

 

(entmake (list '(0 . "TEXT")
              (cons '10 '(0.0 0.0 0.0))
              (cons '11 '(0.0 0.0 0.0))
              (cons '1 "Hello World!")
              '(40 . 5.0)
              '(72 . 1)
              '(73 . 2)))

 

Regards,

 

The best way is to write function with changeable parameters IMHO

Something like this handy

(You can write the similar on it for entmakeing)

;;author unknown 
 (defun text-draw (txt pnt height rotation justification)
  (if (null pnt)(command "_.-TEXT" "" txt)
  (if (= (cdr (assoc 40 (tblsearch "STYLE" (getvar "TEXTSTYLE"))))
   0.0
      ) 
    (progn     
      (if justification
  (command "_.-TEXT" "_J" justification "_none" pnt height rotation txt)
  (command "_.-TEXT" "_none" pnt height rotation txt)
      ) 
    ) 
    (progn
      (if justification
  (command "_.-TEXT" "_J" justification "_none" pnt rotation txt)
  (command "_.-TEXT" "_none" pnt rotation txt)
      ) 
    ) 
  ) 
    )
 (entlast)
)

 

~'J'~

Link to comment
Share on other sites

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