乐筑天下

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

[编程交流] ?每个顶点?

[复制链接]

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:27:21 | 显示全部楼层
这不是问题,你的回答比大多数只接受代码而不从中学习的人要好得多——我只是想给你指出正确的方向:你的方法有缺陷,因为分解/连接方法将引入新的实体,过程变得混乱。
回复

使用道具 举报

23

主题

117

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
123
发表于 2022-7-6 11:30:21 | 显示全部楼层
 
 
 
杰米
 
现在对我来说有意义了。但我想确保我能理解。
 
我的列表就是这个列表。
(foreach)后面的“a”是从MyList中提取的每个列表项的临时保留,这些列表项将由函数(princ(+a 5))进行评估或使用
 
“a”只不过是(1)要建造的临时房屋
然后它成为(2)要处理的临时房屋,然后“a”是(3)要处理的临时房屋,依此类推?
 
如果我在这里是正确的,我想我明白了。
 
谢谢
回复

使用道具 举报

23

主题

117

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
123
发表于 2022-7-6 11:32:50 | 显示全部楼层
 
 
 
我的功能有缺陷(所以我开始发现),非常混乱,但我确实学到了一些东西。我将继续努力。
 
再次感谢,
 
 
 
我刚刚理解了你对我说的“将引入新实体”,当polly元素被破坏时,一个新实体被创建
 
 
所以当连接被连接回来时,我仍然有两个实体,但是连接了?他们不会回到一个entname?我知道这会造成什么问题。。。嗯。。。。。
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 11:35:40 | 显示全部楼层
只是使用您目前提供的代码。也许这可以给你一些想法作为参考
 
  1. (defun c:TEST ( / ptCATCH )
  2. (if
  3.    ;;Entsel returns a list (<Ename> <Point>)
  4.    (setq pickSelection (entsel))
  5.    (progn
  6.      ;;Extract the <Ename>
  7.      (setq sourceEname (car pickSelection))
  8.      (setq ptCATCH nil)
  9.      (while
  10. (setq ptGET (getpoint "\nPick Point for New Vertices"))
  11. (setq ptCATCH (cons ptGET ptCATCH))
  12. )
  13.      (setq ptCATCH (reverse ptCATCH))
  14.      ;;Store the last object added to the AutoCAD drawing Database
  15.      ;;The next object added will be a segment from the polyone break
  16.      (setq lastEname (entlast))
  17. ;===========================================================
  18. (Foreach CATCH ptCATCH
  19.    (command "break" pickSelection "f" CATCH CATCH)
  20.    ;;Get the newly created segment from the break
  21.    (setq nextSegment (entnext lastEname))
  22.    ;;Join the segment to the original polyline
  23.    (command "join"  sourceEname  nextSegment "")
  24.    ;;Store this for the next iteration of the looop
  25.    (setq lastEname (entlast))
  26.    )
  27.   )      
  28. (princ)
  29. )
  30. )

 
其他成员发布的链接肯定会有助于完成此任务
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 11:40:33 | 显示全部楼层
 
你总结得很好,差不多了
回复

使用道具 举报

23

主题

117

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
123
发表于 2022-7-6 11:44:12 | 显示全部楼层
 
 
 
 
超级酷
 
谢谢Jamee
 
在阅读了李·麦克关于我的方法存在缺陷的帖子后,你确实按照我的想法编写了代码,并将引入新的实体。但有点不知所措,从哪里开始。
唯一让我头疼的是,我没有写,你只花了一个小时(或者更少,我不知道)就完成了。J
你从我这里得到五颗星。我会研究这个代码
 
谢谢你的帮助。
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 11:46:15 | 显示全部楼层
你的欢迎
 
这实际上是我的学习曲线。我假设通过将一个对象一分为二,原始对象被删除&两个新实体被添加到数据库中。通过观察,AutoCAD保留分割点之前的原始图元,并在分割点之后向数据库添加新对象。
 
不要担心编码速度有多快。更重要的是,你要明白自己在做什么&为什么。
 
为了进一步改进代码,请考虑进行测试以确保选择了多段线。
 
也可以考虑一种不同的代码逻辑方法。为什么不拆分并加入polyine,因为您正在拾取点?这将消除代码的每一部分&可能不再需要在ptCATCH中存储点
 
值得深思。快乐的编码!
回复

使用道具 举报

23

主题

117

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
123
发表于 2022-7-6 11:50:02 | 显示全部楼层
 
 
 
 
 
Jammie(我刚刚意识到我把你的名字拼错了,很抱歉)
 
 
关于代码的几个问题
 
