Jump to content

Overkill problem after running lisp routine


Recommended Posts

Posted

Hi

 

Overkill does not work after running a lisp routines!!!

 

i'm sure it's the lisp files that are causing the problem.

attached are the file.p$rules calculates lengths of layers (rules) p$list has the layer names and colours

 

thanks

jimpcfd

P$RULES.LSP

P$LLIST.LSP

Posted

Localize your variables and that might solve your issues

Posted

Hi Johnm

 

i'm just a beginner with lisp stuff although have been using autocad for 24 years, so how do i localize the variables in these files ?

 

thanks

jimpcfd

Posted

Localizing variables are a must if you want your routine to not interfere with other routines.

A lisp is laid out with a open parentheses then the Defun then its calling name then a open parentheses and an closed parentheses then what ever code you write, then a closing parentheses

(defun c:test ( / )

code here

);_end of defun

It’s in the parentheses after the calling name where you localize the variables.

The contents of the parentheses are broken down into 2 sections divided by a forward slash example: (aug1 aug1……/ local variables)

If you are passing info to a defun the info is passed to the variables to the left of the forward slash these are called arguments. You can have as many arguments and needed then to the right of the forward slash you list your local variable. Local variable ar the one you create in the body of the code.

(defun c:test ( / a b c );_localized variables

(setq a 1)

(setq b 2)

(setq c (+ a b ))

);_end of defun

Localizing variable will make them all nill when the routine ends otherwise they will still be active and hold their values assigned to then in the code

Passing arguments:

(defun test (aug1 aug2 / a b c );_localized variables and arguments

(setq a aug1)

(setq b aug2)

(setq c (+ a b ))

);_end of defun

In the example above the defun needs 2 arguments passed to it or it will error out and also the calling name has the c: removed. Theses type of routines are called sub-routines

To properly call this routine you must know what type of arguments to pass to it

In this case it needs 2 integers.

Here is how you would call this routine (setq ret (test 5 10) )

This calls the test sub-routine and passes the integers 5 & 10 to it that are now assigned to aug1 and aug2.

The routine processes the info then returns an answer

The answer is 15 and is returned to the variable ret in the call (setq ret (test 5 10) )

These are basic example and could get much more complicated but this should give you a good place to start

Posted

Lee,

I normally code tag my posted codes but in this situation they where just small examples not meant to be copied or used

Posted
Lee,

I normally code tag my posted codes but in this situation they where just small examples not meant to be copied or used

 

No worries, I just thought it might look clearer and wondered whether you knew how :)

Posted

Hi Johnm

 

i understand what you are saying, does that also apply to none defun c:test ( / ) ie defun test() ?:)

Posted

Yes.

If you read my post you will see the example defun test

The c: in the calling name means it is a command line call

Look in the developers help file in AutoCAD and look up defun for a definition

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