Jump to content

New to lisp-can't get 'simple' routine to consistantly run.


Recommended Posts

Posted

:? I'm new to lisp and I've cobbled together some odds and ends to try and do what I'm needing done on several files. This did work but now it doesn't. I load it up and then open up my 20 or so drawings, expecting it to turn on a layer in an xref(static layer name/xref). I'm using 2007. Nothing earth shattering, but it's driving me nuts, bc it did work perfectly and now I get 'nil' after it processes the 1st file. Any help is much appreciated.

 

(DEFUN c:nfcon ()

(setvar "cmdecho" 0)

(command "layer" "thaw" "tb|nfc" "")

(command "_.zoom" "e")

(setvar "cmdecho" 1)

(command "qsave")

(princ)

)

(c:nfcon)

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • tofuannie

    14

  • Lee Mac

    13

Popular Days

Top Posters In This Topic

Posted

How are you loading it? ACADDOC.lsp? ACAD.lsp? Startup Suite?

 

Did you mean to run it through a script?

Posted

Thanks, Lee Mac. Since I don't want it to run all the time, I usually just load it up under Tools>AutoLISP>Load App, when I want to process some files. I don't use a script, bc I ran across a net instance where they just opened up the 10 or so files (once the lsp was loaded) and when each one opened the lsp routine ran. The net routine was similiar to mine, except it was purging not thawing a layer.

Posted

Bear in mind that loading is not the same as running - the only reason this code runs when it is loaded is the (c:nfcon) at the end.

 

What are you trying to achieve? If you want the code to run when you open each drawing just put a call to it in the ACADDOC.lsp

Posted

Ahh, that's where being 'new' comes in. I didn't realize that the routine wouldn't just run after being loaded. My goal is to turn on or off a frozen layer on up to about 50 drawings without having to do each one in an individual basis. I'll try adding a call to ACADDOC.lsp. thanks!

Posted

Here is my recommendation for you:

 

Change your code to this:

 

(DEFUN c:nfcon ()
  (setvar "cmdecho" 0)
  (command "_.-layer" "_thaw" "tb|nfc" "")
  (command "_.zoom" "_e")
  (setvar "cmdecho" 1)
  (command "_.qsave")
(princ))

 

Lets say you save it to filename "mylisp.lsp"

 

Type this at the command-line:

 

(findfile "ACADDOC.lsp")

 

If it returns nil, open a new Notepad doc, and save it as ACADDOC.lsp in your ACAD support path. Else, go to the location and find the file.

 

Open the ACADDOC.lsp and type this:

 

(load "mylisp.lsp")

 

Make sure that the mylisp.lsp file is also in the support path.

 

Now, to create the Script, perhaps take a look at my program here:

http://www.cadtutor.net/forum/showpost.php?p=295487&postcount=23

 

The Script-line you may want to enter is:

 

_.open *file* (c:nfcon) close 

 

And this will create a script that you can run on your 50 drawings.

 

Lee

Posted

Wow, thanks so much for your help, Lee Mac! Just dipping my toe into the lisp water has really shown me what I've been missing. I'll do it! Time to buy a book..any thoughts on a good beginning one to start?

Posted

You needn't really buy anything, there are so many resources online for free:

 

Starting LISP:

http://www.afralisp.net/

http://www.jefferypsanders.com/autolisptut.html

http://ronleigh.info/autolisp/index.htm

 

More Advanced LISP Tutorials:

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html

http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node1.html

 

DCL Tutorials:

http://www.jefferypsanders.com/autolisp_DCL.html

http://www.afralisp.net/

 

Visual LISP Editor:

http://www.afralisp.net/vl/vlisp.htm

http://www.afralisp.net/vl/vl-edit.htm

http://midpointcad.com/au/docs/lakose_The_Visual_LISP_Developers_Bible.pdf

 

Explanation of a LISP function (Text replacement):

http://www.cadtutor.net/forum/showpost.php?p=264546&postcount=15

 

Localising Variables:

http://www.cadtutor.net/forum/showpost.php?p=265649&postcount=4

 

Auto-Loading LISP (ACADDOC.lsp etc):

http://www.theswamp.org/index.php?topic=30946.msg364983#msg364983

http://www.cadtutor.net/faq/questions/53/How+do+I+automatically+load+variables%3F

 

Car/Cadr/Caddr Explained:

http://ronleigh.info/autolisp/afude09.htm

http://www.theswamp.org/index.php?topic=31473.0

 

 

That should keep you occupied :D

 

Lee

Posted

Thanks, Lee Mac. Free is always better in my book! Thanks for the listing...a lot of reading ahead!

Posted

