Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

set variable value for a drawing

16 REPLIES 16
Reply
Message 1 of 17
Anonymous
955 Views, 16 Replies

set variable value for a drawing

Is there a way that I can set a variable specifically for a drawing once,
and be able to access the value of that variable in a LISP routine at any
point in that drawing after that even if the drawing has been closed and
re-opened?
16 REPLIES 16
Message 2 of 17
Anonymous
in reply to: Anonymous

I think you could use a block with attributes ans using a lisp routine, read
and write values.


KBern wrote in message ...
>Is there a way that I can set a variable specifically for a drawing once,
>and be able to access the value of that variable in a LISP routine at any
>point in that drawing after that even if the drawing has been closed and
>re-opened?
>
>
Message 3 of 17
Anonymous
in reply to: Anonymous

Look at the USER variables. See the help files

"KBern" wrote in message
news:AC399656DE8FACB3D98F0CD417014846@in.WebX.maYIadrTaRb...
> Is there a way that I can set a variable specifically for a drawing once,
> and be able to access the value of that variable in a LISP routine at any
> point in that drawing after that even if the drawing has been closed and
> re-opened?
>
>
Message 4 of 17
Anonymous
in reply to: Anonymous

USER variables can be reset by other programs or users. You probably would
want to use a dictionary to store it.

"KBern" wrote in message
news:AC399656DE8FACB3D98F0CD417014846@in.WebX.maYIadrTaRb...
| Is there a way that I can set a variable specifically for a drawing once,
| and be able to access the value of that variable in a LISP routine at any
| point in that drawing after that even if the drawing has been closed and
| re-opened?
|
|
Message 5 of 17
Anonymous
in reply to: Anonymous

Some ways I can think of?
1. Use one of the built in variables
userr1-5, 5 variables for real numbers
useri1-5, 5 variables for integers
users1-5, 5 variables for strings
Disadvantages: Conflict between applications. Who owns these variables?
2. XRECORD
3. Use an external file(read and write with file i/o)
Advantages: Can reference the same data between drawings.
Disadvatages: File management of extra files.
4. XDATA
Must attach the data to a drawn object.
5. Define a block with the data as text
Disadvantage: Can be purged unless referenced. So it must be inserted.
6. Use a block with attributes
7. Persistent reactors? Don't know much about these.

Doug Broad

"KBern" wrote in message
news:AC399656DE8FACB3D98F0CD417014846@in.WebX.maYIadrTaRb...
> Is there a way that I can set a variable specifically for a drawing once,
> and be able to access the value of that variable in a LISP routine at any
> point in that drawing after that even if the drawing has been closed and
> re-opened?
>
>
Message 6 of 17
Anonymous
in reply to: Anonymous

The user variable is only stored in the same session of autocad. If you come
back to that drawing a week later it won't be there. How about using
xrecords?

"Doug Kidd" wrote in message
news:D8485A04B11A7B9E632847FF2FB077AA@in.WebX.maYIadrTaRb...
> Look at the USER variables. See the help files
>
> "KBern" wrote in message
> news:AC399656DE8FACB3D98F0CD417014846@in.WebX.maYIadrTaRb...
> > Is there a way that I can set a variable specifically for a drawing
once,
> > and be able to access the value of that variable in a LISP routine at
any
> > point in that drawing after that even if the drawing has been closed and
> > re-opened?
> >
> >
>
>
Message 7 of 17
Anonymous
in reply to: Anonymous

I was referring to USERI1-5, R1-5 AND S1-5. Sorry I wasn't clearer.

"Paul D" wrote in message
news:4E2622101BF4D0280AEAAD89AA18E5D4@in.WebX.maYIadrTaRb...
> The user variable is only stored in the same session of autocad. If you
come
> back to that drawing a week later it won't be there. How about using
> xrecords?
>
> "Doug Kidd" wrote in message
> news:D8485A04B11A7B9E632847FF2FB077AA@in.WebX.maYIadrTaRb...
> > Look at the USER variables. See the help files
> >
> > "KBern" wrote in message
> > news:AC399656DE8FACB3D98F0CD417014846@in.WebX.maYIadrTaRb...
> > > Is there a way that I can set a variable specifically for a drawing
> once,
> > > and be able to access the value of that variable in a LISP routine at
> any
> > > point in that drawing after that even if the drawing has been closed
and
> > > re-opened?
> > >
> > >
> >
> >
>
>
Message 8 of 17
Anonymous
in reply to: Anonymous

