Lee Mac 发表于 2022-7-6 11:27:21

这不是问题,你的回答比大多数只接受代码而不从中学习的人要好得多——我只是想给你指出正确的方向:你的方法有缺陷,因为分解/连接方法将引入新的实体,过程变得混乱。

cadman6735 发表于 2022-7-6 11:30:21

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

cadman6735 发表于 2022-7-6 11:32:50

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

jammie 发表于 2022-7-6 11:35:40

只是使用您目前提供的代码。也许这可以给你一些想法作为参考
 
(defun c:TEST ( / ptCATCH )

(if
   ;;Entsel returns a list (<Ename> <Point>)
   (setq pickSelection (entsel))

   (progn

   ;;Extract the <Ename>
   (setq sourceEname (car pickSelection))

   (setq ptCATCH nil)

   (while
(setq ptGET (getpoint "\nPick Point for New Vertices"))
(setq ptCATCH (cons ptGET ptCATCH))
)
   (setq ptCATCH (reverse ptCATCH))

   ;;Store the last object added to the AutoCAD drawing Database
   ;;The next object added will be a segment from the polyone break
   (setq lastEname (entlast))

;===========================================================


(Foreach CATCH ptCATCH

   (command "break" pickSelection "f" CATCH CATCH)

   ;;Get the newly created segment from the break
   (setq nextSegment (entnext lastEname))

   ;;Join the segment to the original polyline
   (command "join"sourceEnamenextSegment "")

   ;;Store this for the next iteration of the looop
   (setq lastEname (entlast))
   )
)      
(princ)
)
)
 
其他成员发布的链接肯定会有助于完成此任务

jammie 发表于 2022-7-6 11:40:33

 
你总结得很好,差不多了

cadman6735 发表于 2022-7-6 11:44:12

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

jammie 发表于 2022-7-6 11:46:15

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

cadman6735 发表于 2022-7-6 11:50:02

 
 
 
 
 
Jammie(我刚刚意识到我把你的名字拼错了,很抱歉)
 
 
关于代码的几个问题
 
第一:
我注意到您正在使用and(if)语句和一个(progn),该语句在(princ)之前结束。为什么?谢谢,因为这让我了解了如何使用(尖头)固定器。你可以把一个完整的程序放在(叉)语句中,我在学习我正在阅读的这本书中的例子时没有掌握这个概念。
 
第二:
我注意到你把(princ)放在(if)语句中。为什么?到目前为止,我只看过节目结束时的(普林斯)。
 
 
我重新编写了您给我的代码,并接受了您的建议,在选择点中断并加入该行(它很有效,我很高兴)。
 
 

(defun c:vertex ( / ptCATCH )

;;Entsel returns a list (<Ename> <Point>)
   (setq pickSelection (entsel))   
;;Extract the <Ename>
   (setq sourceEname (car pickSelection))
;;Break each point at selection
   (while
(setq ptGET (getpoint "\nPick Point for New Vertices"))
       (setq lastEname (entlast))

   (command "break" pickSelection "f" ptGET ptGET)
;;Get the newly created segment from the break
   (setq nextSegment (entnext lastEname))
;;Join the segment to the original polyline
   (command "join"sourceEnamenextSegment "")
;;Store this for the next iteration of the loop
   (setq lastEname (entlast))
)

(princ)
)

jammie 发表于 2022-7-6 11:53:05

李在这个论坛的有用链接部分收集了大量的链接
 
http://www.cadtutor.net/forum/showthread.php?t=49515
 
我建议看一下条件解释下的链接(CAB/Lee Mac)
 
 
 
PROGN允许对多行代码进行评估,以响应IF测试后的肯定或否定评估。
 

;Without PROGN AutoCAD aould evaluate the function as follows

(if

   ;Test
   (setq pickSelection (entsel))
   ;Positive result
   (setq sourceEname (car pickSelection))
   ;Negative result
    (setq ptCATCH nil)
   ;Unexpected additional arguments suplied. Error will be created here
   (while...
 
 
 
 
这仅仅是为了给IF statemet带来负面结果。这是没有必要的。
可能更恰当地使用princ是在未选择对象时提示用户
 
(defun c:TEST ( / ptCATCH )

(if
   ;Test
   (setq pickSelection (entsel))

;Positive result
   (progn
   
   (setq sourceEname ...)
)   

;Negative result
   (princ "\nNo Object selected)
)
)
 
如果我没有很好地解释这些项目,请道歉

jammie 发表于 2022-7-6 11:55:01

 
 
代码使用得很好!作为一个想法,我在其中添加了4条额外的线,以允许在拾取点时显示选定对象的顶点夹点
 

(defun c:vertex ( / ptCATCH pickSelection sourceEname ptGET lastEname nextSegment tempSelectionSet)

(command "Undo" "BEgin")
;;Entsel returns a list (<Ename> <Point>)
   (setq pickSelection (entsel))   
;;Extract the <Ename>
   (setq sourceEname (car pickSelection))

;Create a temporary selection set
   (setq tempSelectionSet (ssadd))
;Add the picked ojbect to it
   (SSADD sourceEname tempSelectionSet)
   

;;Break each point at selection
   (while
(progn
;Turn on grips
(sssetfirst NIL tempSelectionSet )
(setq ptGET (getpoint "\nPick Point for New Vertices"))
)
       (setq lastEname (entlast))

   (command "break" pickSelection "f" ptGET ptGET)
;;Get the newly created segment from the break
   (setq nextSegment (entnext lastEname))
;;Join the segment to the original polyline
   (command "join"sourceEnamenextSegment "")
;;Store this for the next iteration of the loop
   (setq lastEname (entlast))

)

;Turn off grips
(sssetfirst tempSelectionSet)
(command "Undo" "End")
(princ)
)
 
为了进一步理解条件句,可以尝试将IF语句合并到代码中,它只允许选择某些对象。否则,当选择某些对象(如插入等)时,例程可能会产生错误。。。
页: 1 [2]
查看完整版本: ?每个顶点?