乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 43|回复: 4

[编程交流] [Solved] - Setvar error

[复制链接]

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 11:15:19 | 显示全部楼层 |阅读模式
I was having some trouble with a very simple setvar command in a lisp script, as such:
 
  1. (setvar "FIELDEVAL" "31");
 
which was giving me this error:
  1. AutoCADvariable setting rejected: "CMDECHO" nil
 
It turns out that you cannot have quotes around the 31, and that it should have read:
 
  1. (setvar "FIELDEVAL" 31); This is fixed now
 
I looked through my code and found places where I had used quotes to enclose variables, so maybe you can do it with some variables and not others?  Does anybody have any input on this?  
 
For example, this seemed to work:
  1. (setvar "TEXTSTYLE" "Some-Style");
 
Hopefully this helps somebody in the future.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:42:45 | 显示全部楼层
System Variables are of different data types whether it be Double, Integer, String, etc.
 
A reference for these can be found using the System variable editor (Sysvdlg) in AutoCAD, or another reference such as this.
 
As for the error you are receiving, that is due to an unlocalised error handler within a routine loaded on your system.
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
438
发表于 2022-7-6 11:53:47 | 显示全部楼层
The best policy for you error handler (after making sure it's localized) would be to check and make sure the the variable has a value before trying to set a variable with said value.
 
eg.
At some point in time in the routine.
  1. (setq OldCmdecho (getvar 'cmdecho))
In your error handler, you would check before trying to set with:
  1. (if OldCmdecho (setvar 'cmdecho OldCmdecho))
or
  1. (and OldCmdecho (setvar 'cmdecho OldCmdecho))
Both will check the variable before trying to set with it.
 
There are other fancier ways, but these are the simplest.
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-6 12:10:18 | 显示全部楼层
To be able to ignore the data type of a system variable may use the below approach that will allow you to use only strings:
 
  1. [color=black](command "_SETVAR" "FIELDEVAL" "31")[/color]
Regards,
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 12:22:46 | 显示全部楼层
If you are unsure as to what type of value a system variable accepts you could use the TYPE function
  1. Command: (type (getvar "TEXTSTYLE"))STRCommand: (type (getvar "filletrad"))REALCommand: (type (getvar "FIELDEVAL"))INTCommand: (type (getvar "lastpoint"))LIST
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-6 11:42 , Processed in 1.063978 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表