Can I do this in LISP??
Message 9 of 17
Anonymous
in reply to: Anonymous

Doug,
Could I somehow create a dictionary file that would house the settings for
each file that requires this variable to be set? I guess I would need code
that would access this dictionary and know which file is open so it could
retrieve the correct value from the dictionary. I really don't know if this
is possible, but if it is I would love to hear how I could do it. I really
only know LISP, so this puts me at a disadvantage here.

Kyle Bernhardt
Message 10 of 17
Anonymous
in reply to: Anonymous

I dont see the USERR1 and USERS1 variables being used too often. Which means
you dont have to worry about them being reset.
I would use USERR1 to store Reals, and USERS1 to store STrings.
Like this:
----------------------
Command: (setvar "users1" "Hey man")
"Hey man"

Command: (getvar "users1")
"Hey man"
--------------------------
Thats the simplest way, and you can store 5 strings and 5 reals in each
drawing.
Need more? Try X Data.


"KBern" wrote in message
news:f06fc96.6@WebX.maYIadrTaRb...
> Can I do this in LISP??
>
>
Message 11 of 17
Anonymous
in reply to: Anonymous

I used to use the USERxx variables to store the drawing setup data. A couple
of years ago, some drawings started returning from the vendor with some of
these variables changed. I quickly switched to using a dictionary upon
discovering this.

Tony
Message 12 of 17
Anonymous
in reply to: Anonymous

Kyle:

Here's what I use...

To save your data:

(VLAX-LDATA-PUT "YourDictName" "SAVEDVAR1" variable1)
(VLAX-LDATA-PUT "YourDictName" "SAVEDVAR2" variable2)
(VLAX-LDATA-PUT "YourDictName" "SAVEDVAR3" variable3)

Where:

"YourDictName" would be a unique name for your dictionary
"SAVEDVARx" would be a meaningful name for the data
variablex would be your LISP variable

To retrieve the data:

(SETQ variable1 (VLAX-LDATA-GET "YourDictName" "SAVEDVAR1"))
(SETQ variable2 (VLAX-LDATA-GET "YourDictName" "SAVEDVAR2"))
(SETQ variable3 (VLAX-LDATA-GET "YourDictName" "SAVEDVAR3"))

Tony
Message 13 of 17
Anonymous
in reply to: Anonymous

Anthony Dawe has answered your question if what you want is to save a variable within each
file. If you want to create an external file to coordinate multiple drawings, you can use the
following functions:
(open filename mode) filename=string, mode="w" or "r" or "a"
for Write, Read or Append
This function returns a file handle (if successful)

(princ expression filehandle) used to send info to file line by line
Use "\n" character to start a new line
Expression can be a string, symbol, list....
Other printing functions work also.

(read-line filehandle) used to retrieve info from file
sequential access only. You need to establish a format or order.

(read string) used to translate string into lisp expression
returns the evaluation of the string into an exression

(close filehandle) necessary to do each time file is opened after done with it.

(findfile string) returns a fully qualifed filename if successful.

For example, you could save a "very simplified" version of the layer table with:
(tblobjname must be used for the complete layer table)

(setq fh (open "layers.lay" "w"))
(setq lay (tblnext "layer" t))
(while lay
(princ lay fh)
(setq lay (tblnext "layer"))
)
(close fh)

And to restore or rebuild the layer table
(setq fh (open "layers.lay" "r"))
(while (and (setq lays (read-line fh))
(setq lays (read lays))
(setq layc (cdr(assoc 67 lays))) ;color
(setq layl (cdr(assoc 6 lays))) ;linetype
(setq layn (cdr(assoc 2 lays))) ;name
....etc
) ;and
(command "layer" "c" layc layn) ;color
(command "lt" layl layn)
....etc
);while ...
(close fh)

