Jump to content

Calling a variable from a Script?


Recommended Posts

Brand new at writing a script. My question is, is it possible to create a variables (A, B, C, etc) within autocad and call those variables within a script?

 

I've been able to write a script that generates an entity using Pline command that traces points within a .dat file, then scales that entity. The script also adds a small amount of text. I'd like to be able to call the scale factor and the text from variables.

 

For now I'd like to stay with the scripting language, if possible.

 

Not sure if I've explained this correctly or not, as I said, I'm just learning this so any help would be appreciated.

 

Don

Link to comment
Share on other sites

You can use the user system variables USERI1-5 (to store integrs) or USERR1-5 (for decimals):

_SETVAR USERI1 3
_PLINE 0.0,0.0 _W (getvar "USERI1")  50.0,50.0 
;end of script

_SETVAR USERR1 3.75
_PLINE 0.0,0.0 _W (getvar "USERR1")  50.0,50.0 
;end of script

Link to comment
Share on other sites

Thank for the quick reply Mircea. I've been able to populate the variables both from the command line and from within the script. This I've verified from the command line. Ultimately what I want to be able to do is populate several of the from the command line and then call them up from within the script.

 

But I can't get the "getvar" line to work at all. I'll try to post a snippet of code here. Very simple....populate a variable...draw a line...and attempt to scale that line using the contents of the variable. Feeling a little dense here...:oops:

 

_SETVAR USERI1 3
_LINE
0.0,2.0
2.0,2.0

_scale
0.0,2.0

0.0,2.0
_getvar useri1

;end of script

 

BTW...this code works if I just insert a numerical scale factor in place of the getvar statement....

Edited by DEG
added more detail
Link to comment
Share on other sites

I'm pretty sure I did but let me go try it again with that in mind.......BRB

 

Didn't work....Here's what the Command Window says....

SETVAR SETVARIABLE

Default: SETUSRRL1

Options: ? or

Variable name» USERI1

Default: 16

Enter new value for SETUSRINT1» 16

:

_LINE

Options: Segments, Enter to continue from last point or

Specify start point» 0.0,0.0

Options: Segments, Undo, Enter to exit or

Specify next point» 0,2

Options: Segments, Undo, Enter to exit or

Specify next point»

:

scale

Specify entities» 0,0

1 found, 1 total

Specify entities»

Specify base point» 0,0

Options: Reference or

Specify scale factor» _(getvar

Requires valid numeric distance or second point, or option keyword.

Options: Reference or

Specify scale factor» "useri1")

Requires valid numeric distance or second point, or option keyword.

Options: Reference or

Specify scale factor»

And here is the revised code...

 

Osnap
none
SETVAR USERI1 16
_LINE 
0.0,0.0
0,2

scale
0,0

0,0
_(getvar "useri1")

;end of script

Link to comment
Share on other sites

I spotted two issues into the script you posted:

Osnap
none
SETVAR USERI1 16
_LINE 
0.0,0.0
0,2[color=red]
<-- there is an extra space[/color]
scale
0,0

0,0
[color=red]_[/color](getvar "useri1")[color=red]<-- remove the underline[/color]
[color=red] <-- there is an extra space and line[/color]
;end of script

Your profile read AutoCAD full; please don't miss that if is LT in fact, then the AutoLISP statement will not work!

Link to comment
Share on other sites

Another comment, if you simulate pick in order to get the item to scale, in some circumstances this operation may fail or get a wrong entity; since the line you are willing to process is the last drawn entity, may use the Last selection mode instead:

...
_SCALE
[color=magenta]_L[/color]

0.0,0.0
...

Link to comment
Share on other sites

I do use full version 2005 but at home I have Draftsight. That's the program I've been using this script on......So, I scooted down to work and tried this on my Acad2005 and it worked with the changes you outlined above. I'll finish up this script and just use it at work. Thanks for your input and sorry to be so dense but this is new to me....Thank you all

 

Don

Link to comment
Share on other sites

Just saw your last post and that's an great idea as I've only been picking one point...I still have a lot to learn of the conventions with script...Thanks again Mircea.....

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