乐筑天下

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

[编程交流] Beginner Question - "command"

[复制链接]

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 04:50:06 | 显示全部楼层 |阅读模式
Hello,
 
At this point, I'm just trying to automate some routine tasks for reliability, so mostly using the "command" function in AutoLISP.  This routine is just intended to shift/rotate/scale from UTM to a local plant grid (a simple three-parameter conversion).  
 
My confusion is that the lines of code work fine individually, but not within the program itself (it creates the selection set just fine, but crashes on the 'move' line).  Am I missing something basic and obvious?  Or is the entire approach, mimicking a manual conversion, flawed?
 
Thank you for your help & insight!
 
  1. (defun c:UTM2KFS()(setq sel1 (ssget "P"))  (command "move" "!sel1" "" "357351.181,5957636.884" "5000,1000")  (command "rotate" "P" "" "5000,1000" "-3d24'54"")  (command "scale" "P" "" "5000,1000" "1.00024606053") (princ))
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-6 05:04:08 | 显示全部楼层
I don't know what you are after but try this modification on the code and let me know .
 
  1. (defun c:UTM2KFS (/ ss i) (if (setq ss (ssget "P"))   (repeat (setq i (sslength ss))     (command "_.move"              (ssname ss (setq i (1- i)))              ""              "357351.181,5957636.884"              "5000,1000"     )     (command "_.rotate" "P" "" "5000,1000" "-3d24'54")     (command "_.scale" "P" "" "5000,1000" "1.00024606053")   ) ) (princ))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 05:14:44 | 显示全部楼层
I hope the following comments help:
  1. ([color=BLUE]defun[/color] c:UTM2KFS ( [color=BLUE]/[/color] sel1 )   [color=GREEN];; Define function, declare local variables.[/color]   [color=GREEN];; To understand why variable localisation is important, see http://bit.ly/15Qw104[/color]      ([color=BLUE]if[/color] [color=GREEN];; If the following expression returns a non-nil value[/color]       ([color=BLUE]setq[/color] sel1 ([color=BLUE]ssget[/color] [color=MAROON]"_P"[/color]))       [color=GREEN];; Attempt to retrieve the Previous selection set and[/color]       [color=GREEN];; assign the selection set to the local variable 'sel1'[/color]       [color=GREEN];; For a full ssget function reference, see http://bit.ly/137NmOJ[/color]       [color=GREEN];; The following command expression is the THEN argument for the IF function:[/color]       ([color=BLUE]command[/color]           [color=GREEN];; Issue the following to the AutoCAD command-line[/color]                      [color=MAROON]"_.move"[/color]           [color=GREEN];; Start the Move command.[/color]           [color=GREEN];; See http://bit.ly/18cyqA3 for the meaning of the command prefixes[/color]           sel1           [color=GREEN];; Supply the move command with the selection set assigned to local variable sel1[/color]           [color=GREEN];; The variable symbol will be evaluated as an argument for the command function,[/color]           [color=GREEN];; yielding the selection set value.[/color]           [color=MAROON]""[/color] [color=GREEN];; Accept the selection (ENTER)[/color]           [color=MAROON]"_non"[/color] [color=GREEN];; Ignore Object Snap for the next prompt (_non = None)[/color]           '(357351.181 5957636.884) [color=GREEN];; Pass the base point[/color]           [color=MAROON]"_non"[/color] [color=GREEN];; Ignore Object Snap[/color]           '(5000 1000) [color=GREEN];; Pass the displacement point[/color]           [color=MAROON]"_.rotate"[/color]           [color=GREEN];; Start the Rotate command.[/color]           [color=GREEN];; (There is no need for a separate command expression)[/color]           sel1 [color=GREEN];; Pass the same selection set of objects[/color]           [color=MAROON]""[/color] [color=GREEN];; Accept the selection[/color]           [color=MAROON]"_non"[/color] [color=GREEN];; Ignore Object Snap[/color]           '(5000 1000) [color=GREEN];; Pass the base point[/color]           3.415 [color=GREEN];; Pass the rotation angle (in degrees)[/color]           [color=MAROON]"_.scale"[/color]           [color=GREEN];; Start the Scale command[/color]           [color=GREEN];; (Again, no need for a separate command expression)[/color]           sel1 [color=GREEN];; Pass the same selection set of objects[/color]           [color=MAROON]""[/color] [color=GREEN];; Accept the selection[/color]           [color=MAROON]"_non"[/color] [color=GREEN];; Ignore Object Snap[/color]           '(5000 1000) [color=GREEN];; Pass the base point[/color]           1.00024606053 [color=GREEN];; Pass the scale factor[/color]                  ) [color=GREEN];; end COMMAND[/color]       [color=GREEN];; The following expression is the ELSE argument for the IF function:[/color]       ([color=BLUE]princ[/color] [color=MAROON]"\nNo previous selection."[/color])       [color=GREEN];; Notify the user that no previous selection set is available[/color]          ) [color=GREEN];; end IF[/color]   ([color=BLUE]princ[/color]) [color=GREEN];; Suppress the return of the last evaluated expression[/color]   ) [color=GREEN];; end DEFUN[/color]
回复

使用道具 举报

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 05:18:54 | 显示全部楼层
Ah if only we could give kudos on this forum, I would have given them in this one.
Commenting like this is so helpful for more than just the one user who is attempting the now-commented routine, I personally enjoy and spend more time with any lisp that is commented like this just in order to see how the functions work together in their lisp-required manner. There will be no Lee Mac "Code Commenting Routine" as I'm pretty sure that real time is spent on any of these commented-on lisps and just wanted to throw my appreciation out there because these are at the top of the useful-to-learning lisp routines that I can find...
In a nutshell, thanks for this helpful lisp........useful, not by application, but by thoroughness of design.
回复

使用道具 举报

2

主题

389

帖子

387

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 05:27:28 | 显示全部楼层
What catches my eye here is that you referred to the selection using an exclamation point (!) prefix.  The exclamation point prefix is used at the command line in AutoCAD when you want to retrieve the value of a variable, but it is not used within AutoLISP, not even in the command function.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-6 05:36:19 | 显示全部楼层
Plus the two strings' marks all around
回复

使用道具 举报

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 05:45:37 | 显示全部楼层
Lee Mac, you're a god!  It worked!  I'll study up to understand all the details.  THANK YOU, THANK YOU, THANK YOU!!! :D:D  (Have actually been banging my head against very similar problem off-and-on for more than a year - celebration!  I think that'll clear up, too!)  THANK YOU!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 05:56:26 | 显示全部楼层
You're very welcome -
I'm glad that the comments help with your understanding and that my time was well invested.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 18:53 , Processed in 0.618444 second(s), 68 queries .

© 2020-2025 乐筑天下

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