Jump to content

Variable in Script


Freerefill

Recommended Posts

I feel completely dense but I can't figure this out.

 

I defined a variable using LISP, nothing fancy, just a list of files. For example,

 

(setq f_lst '("C:/Rec1.dwg" "C:/Rec2.dwg"))

All well and good, but here's my question: Why can't I use that variable in a script file? I wrote the script, there's only one line, nothing fancy:

 

open (car f_lst)

But it doesn't work. I've tried a number of different variations, but either it cannot find the file (I have re-written my list a few times as well, in case I wasn't getting the backslash/forwardslash thing correct) or it hangs up as if waiting for more user input, and if I hit 'enter', it opens up the last file I opened.

 

Can variables not be used in a script? I could imagine an error if that bit of LISP wasn't evaluated, but if I had a script of simply:

 

(car f_lst)

then it -would- return "C:/Rec1.dwg".

 

I really feel like there's something basic that I'm missing and I just spent an hour trying to figure it out. Can anyone help?

Link to comment
Share on other sites

Dave, I did try assigning (car f_lst) to a variable after defining f_lst, and that variable did get defined properly. However, I ran into the same set of problems when I tried to use that variable. This was my initial script.. I took out the variable definition in order to attempt to remove possible errors.

 

(setq f_lst '("C:/Rec1.dwg" "C:/Rec2.dwg") f_opn (car f_lst))
open f_opn

 

Both variables are defined just fine, but no files are opened.

 

And Lee, I know. I had thought that might be my problem so I put a few extra spaces in there. It "worked", a file opened, and I was all excited until I realized that all I was doing was opening the previous file, which would be the equivalent of typing "open" at the command line and hitting "enter" a few times.

Link to comment
Share on other sites

Well that's the first time I've heard the word "namespace" so that's out of my league. Any help on that, Lee?

 

I doubt that I could explain it too well, but how I understand it is that each document object has its own Namespace - and all variables defined in that namespace aren't accessible outside of it (without use of such functions as vl-propagate - or the use of the blackboard namespace using vl-bb-set)

 

Try setting the variable to the blackboard using vl-bb-set and retrieving it in the script using vl-bb-ref. I believe the blackboard namespace lies in the background, separate from the document namespaces, but I could be wrong.

 

Hopefully I understand it correctly,

 

Lee

Link to comment
Share on other sites

I doubt that I could explain it too well, but how I understand it is that each document object has its own Namespace - and all variables defined in that namespace aren't accessible outside of it (without use of such functions as vl-propagate - or the use of the blackboard namespace using vl-bb-set)

 

Try setting the variable to the blackboard using vl-bb-set and retrieving it in the script using vl-bb-ref. I believe the blackboard namespace lies in the background, separate from the document namespaces, but I could be wrong.

 

Hopefully I understand it correctly,

 

Lee

 

I'm not 100% if this is what you meant, never having even looked at those functions before.. but if this is at all correct, it's still not working.

 

(setq f_lst '("C:/Rec2.dwg" "C:/Rec1.dwg"))
(vl-bb-set 'f_opn (car f_lst))
open (vl-bb-ref 'f_opn)

Link to comment
Share on other sites

Try defining it outside of the script, then just reference it in the script - just an idea.

 

Btw, for more on namespaces, look at the help for vl-bb-set in the VLIDE files, they have a link at the bottom for "Sharing Data between Namespaces".

 

Lee

Link to comment
Share on other sites

Still no jollies, Lee. I defined it outside the script and made sure I could reference it. No dice.

 

I'm beginning to think that it's just not evaluating anything after the "open ". That would explain why the filename string itself would work, but no variables or expressions do. And, if that's the case, there's nothing to be done except change the way the script is produced.

Link to comment
Share on other sites

not sure if it will make a difference but do you get the same result using SDI=0 & SDI=1?

 

Good idea Dave - worth a try anyway :)

 

Another thing Mr Refill,

 

How about defining a function, say:

 

(defun test ( )
 (princ "C:\\....")
)

 

And see if it evaluates when within the script:

 

open (test) ...

 

Worth a try anyway.

Link to comment
Share on other sites

The SDI trick did it, but at the cost of forcing the user to only work with a single document. If the user had multiple documents already open, that wouldn't work. But that's cool, I've never touched namespaces or the SDI system variable. Learned two new things ^.^ And namespaces sounds interesting, I'll have to read into that more.

 

If there's no other way to manage it, I'll just try to create a work-around.

 

Thanks a lot for the help, both Dave and Mr. Mac. :)

Link to comment
Share on other sites

I nearly always work in SDI mode - a habit from when networks were unstable and our need to open 500+ drawings in quick succession.

 

We have a script maker to prepare a batch of files for printing and once upon a time I tried to get it to work in MDI mode. It was a distant memory that I could just about hear suggesting that one of the problems was passing on the next file name to the script.

 

Its unusual for my memory to recall anything useful, glad it has finally paid off :)

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