乐筑天下

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

[编程交流] What's wrong with this LI

[复制链接]

8

主题

38

帖子

30

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 15:38:51 | 显示全部楼层 |阅读模式
I pieced together this routine which draws a line from its midpoint..
I added error handler and echo off...
 
The LISP executes fine but it gives me an "; error: AutoCAD variable setting rejected: CMDECHO nil" message... not sure how to fix it. It also spits out some coordinates at the end of the routine that I'd like to get rid of (which echo off should take care of right?)
 
Currently it allows me to pick a point and displays the default dashed rubber band/cursor tracer line. I would like for it to be dynamic where it shows the preview of the actual line in both directions from starting point and the rubber band/tracer line as well... Similar to when you draw a circle and type "D" for diameter: it shows a preview of said circle and the rubber band/tracer line extends past it the length of the radius...
 
Thanks in advance...
 
One last thing... I'm super new at LISPing so please be as detailed as possible... Thanks again
MidLine LISP:
  1. (defun c:MidLine (/ *error* pt1 pt1w pt2 pt2w pt0 ang len ed)(defun *error* ( msg )       (if ocmd (setvar 'CMDECHO ocmd))       (if acdoc (_EndUndoMark acdoc))       (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))           (princ (strcat "\nError: " msg))       )       (princ)   )   (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))   (_StartUndoMark acdoc)   (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))   (_StartUndoMark acdoc)   (setq ocmd (getvar 'CMDECHO))   (setvar 'CMDECHO 0) (setq pt1 (getpoint "\nMIDLINE Specify midpoint of line: "))   (setq pt1w (trans pt1 1 0)         pt2  (getpoint pt1 "\nMIDLINE Specify endpoint of line: ")         pt2w (trans pt2 1 0)   )   (setq ang (angle pt2w pt1w))   (setq len (/ (distance pt1w pt2w) 2.0))   (setq pt0 (polar pt1w ang len))   (setq ang (angle pt1w pt2w))   (setq pt2 (polar pt1w ang len))   (setq ed (list '(0 . "LINE") (cons 10 pt0) (cons 11 pt2)))   (entmake ed) )(defun _StartUndoMark ( doc )   (_EndUndoMark doc)   (vla-StartUndoMark doc))(defun _EndUndoMark ( doc )   (if (= 8 (logand 8 (getvar 'UNDOCTL)))       (vla-EndUndoMark doc)   ))   (setvar 'CMDECHO ocmd)   (_EndUndoMark acdoc)(princ)
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 15:45:51 | 显示全部楼层
I would add some force osnaps "_mid" or use osmode variables get existing osmode then set for MID & END
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 15:50:08 | 显示全部楼层
Hi,
Not sure if this goal if the program is what you are after but its as per your original codes.
 
Besides that, this is just for your learning and its more than enough.
 
  1. (defun c:midline (/ pt1 pt1w pt2 pt2w pt0 ang len) (and (setq pt1 (getpoint "\nMIDLINE Specify midpoint of line: "))      (setq pt2 (getpoint pt1 "\nMIDLINE Specify endpoint of line: "))      (setq pt1w (trans pt1 1 0))      (setq pt2w (trans pt2 1 0))      (setq ang (angle pt2w pt1w))      (setq len (/ (distance pt1w pt2w) 2.0))      (setq pt0 (polar pt1w ang len))      (setq ang (angle pt1w pt2w))      (setq pt2 (polar pt1w ang len))      (entmake (list '(0 . "LINE") (cons 10 pt0) (cons 11 pt2)))      ) (princ))
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 15:54:48 | 显示全部楼层
Note that the _EndUndoMark subfunction should be wrapped within a while loop, so substitute the if function with while - it was explained somewhere why (so I won't bother).
回复

使用道具 举报

8

主题

38

帖子

30

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 15:56:15 | 显示全部楼层
Thanks for the responses...
 
You got rid of the weird coordinates it was displaying... GREAT! Thank you!.....
 
Now how do I properly add error handling and echo off? and how do i make it display a dynamic preview of the line to be drawn as described above?
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 16:02:45 | 显示全部楼层
 
You are welcome.
 
 
Can you please answer the following questions?
 
1- Why do you want to use error handler function ?
2- What's the use of system variable 'CMDECHO and why do you want use it with that simple routine?
回复

使用道具 举报

8

主题

38

帖子

30

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 16:03:15 | 显示全部楼层
I guess I don't need CMDECHO for your simplified version since it stopped displaying those weird coordinates... as for error handling: so that it won't display the "error; function cancelled" message if I press escape key mid command..
I was just under the impression that these two elements are standard procedure when LISPing... forgive my ignorance if that's completely false but...
Ultimately the routine works as intended... I'm just trying to fine tune it to my preference and to try to grasp some of the concepts of this awesome programming language
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 16:07:11 | 显示全部楼层
 
If you add the princ function at the end then this should prevent that to happen.
 
 
Yes you can add the error handler but if you want to cancel the command from continuing then a sample hit on the space bar or enter should exit the command quietly and safely.
 
No worries, you are doing just well with your initial believes & thoughts about programming.
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-5 16:11:16 | 显示全部楼层
Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE]
  1. Your Code Here[/NOPARSE]
=
  1. Your Code Here
回复

使用道具 举报

8

主题

38

帖子

30

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 16:15:03 | 显示全部楼层
Upon further research I discovered that i need to add GRREAD to my code in order to get a dynamic preview of the line... I just don't have a clue how to incorporate it and have it display the line dynamically in both directions from starting mid-point. Any insight on this would be greatly appreciated.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-1 11:29 , Processed in 0.276190 second(s), 73 queries .

© 2020-2025 乐筑天下

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