Jump to content

Recommended Posts

Posted

I am learning LISP by modifying some code that Lee wrote for me a while back. Can someone explain to me the difference between the 2 snippets of code below?

 

 (setq bname (getfiled "select block to insert" "" "dwg" )
 (if (setq file
            (getfiled "Select Text File" (if *load *load "") "txt" )
   (progn .......

 

  
(setq bname (getfiled "select block to insert" "" "dwg" 0))
 (if (setq file
            (getfiled "Select Text File" "" "txt" 0))
   (progn .......

 

Lee's code is the first, which I have modified to the second. I was having problems with "file is nil" after selecting my input files, I THINK that I tracked it down to the bit field - 8 sends only the filename and 0 sends the full path. What does the (if *load *load "") statement do? Why use it instead of the apparently simpler version below it?

 

According to the VLISP help file:

(getfiled title default ext flags)

...default A default file name to use; can be a null string ("").

 

...

 

 

I'm not sure why I would use an expression to specify a default file name?

 

Thanks for any guidance you can give me.

 

Glen

Posted

I use *load as a global variable and store the new filepath to it after a file has been selected, hence it uses this as the next default.

 

As for the bit code, 8 will only return the filename (if the file is in the search path), but you can maybe use "findfile" to get the whole path.

 

If not, you could use 128 to get the whole path.

 

Bear in mind that bit 0 is used for creation of a new file.

Posted

Ahh - that makes sense, I hadn't thought of it being a global variable.

 

As I understand it, bit 0 is for the creation of a new file but only if it is set. So instead of 0 it would be a 1 to create a new file, correct?

 

Thanks, I really appreciate there being a place that I can ask questions rather than solely relying on the help files and trial and error.

 

Glen

Posted

Hmmm, now you've got me thinking.

 

As, in the help files, it says use an integer between 0 and 15 for the flags, however I have only ever used the bit values: 1, 4, 8, 16 etc.

 

But this raises the question that, if you can use both, how does AutoCAD know whether you want bit code 8, or (3 + 5)?

 

:unsure:

Posted

According to the help file, bit 1 (binary value 2) is not used, but regardless, any given value sets a unique group of bits in that bit coded field. 3 is not a single flag value it is two different flags that are both set: bit 0 (decimal 1) and bit 1 (decimal 2) both set and added together to get decimal 3. (Not valid in this case since bit 1 is not used)

Likewise 5 would be bit 2 (decimal 4) added to bit 0 (decimal 1) both set.

 

8 could only be bit 3 set.

 

It took me a while to get my head around bit coded fields, but once you get past binary to decimal to binary conversions it is a slick way to set multiple options with one number.

 

Glen

Posted

Oh, don't get me wrong, I know how the binary addition works - but I thought that you could use the bit values instead of the binary values or vice versa.

Posted

I figured you knew how it worked, just wanted to make sure if anyone else read it they didn't get confused.

 

Nother question, is it the * that makes that variable a global? The very little bit of a 1 credit C course (that I had to take (twice) 15 years ago) that remains in my brain is telling me that it is a pointer rather than a variable - but I'm guessing that LISP does not use pointers.

 

Doing a search on "*" is an excersize in futility.

 

Glen

Posted

Ahh, sorry the confusion.

 

A Global Variable can be any symbol that is not localised in the function definition (the two brackets next to the syntax).

 

I just use more obscure symbols, such as "*load" or "$load" so that they are less likely to clash with variables used by other programs.

 

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