Ok, I know my 'new' is showing. I just couldn't wait to try out your help but I still need some more direction. The script routine is amazing. I really don't understand any of it, but I get the gist of it. What I'll end up doing is seaching info on every variable listed in the script and maybe somewhere in the future, it will begin to jell! Back to the question..I changed my lsp as you suggested, except the name is "nfcon.lsp and nfcoff.lsp" ( I have one for thawing the layer and one for freezing the layer) I created the ACADDOC.lsp and added the line you suggested, except mine also included the path..(load "z:/blah/blah/nfcon.lsp"). I saved your script file in notepad to "wScript.lsp" saved it at the same location of my "nfcon.lsp". Then in the command line I cut and pasted "_.open *file* (c:nfcon) close". Your script ran and opened up the dialog to pick my files (very cool); they opened but the "nfcon" didn't thaw the layer. Everything was so smooth, except for the final piece. What did I do wrong?

Posted

Just to clarify, if my program successfully created the script to the location you chose to save it, you will still need to run that script using the script command in AutoCAD - my routine merely writes the script. :)

 

I shall take a look at the code you are using also :)

Posted

A VL alternative to your code:

 

(defun c:nfcon (/ lay app)
 (vl-load-com)

 (if (not (vl-catch-all-error-p
            (setq lay
              (vl-catch-all-apply
                (function vla-item)
                  (list (vla-get-layers                           
                          (vla-get-ActiveDocument
                            (setq app (vlax-get-acad-object)))) "tb|nfc")))))
   
   (vla-put-freeze lay :vlax-false))

 (vla-ZoomExtents app)
 (vla-save (vla-get-ActiveDocument app))
 
 (princ))

Posted

You're fast Lee Mac! Please help me to understand a couple of things, if you don't mind. I checked the txt window in ACad and it shows that "_.open" worked, but it showed *file* as an unknown command and then didn't carry on with "(c:nfcon)". Why is that? Are the 3 routines not connected to each other and that's why you've made the above suggestion? or... (always, thanks!)

Posted
You're fast Lee Mac! Please help me to understand a couple of things, if you don't mind. I checked the txt window in ACad and it shows that "_.open" worked, but it showed *file* as an unknown command and then didn't carry on with "(c:nfcon)". Why is that? Are the 3 routines not connected to each other and that's why you've made the above suggestion? or... (always, thanks!)

 

Ok, I think we may have got confused slightly along the way. The *file* is just a 'token' I use solely in my ScriptWriter program to represent the filename of a drawing.

 

Hence, the user enters a line of operations that he/she wants to perform on a set of drawings, but replacing the filepath of the drawing with the *file* token.

 

My program will then write a script encoding the filepaths of all the drawings in the directory selected in place of the *file* token.

 

The script can then be run to operate on those drawings.

 

The advantage is the user does not have to manually copy/paste/type each line of the script, but only the first line.

 

Sorry, meant to ask...what is VL?

 

Visual LISP - an extension to standard AutoLISP with extra power :D

Posted

:lol: That's OK Lee Mac, you can say "I" got confused along the way. I'm a newbie, so every little thing is taken literally.

 

So, I've opened any ACad dwg and in the command line, I place "_.open z:\xxx\xxx.dwg (c:nfcon) close" and then it will run your "wScript.lsp", open my numerous dwgs, and run the "nfcon". Where does that command line entry pick up your "wScript.lsp" in order to create the script?

 

Sorry for the crazy questions...just know, you are planting a seed that I'll grow. thanks

Posted

No worries, I'll step you through it. :)

 

  • Open AutoCAD to any new drawing
  • Make sure that my WScript.lsp is loaded
  • Type WScript at the command line
  • Enter your script line [i.e. _.open *file* (c:ncfcon) _.close ]
  • Select the Directory you want to process
  • Select a Location for the script file

Now the script file is written, we can run it.

 

  • In AutoCAD type "script" at the command line
  • Select the Script file we just created, click ok.

Hopefully this should clarify things for you, but please let me know if you are stuck on any part of this, and I'd be happy to help out some more.

 

Lee

Posted

:lol: ehh, Wow!

 

It really helps when the sun comes out, doesn't it? Everything ran as perfectly as you laid out. It was exactly what I wanted to do.

 

Thanks, and next time I'll start out with much, much smaller wants. I really didn't have a clue as to what I was wanting to do when I first started out. I figured it would be a snap to pull together...not for me...not yet. You're the best, thanks so much!!

Posted
:lol: ehh, Wow!

 

It really helps when the sun comes out, doesn't it? Everything ran as perfectly as you laid out. It was exactly what I wanted to do.

 

Thanks, and next time I'll start out with much, much smaller wants. I really didn't have a clue as to what I was wanting to do when I first started out. I figured it would be a snap to pull together...not for me...not yet. You're the best, thanks so much!!

 

Not a problem, my pleasure.

 

Its a steep learning curve, and now you know for next time you want to operate on multiple drawings :)

 

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