Be careful about choosing extensions for your data files. Of course TXT is the
simplest since you can use notepad to examine them by just clicking on them. If you use any
other extension, you must inform the operating system which application you need to launch when
you double click on the file.

Pardon this over simplified explanation and example. You can set up the dictionary format in a
variety of forms but association lists can be written and read from files most easily. Each
line of the file could be an atom or list or a pointer to the number of lines to skip.


Doug Broad

"KBern" wrote in message
news:91B639C116723205702A1471E9ACFCD6@in.WebX.maYIadrTaRb...
> Doug,
> Could I somehow create a dictionary file that would house the settings for
> each file that requires this variable to be set? I guess I would need code
> that would access this dictionary and know which file is open so it could
> retrieve the correct value from the dictionary. I really don't know if this
> is possible, but if it is I would love to hear how I could do it. I really
> only know LISP, so this puts me at a disadvantage here.
>
> Kyle Bernhardt
>
>
Message 14 of 17
Anonymous
in reply to: Anonymous

I see how this would work great, except I don't know how top use this with
my code knowledge (no ARX). I use this in a LISP command and I get a "no
function definition" error. What am I doing wrong here?

"Anthony Dawe" wrote in message
news:4FDCEF02935825134A2761CD0388731F@in.WebX.maYIadrTaRb...
> Kyle:
>
> Here's what I use...
>
> To save your data:
>
> (VLAX-LDATA-PUT "YourDictName" "SAVEDVAR1" variable1)
> (VLAX-LDATA-PUT "YourDictName" "SAVEDVAR2" variable2)
> (VLAX-LDATA-PUT "YourDictName" "SAVEDVAR3" variable3)
>
> Where:
>
> "YourDictName" would be a unique name for your dictionary
> "SAVEDVARx" would be a meaningful name for the data
> variablex would be your LISP variable
>
> To retrieve the data:
>
> (SETQ variable1 (VLAX-LDATA-GET "YourDictName" "SAVEDVAR1"))
> (SETQ variable2 (VLAX-LDATA-GET "YourDictName" "SAVEDVAR2"))
> (SETQ variable3 (VLAX-LDATA-GET "YourDictName" "SAVEDVAR3"))
>
> Tony
>
>
Message 15 of 17
Anonymous
in reply to: Anonymous

Kyle:

Sorry for the delayed reply....Been on vacation...

What version of AutoCAD are you using? I'm doing this in AutoCAD 2000 and
2000i.

The functions are a part of the ActiveX functions available in LISP. Before
using these functions, you MUST load ActiveX support by issuing the
(vl-load-com) function. See chapter 6 of the Visual LISP Developers guide
(Working with ActiveX; Accessing AutoCAD Objects).

Tony
Message 16 of 17
Anonymous
in reply to: Anonymous

Where do I find the AutoCAD LT 2002 autolisp file?....actually I want to
modify the exsiting lisp how do I do that?

To my understanding, for all AutoCAD LT software they require a visual basic
program to edit the lisp, it that true?cause this is my first time using
ACAD LT 2002 software..

pls help,
Lucasraj


"Anthony Dawe" wrote in message
news:378256F759E23276593586F22DEFBB7D@in.WebX.maYIadrTaRb...
> Kyle:
>
> Sorry for the delayed reply....Been on vacation...
>
> What version of AutoCAD are you using? I'm doing this in AutoCAD 2000 and
> 2000i.
>
> The functions are a part of the ActiveX functions available in LISP.
Before
> using these functions, you MUST load ActiveX support by issuing the
> (vl-load-com) function. See chapter 6 of the Visual LISP Developers guide
> (Working with ActiveX; Accessing AutoCAD Objects).
>
> Tony
>
>
>
Message 17 of 17
Anonymous
in reply to: Anonymous

I've never had access to AutoCAD LT, so I can't be much help with that. I
don't believe that LISP or other customizing languages are 'officially'
available with the LT versions.

Tony

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost