0

How do I store a user dictionary in one file and load the same dictionary at the beginning of another file? This should give the same result as if the dictionary was defined at the top of the same file.

More explicitely: I have written a global dictionary ObjDict, containing several variable and procedure definitions.

!%PS-Adobe-3.0 EPSF-3.0

/ObjDict 30 dict def
ObjDict begin
...
/particle 
{  
     /posy exch def
     /posx exch def
     ...
} bind def
...
end %ObjDict

%%EOF

Now I want to call the procedure particle with the corresponding positions posy posx from a different file, that I want to be created by my simulation program. eg:

!%PS-Adobe-3.0 EPSF-3.0

ObjDict begin
    0.5 0.5 particle
    0.1 0.0 particle
    0.3 0.3 particle
end %ObjDict

%%EOF

Is there a simple way to let the second file know about the dictionary ObjDict defined in the first file? Thanks in advance!

0

This question is probably a better fit on StackOverflow, but it's too old to migrate. Also userdict is a specific dictionary defined by the postscript language; other dictionaries are just called dictionaries or dicts.

It looks like you're trying to make EPS (Encapsulated PostScript) files. EPS files are intended to be self-contained. So they ought not to depend upon data from another file.

To make these regular PostScript, change the first line to

%!

or

%!PS

. Then you can use the run operator to run the file with the dictionary.

  • (filename)   run   -

Also, you have not created a "global" dictionary unless you use true setglobal to change the allocation mode to global. But also be warned that you cannot simply use def with an object allocated in global memory. Objects in global memory cannot be stored in dictionaries or arrays which are in local memory (like userdict). So if you really need a global array, you have to put it in globaldict.

currentglobal
  true setglobal
  globaldict /ObjDict 30 dict put
setglobal

But you probably don't need to use global memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.