ahlzl
发表于 2006-12-31 18:34:00
本帖最后由 作者 于 2006-12-31 18:36:53 编辑 <br /><br /> <p>我改了一下程序。现在能实现第8贴中图1的效果。</p><p>Option Explicit<br/>Const PI As Double = 3.1415926535897</p><p>Public Sub Chamfering()<br/> On Error Resume Next<br/> <br/> Dim SSet As AcadSelectionSet<br/> If Not IsNull(ThisDrawing.SelectionSets.Item("chamfering")) Then<br/> Set SSet = ThisDrawing.SelectionSets.Item("chamfering")<br/> SSet.Delete<br/> End If<br/> Set SSet = ThisDrawing.SelectionSets.Add("chamfering")<br/> ThisDrawing.Utility.Prompt ("选择要斜切的对象...")<br/> SSet.SelectOnScreen<br/> <br/> Dim ptBase As Variant<br/> ptBase = ThisDrawing.Utility.GetPoint(, "请输入斜切对象的基点:")<br/> <br/> Dim pt2 As Variant<br/> pt2 = ThisDrawing.Utility.GetPoint(ptBase, "请输入斜切对象的插入点:")<br/> <br/> Dim angle As Double<br/> angle = ThisDrawing.Utility.GetAngle(ptBase, "请输入倾斜角度:")<br/> <br/> If Abs((angle / (0.5 * PI)) - Int(angle / (0.5 * PI))) < 0.001 Then<br/> MsgBox ("您输入的角度不合适,无法完成操作!")<br/> Exit Sub<br/> End If<br/> <br/> Dim newb As AcadBlock, newbName As String, n As Integer<br/> n = 1<br/> newbName = "ahlzl"<br/>BLOCK2:<br/> For Each newb In ThisDrawing.Blocks<br/> If newb.Name = newbName Then<br/> newbName = "ahlzl" & "_" & CStr(n)<br/> n = n + 1<br/> GoTo BLOCK2<br/> End If<br/> Next newb<br/> Set newb = ThisDrawing.Blocks.Add(ptBase, newbName)<br/> <br/> Dim objCollection0() As Object, i As Integer<br/> ReDim objCollection0(SSet.Count - 1) As Object<br/> For i = 0 To SSet.Count - 1<br/> Set objCollection0(i) = SSet.Item(i)<br/> Next<br/> <br/> Dim retObjects0 As Variant<br/> retObjects0 = ThisDrawing.CopyObjects(objCollection0, newb)<br/> <br/> Dim a1 As AcadBlockReference<br/> Set a1 = ThisDrawing.ModelSpace.InsertBlock(ptBase, newbName, 1 / Cos(angle), 1, 1, 0)<br/> <br/> a1.Rotate ptBase, DegreeToRadian(-45)<br/> <br/> Dim strBlkName As String<br/> strBlkName = "CAD倾斜"<br/> n = 1</p><p> Dim blockObj As AcadBlock<br/>BLOCK:<br/> For Each blockObj In ThisDrawing.Blocks<br/> If blockObj.Name = strBlkName Then<br/> strBlkName = "CAD倾斜" & "_" & CStr(n)<br/> n = n + 1<br/> GoTo BLOCK<br/> End If<br/> Next blockObj<br/> Set blockObj = ThisDrawing.Blocks.Add(ptBase, strBlkName)<br/> <br/> Dim objCollection(0) As Object<br/> Set objCollection(0) = a1<br/> <br/> Dim retObjects As Variant<br/> retObjects = ThisDrawing.CopyObjects(objCollection, blockObj)<br/> <br/> Dim xScale As Double, yScale As Double, zScale As Double, ang As Double<br/> xScale = Cos(PI / 4 - angle / 2) / Cos(DegreeToRadian(45))<br/> yScale = Sin(PI / 4 - angle / 2) / Sin(DegreeToRadian(45))<br/> zScale = 1<br/> ang = PI / 4 + angle / 2<br/> <br/> Dim ref1 As AcadBlockReference<br/> Set ref1 = ThisDrawing.ModelSpace.InsertBlock(pt2, strBlkName, xScale, yScale, zScale, ang)<br/> <br/> a1.Delete<br/> SSet.Delete<br/>End Sub</p><p>Private Function DegreeToRadian(angle As Double) As Double<br/> DegreeToRadian = angle * PI / 180<br/>End Function</p><p></p>
byghbcx
发表于 2007-1-8 11:28:00
感谢两位版主提供的程序代码,我试着对块进行转换,但对带属性的块不能生成无名块,还请high兄多指教.
byghbcx
发表于 2007-1-8 11:35:00
<font face="Courier New" color="#ff0000">(<a href="http://www.mjtd.com/object/autolisp/defun.htm" target="_black"><font color="#0000ff">defun</font></a><font color="#000000">
</font><b><font color="#0000ff">Nmblock</font></b><font color="#000000">
</font><font color="#ff0000">(</font><font color="#000000">ss pt </font><font color="#ff0000">k </font><a href="http://www.mjtd.com/object/autolisp/47.htm" target="_black"><font color="#0000ff">/</font></a><font color="#000000"> i n num</font><font color="#ff0000">)</font><br/><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/entmake.htm" target="_black"><font color="#0000ff">entmake</font></a><font color="#ff0000">(</font><font color="#000000">list</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/cons.htm" target="_black"><font color="#0000ff">cons</font></a><font color="#000000">
</font><font color="#008000">0</font><font color="#000000">
</font><font color="#ff00ff">"BLOCK"</font><font color="#ff0000">)</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/cons.htm" target="_black"><font color="#0000ff">cons</font></a><font color="#000000">
</font><font color="#008000">2</font><font color="#000000">
</font><font color="#ff00ff">"*u"</font><font color="#ff0000">)</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/cons.htm" target="_black"><font color="#0000ff">cons</font></a><font color="#000000">
</font><font color="#008000">70</font><font color="#000000">
</font><font color="#008000">1</font><font color="#ff0000">)</font><font color="#000000">
</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/cons.htm" target="_black"><font color="#0000ff">cons</font></a><font color="#000000">
</font><font color="#008000">10</font><font color="#000000"> pt</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><br/><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#0000ff">setq</font></a><font color="#000000"> i </font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/sslength.htm" target="_black"><font color="#0000ff">sslength</font></a><font color="#000000"> ss</font><font color="#ff0000">)</font><font color="#000000"> n </font><font color="#ff0000">(</font><font color="#008000">-</font><font color="#000000">
</font><font color="#008000">1</font><font color="#ff0000">)</font><font color="#ff0000">)</font><br/><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/repeat.htm" target="_black"><font color="#0000ff">repeat</font></a><font color="#000000"> i </font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/entmake.htm" target="_black"><font color="#0000ff">entmake</font></a><font color="#ff0000">(</font><font color="#000000">cdr </font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/entget.htm" target="_black"><font color="#0000ff">entget</font></a><font color="#ff0000">(</font><font color="#000000">ssname ss </font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#0000ff">setq</font></a><font color="#000000"> n </font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/1+.htm" target="_black"><font color="#0000ff">1+</font></a><font color="#000000"> n</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><br/><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#0000ff">setq</font></a><font color="#000000"> num </font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/entmake.htm" target="_black"><font color="#0000ff">entmake</font></a><font color="#000000"> '</font><font color="#ff0000">(</font><font color="#ff0000">(</font><font color="#008000">0</font><font color="#000000">
</font><font color="#008000">.</font><font color="#000000">
</font><font color="#ff00ff">"ENDBLK"</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><br/><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/entmake.htm" target="_black"><font color="#0000ff">entmake</font></a><font color="#ff0000">(</font><font color="#000000">list</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/cons.htm" target="_black"><font color="#0000ff">cons</font></a><font color="#000000">
</font><font color="#008000">0</font><font color="#000000">
</font><font color="#ff00ff">"INSERT"</font><font color="#ff0000">)</font><font color="#000000">
</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/cons.htm" target="_black"><font color="#0000ff">cons</font></a><font color="#000000">
</font><font color="#008000">2</font><font color="#000000"> num</font><font color="#ff0000">)</font><font color="#000000">
</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/cons.htm" target="_black"><font color="#0000ff">cons</font></a><font color="#000000">
</font><font color="#008000">10</font><font color="#000000"> pt</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><br/><font color="#000000">
</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/if.htm" target="_black"><font color="#0000ff">if</font></a><font color="#000000"> k</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/progn.htm" target="_black"><font color="#0000ff">progn</font></a><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#0000ff">setq</font></a><font color="#000000"> i </font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/sslength.htm" target="_black"><font color="#0000ff">sslength</font></a><font color="#000000"> ss</font><font color="#ff0000">)</font><font color="#000000"> n </font><font color="#ff0000">(</font><font color="#008000">-</font><font color="#000000">
</font><font color="#008000">1</font><font color="#ff0000">)</font><font color="#ff0000">)</font><br/><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/repeat.htm" target="_black"><font color="#0000ff">repeat</font></a><font color="#000000"> i</font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/entdel.htm" target="_black"><font color="#0000ff">entdel</font></a><font color="#ff0000">(</font><font color="#000000">ssname ss </font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#0000ff">setq</font></a><font color="#000000"> n </font><font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/1+.htm" target="_black"><font color="#0000ff">1+</font></a><font color="#000000"> n</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><br/><font color="#000000">
</font><font color="#800080"><span style="BACKGROUND-COLOR: #c0c0c0;"><font color="#800080">; <font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/command.htm" target="_black"><font color="#0000ff">command</font></a>
<font color="#ff00ff">".erase"</font> ss <font color="#ff00ff">""</font><font color="#ff0000">)</font><br/></font></font><br/></span><font color="#ff0000">)</font></font>
highflybir
发表于 2007-1-8 13:03:00
<p></p><p></p><p>按照ahlzl的两次做块的思路,调整了其中的系数和数值,重新写了一个变换程序,这个程序已经能对任何CAD实体进行变换了。</p>
byghbcx
发表于 2007-1-8 15:06:00
<p>谢谢highflybir兄作出的及时回应,你的程序很好,在第二次匿名块名图块炸开后,有的东西又复原了,如尺寸线,文字等.</p><p>不过用你的Nblock程序对带属性块有作用,加载到我的transblock中可以用.我的程序中还有就是没有清理无用的匿名块.加入反应器后,拉的次数过多,系统会吃不消.</p><p> </p>
changchangyouyu
发表于 2010-9-28 19:48:00
<p>这么好的帖子,怎么就能沉呢,没天理。顶起!</p>
yoyoho
发表于 2010-9-28 21:23:00
<p>感谢分享程序</p>
<p>收藏学习!</p>
cheng5276
发表于 2010-10-6 00:13:00
高手们在华山论剑!太强了!我等丐帮的2袋弟子只能瞠目结舌啊
lrd1861
发表于 2011-7-7 06:06:00
好贴 顶起来
ljpnb
发表于 2011-7-7 06:27:01
确实强大,几位版大厉害,要努力学一下