第一:
我注意到您正在使用and(if)语句和一个(progn),该语句在(princ)之前结束。为什么?谢谢,因为这让我了解了如何使用(尖头)固定器。你可以把一个完整的程序放在(叉)语句中,我在学习我正在阅读的这本书中的例子时没有掌握这个概念。
 
第二:
我注意到你把(princ)放在(if)语句中。为什么?到目前为止,我只看过节目结束时的(普林斯)。
 
 
我重新编写了您给我的代码,并接受了您的建议,在选择点中断并加入该行(它很有效,我很高兴)。
 
 
  1. (defun c:vertex ( / ptCATCH )
  2. ;;Entsel returns a list (<Ename> <Point>)
  3.    (setq pickSelection (entsel))   
  4. ;;Extract the <Ename>
  5.      (setq sourceEname (car pickSelection))
  6. ;;Break each point at selection
  7.      (while
  8. (setq ptGET (getpoint "\nPick Point for New Vertices"))
  9.        (setq lastEname (entlast))
  10.    (command "break" pickSelection "f" ptGET ptGET)
  11. ;;Get the newly created segment from the break
  12.    (setq nextSegment (entnext lastEname))
  13. ;;Join the segment to the original polyline
  14.    (command "join"  sourceEname  nextSegment "")
  15. ;;Store this for the next iteration of the loop
  16.    (setq lastEname (entlast))
  17. )
  18. (princ)
  19. )
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 11:53:05 | 显示全部楼层
李在这个论坛的有用链接部分收集了大量的链接
 
http://www.cadtutor.net/forum/showthread.php?t=49515
 
我建议看一下条件解释下的链接(CAB/Lee Mac)
 
 
 
PROGN允许对多行代码进行评估,以响应IF测试后的肯定或否定评估。
 
  1. ;Without PROGN AutoCAD aould evaluate the function as follows
  2. (if
  3.   
  4.    ;Test
  5.    (setq pickSelection (entsel))
  6.    ;Positive result
  7.    (setq sourceEname (car pickSelection))
  8.    ;Negative result
  9.     (setq ptCATCH nil)
  10.    ;Unexpected additional arguments suplied. Error will be created here
  11.    (while...

 
 
 
 
这仅仅是为了给IF statemet带来负面结果。这是没有必要的。
可能更恰当地使用princ是在未选择对象时提示用户
 
  1. (defun c:TEST ( / ptCATCH )
  2. (if
  3.    ;Test
  4.    (setq pickSelection (entsel))
  5. ;Positive result
  6.    (progn
  7.    
  8.      (setq sourceEname ...)
  9.   )     
  10. ;Negative result
  11.    (princ "\nNo Object selected)
  12. )
  13. )

 
如果我没有很好地解释这些项目,请道歉
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 11:55:01 | 显示全部楼层
 
 
代码使用得很好!作为一个想法,我在其中添加了4条额外的线,以允许在拾取点时显示选定对象的顶点夹点
 
  1. (defun c:vertex ( / ptCATCH pickSelection sourceEname ptGET lastEname nextSegment tempSelectionSet)
  2. (command "Undo" "BEgin")
  3. ;;Entsel returns a list (<Ename> <Point>)
  4.    (setq pickSelection (entsel))   
  5. ;;Extract the <Ename>
  6.      (setq sourceEname (car pickSelection))
  7. ;Create a temporary selection set
  8.      (setq tempSelectionSet (ssadd))
  9. ;Add the picked ojbect to it
  10.      (SSADD sourceEname tempSelectionSet)
  11.      
  12. ;;Break each point at selection
  13.      (while
  14. (progn
  15.   ;Turn on grips
  16.   (sssetfirst NIL tempSelectionSet )
  17.   (setq ptGET (getpoint "\nPick Point for New Vertices"))
  18.   )
  19.        (setq lastEname (entlast))
  20.    (command "break" pickSelection "f" ptGET ptGET)
  21. ;;Get the newly created segment from the break
  22.    (setq nextSegment (entnext lastEname))
  23. ;;Join the segment to the original polyline
  24.    (command "join"  sourceEname  nextSegment "")
  25. ;;Store this for the next iteration of the loop
  26.    (setq lastEname (entlast))
  27. )
  28. ;Turn off grips
  29. (sssetfirst tempSelectionSet)
  30. (command "Undo" "End")
  31. (princ)
  32. )

 
为了进一步理解条件句,可以尝试将IF语句合并到代码中,它只允许选择某些对象。否则,当选择某些对象(如插入等)时,例程可能会产生错误。。。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 12:05 , Processed in 0.922421 second(s), 70 queries .

© 2020-2025 乐筑天下

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