offloading 发表于 2009-2-7 09:42:00

[求助]自动修剪

<p>各位友人:如何实现,自动修剪,只保留矩形内线段!烦请给个例子吧!</p><p></p>

robbin840311 发表于 2009-2-8 11:52:00

顶,顶!

mary_99w 发表于 2009-2-13 17:05:00

<p>这个简单,不知道你解决了没有,首先选定那个矩形,然后发送截断命令,用栏选,选取四个点比矩形大的四个点,就是再建一个矩形。 Set AcadApp = GetObject(, "AutoCAD.Application")<br/>On Error GoTo ert<br/>&nbsp; startpnt = AcadApp.ActiveDocument.Utility.GetPoint(, vbCrLf + "正在准备标注点" &amp; j &amp; "请输入点位:")<br/>insertionpnt1(0) = startpnt(0) - 0.5: insertionpnt1(1) = startpnt(1) - 0.5: insertionpnt1(2) = startpnt(2):<br/>Set obj_Text1 = AcadApp.ActiveDocument.ModelSpace.AddText(j, insertionpnt1, 1)<br/>Set cice = AcadApp.ActiveDocument.ModelSpace.AddCircle(startpnt, rad)<br/>Dim ae As AcadObject<br/>ad = cice.Handle<br/>Dim at As String<br/>Set ab = AcadApp.ActiveDocument.ModelSpace.AddCircle(startpnt, rad)<br/>point1(0) = startpnt(0): point1(1) = startpnt(1) - 1: point1(2) = startpnt(2)<br/>point2(0) = startpnt(0) - 1: point2(1) = startpnt(1): point2(2) = startpnt(2)<br/>point3(0) = startpnt(0): point3(1) = startpnt(1) + 1: point3(2) = startpnt(2)<br/>point4(0) = startpnt(0) + 1: point4(1) = startpnt(1): point4(2) = startpnt(2)<br/>Text1 = point1(0) &amp; "," &amp; point1(1)<br/>Text2 = point2(0) &amp; "," &amp; point2(1)<br/>Text3 = point3(0) &amp; "," &amp; point3(1)<br/>Text4 = point4(0) &amp; "," &amp; point4(1)<br/>Set ae = AcadApp.ActiveDocument.HandleToObject(ad)<br/>at = "(handent " &amp; Chr(34) &amp; ad &amp; Chr(34) &amp; ")"<br/>AcadApp.ActiveDocument.SendCommand "_trim" &amp; vbCr &amp; at &amp; vbCr &amp; vbCr &amp; "f" &amp; vbCr &amp; Text1.Text &amp; vbCr &amp; Text2.Text &amp; vbCr &amp; Text3.Text &amp; vbCr &amp; Text4.Text &amp; vbCr &amp; vbCr &amp; vbCr</p><p>我这个截取圆内的线段,你只需要把坐标改成比矩形大的坐标就行了,完全可以做到,我应用过的。</p>

nhy12345678 发表于 2009-2-13 21:42:00

<p>这个就是专门为你写的完整代码:运行时先选择一个矩形,右键即可完成你要的操作</p><p>Sub tttt()<br/>&nbsp;&nbsp; Dim p As Variant<br/>&nbsp;&nbsp; Dim ent As AcadEntity<br/>&nbsp;&nbsp; Dim min, max As Variant<br/>&nbsp;&nbsp; Dim a(0 To 2) As Double<br/>&nbsp;&nbsp; Dim b(0 To 2) As Double<br/>&nbsp;&nbsp; ThisDrawing.Utility.GetEntity ent, p, "请选择一个矩形:"<br/>&nbsp;&nbsp; ent.GetBoundingBox min, max<br/>&nbsp;&nbsp; st3 min, min(0) - 0.001, min(1) - 0.001, 0<br/>&nbsp;&nbsp; st3 max, max(0) + 0.001, max(1) + 0.001, 0<br/>&nbsp;&nbsp; st3 a, min(0) - 0.001, max(1) + 0.001, 0<br/>&nbsp;&nbsp; st3 b, max(0) + 0.001, min(1) - 0.001, 0<br/>&nbsp;&nbsp; ThisDrawing.SendCommand "_trim" &amp; vbCr &amp; "(handent """ &amp; ent.Handle &amp; """)" &amp; vbCr &amp; vbCr &amp; "f" &amp; vbCr &amp; min(0) &amp; "," &amp; min(1) &amp; vbCr &amp; a(0) &amp; "," &amp; a(1) &amp; vbCr &amp; max(0) &amp; "," &amp; max(1) &amp; vbCr &amp; b(0) &amp; "," &amp; b(1) &amp; vbCr &amp; min(0) &amp; "," &amp; min(1) &amp; vbCr &amp; vbCr &amp; vbCr<br/>&nbsp;&nbsp; ThisDrawing.SendCommand "_trim" &amp; vbCr &amp; "(handent """ &amp; ent.Handle &amp; """)" &amp; vbCr &amp; vbCr &amp; "f" &amp; vbCr &amp; min(0) &amp; "," &amp; min(1) &amp; vbCr &amp; a(0) &amp; "," &amp; a(1) &amp; vbCr &amp; max(0) &amp; "," &amp; max(1) &amp; vbCr &amp; b(0) &amp; "," &amp; b(1) &amp; vbCr &amp; min(0) &amp; "," &amp; min(1) &amp; vbCr &amp; vbCr &amp; vbCr<br/>End Sub</p>

天龙八部 发表于 2009-2-14 10:59:00

<p>判断选择实体的四个相交点,用BREAK截断,在把角点在该对象之外的所有线条DEL就OK了,这样更方便一些</p>

kingzgh 发表于 2009-4-13 19:59:00

四楼主代码中的st3是指什么啊????????????

kingzgh 发表于 2009-4-13 20:06:00

假如相反,我只保留矩形外的线段,删除矩形里的线段该怎么做啊??????????

kingzgh 发表于 2009-4-13 20:13:00

<strong><font face="Verdana" color="#da2549">希望nhy12345678给予回答啊!!!!!!!!!!!</font></strong>

kingzgh 发表于 2009-4-18 10:27:00

<p>希望楼主能够及时回复,这个方法有个问题,当矩形斜过来的时候好像就不起作用了!!!!!!!!!!!!!!!!!!!!!!!</p>
页: [1]
查看完整版本: [求助]自动修剪