Jump to content

Learning AutoLisp


albroswift

Recommended Posts

Greetings

Project for this weekend learn a thing or 2 about .lsp files.

Started down the tutorial

http://www.cadtutor.net/tutorials/autolisp/quick-start.php

Lots of new language, most of it makes sense, after reading tutorial I tried a couple of the sample scripts.

The CHLAYER worked as expected, put file in .../scripts directory, loaded the file, works great and as expected, and is something I can use regularly.

Tried the "Change Crosshair Angle" script:

 

(defun c:perpdon (/ a b  pntl pnt2 angl) (graphscr)
(setq a (entsel))
(setq b (entget (car a)))
(setq pntl (cdr (assoc 10 b)))
(setq pnt2 (cdr (assoc 11 b)))
(setq angl (angle pntl pnt2))
(setvar "snapang" ang1)
(princ)
)
(defun c:perpdoff (setvar "snapang" 0)
(princ)
)

Script goes right to select entity, I select a line, then nothing happens. Ortho remains 0/90

Also tried separating the scripts "PERPDON" and "PERPDOFF" as different .lsp files

Either way, command "PERPDOFF" always returns "Unknown command press F1 for help"

ACAD 2014

Thanks--

AL

Edited by SLW210
Link to comment
Share on other sites

Simple error to fix (), please do code section using the # option or type [ c o d e ] at start [ / c o d e] at end moderator will pick this up.

 

(defun c:perpdoff () (setvar "snapang" 0)

Link to comment
Share on other sites

Thanks for the instructions on posting code. Tried adding the (), still no joy. tried a couple of other scripts and they work, like to know what is missing here.

AL

(defun c:perpdon (/ a b pntl pnt2 angl) (graphscr)
(setq a (entsel))
(setq b (entget (car a)))
(setq pntl (cdr (assoc 10 b)))
(setq pnt2 (cdr (assoc 11 b)))
(setq angl (angle pntl pnt2))
(setvar "snapang" ang1)
(princ)
)
(defun c:perpdoff () (setvar "snapang" 0)
(princ)
)

Link to comment
Share on other sites

Thanks for the instructions on posting code. Tried adding the (), still no joy. tried a couple of other scripts and they work, like to know what is missing here.

AL

(defun c:perpdon (/ a b pntl pnt2 angl) (graphscr)
(setq a (entsel))
(setq b (entget (car a)))
(setq pntl (cdr (assoc 10 b)))
(setq pnt2 (cdr (assoc 11 b)))
(setq angl (angle pntl pnt2))
(setvar "snapang" ang1)
(princ)
)
(defun c:perpdoff () (setvar "snapang" 0)
(princ)
)

 

It appears that the code has mixed the numeral "1" with the lower case "L" in the "ang" variable. If you make them consistent this should fix the problem (i.e., use either "ang1" or "angl").

 

To avoid confusion, it might also be better to set the two "pnt" variables to use either numerals or letters but not one of each. I would use "pnt1" and "pnt2". Currently "pnt1" is actually "pntl" and depending on the font used, it's difficult to see the difference.

Link to comment
Share on other sites

You are 100% correct. Changing the font makes it very clear. Just edited script and re-loaded and it works as expected.

Thanks--

Al

Link to comment
Share on other sites

Nice pick up BKT missed that you get used to typing PT1 so dont think to look for typo.

 

Thanks, BIGAL - I ran into this same typo a while back and I remember how long it took to find it!

Link to comment
Share on other sites

Been using cad since the Tandy 3000 was the hot machine and Mr Gore had yet to invent the net. Sure glad he did, having resources like these forums really beats the early BBs. Thanks again for the help.

Al

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