hunterah 发表于 2006-8-9 09:00:00

请教用CopyObjects方法产生的块炸碎后插入点偏移的问题

<P>在我的程序中先将用CopyObjects方法产生的块插入图纸中,再用EXPLODE炸碎块,然后用DELETE方法删除块,结果炸碎后的对象偏移了我块插入点很远的位置,没办法只好用sendcommand办法手工解决(炸碎后插入点不变),求教版主如何解决?现贴程序中部分内容:</P>
<P>Set blkrefobj = ThisDrawing.ModelSpace.InsertBlock(inspt, "tempblock", smin, smin, smin, 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;'以下这段用来调整插入后图块的位置</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;Dim topt(0 To 2) As Double<BR>&nbsp;&nbsp;&nbsp; topt(0) = inspt(0) + ((d(0) - e(0) * smin) / 2)<BR>&nbsp;&nbsp;&nbsp; topt(1) = inspt(1) + ((d(1) - e(1) * smin) / 2)<BR>&nbsp;&nbsp;&nbsp; topt(2) = 0<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; blkrefobj.Move inspt, topt&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; blkrefobj.Update</P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; ActiveDocument.Utility.Prompt "接下来请选择插入的图块!炸碎后可进行文字高度调整和旋转角度的工作!"<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ThisDrawing.SendCommand "_explode" + Chr(13)&nbsp; '没办法此处只好手工解决炸碎后插入点偏移的问题<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 'blkrefobj.Explode<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 'blkrefobj.Delete<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Application.Update</P>

wyj7485 发表于 2006-8-9 09:43:00

<P>应该是定义块插入点出了问题</P>

hunterah 发表于 2006-8-9 10:13:00

能指出问题出在哪吗?有没有解决办法?

wyj7485 发表于 2006-8-9 10:27:00

把程序完整贴上来看看

hunterah 发表于 2006-8-9 10:48:00

本帖最后由 作者 于 2006-8-10 16:12:26 编辑 <br /><br /> <P>比较乱还属测试阶段不过基本功能可完成,重点看后面。程序的功能是按矩形框大小调整比例。</P>
<P>Public blnCancelled As Boolean<BR>Public s As Double<BR>Public smin As Double<BR>Public sfit As Double<BR>Public sx As Double<BR>Public sy As Double</P>
<P>Sub adjust_scale()</P>
<P>&nbsp;&nbsp;&nbsp; On Error Resume Next<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.PurgeAll<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim ss As AcadSelectionSet<BR>&nbsp;&nbsp;&nbsp; Dim pt(0 To 2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim i As Integer<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; If ThisDrawing.SelectionSets.Count &lt;&gt; 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To ThisDrawing.SelectionSets.Count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item(i).Delete<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set ss = ThisDrawing.SelectionSets.Add("ssss")<BR>&nbsp;&nbsp;&nbsp; ActiveDocument.Utility.Prompt "确认你选择的不包括图块,否则程序有可能出错!您最好退出此命令炸碎图块后重新操作!"<BR>&nbsp;&nbsp;&nbsp; ss.SelectOnScreen<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; If ss.Count &lt;&gt; 0 Then<BR>&nbsp;&nbsp;&nbsp; ReDim retval(0 To ss.Count - 1) As AcadEntity<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; For i = 0 To ss.Count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set retval(i) = ss.Item(i)<BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim entObj As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Dim minext As Variant, maxext As Variant<BR>&nbsp;&nbsp;&nbsp; Dim a(0 To 2), b(0 To 2) As Double&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'a()为右上脚坐标,b()为左下脚坐标<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; Set entObj = ss.Item(0)<BR>&nbsp;&nbsp;&nbsp; entObj.GetBoundingBox minext, maxext<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; a(0) = maxext(0)<BR>&nbsp;&nbsp;&nbsp; a(1) = maxext(1)<BR>&nbsp;&nbsp;&nbsp; a(2) = maxext(2)<BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp; b(0) = minext(0)<BR>&nbsp;&nbsp;&nbsp; b(1) = minext(1)<BR>&nbsp;&nbsp;&nbsp; b(2) = minext(2)<BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp; For i = 1 To ss.Count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set entObj = ss.Item(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entObj.GetBoundingBox minext, maxext<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If a(0) &lt; maxext(0) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a(0) = maxext(0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If a(1) &lt; maxext(1) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a(1) = maxext(1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If b(0) &gt; minext(0) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b(0) = minext(0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If b(1) &gt; minext(1) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b(1) = minext(1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; pt(0) = b(0)<BR>&nbsp;&nbsp;&nbsp; pt(1) = b(1)<BR>&nbsp;&nbsp;&nbsp; pt(2) = b(2)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim bk As AcadBlock<BR>&nbsp;&nbsp;&nbsp; Set bk = ThisDrawing.Blocks.Add(pt, "tempblock")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ThisDrawing.CopyObjects retval, bk<BR>&nbsp;&nbsp;&nbsp; Erase retval<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim c1 As Variant<BR>&nbsp;&nbsp;&nbsp; Dim c2 As Variant<BR>&nbsp;&nbsp;&nbsp; Dim cssize As Integer<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; cssize = ThisDrawing.Application.Preferences.Display.cursorsize<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Application.Preferences.Display.cursorsize = 100<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>c1get:<BR>&nbsp;&nbsp;&nbsp; c1 = ThisDrawing.Utility.GetPoint(, "选择边界点1:")<BR>&nbsp;&nbsp;&nbsp;&nbsp;If c1(0) = nil Then GoTo c1get<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>c2get:<BR>&nbsp;&nbsp;&nbsp; 'On Error Resume Next<BR>&nbsp;&nbsp;&nbsp; c2 = ThisDrawing.Utility.GetCorner(c1, "选择边界点2:")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; If c2(0) = nil Then GoTo c1get<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Application.Preferences.Display.cursorsize = cssize<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim d(0 To 1) As Double<BR>&nbsp;&nbsp;&nbsp; d(0) = VBA.Abs(c1(0) - c2(0))&nbsp; '选取范围水平距离<BR>&nbsp;&nbsp;&nbsp; d(1) = VBA.Abs(c1(1) - c2(1))&nbsp; '选取范围垂直距离<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim e(0 To 1) As Double<BR>&nbsp;&nbsp;&nbsp; e(0) = VBA.Abs(b(0) - a(0))&nbsp;&nbsp;&nbsp; '选取集合水平距离<BR>&nbsp;&nbsp;&nbsp; e(1) = VBA.Abs(b(1) - a(1))&nbsp;&nbsp;&nbsp; '选取集合垂直距离<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim inspt(0 To 2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim blkrefobj As AcadBlockReference<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; If c2(0) &lt; c1(0) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c1(0) = c2(0)<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; If c2(1) &lt; c1(1) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c1(1) = c2(1)<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; inspt(0) = c1(0): inspt(1) = c1(1): inspt(2) = c1(2)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; sx = d(0) / e(0)<BR>&nbsp;&nbsp;&nbsp; sy = d(1) / e(1)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; smin = sy<BR>&nbsp;&nbsp;&nbsp; If sy &gt; sx Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; smin = sx<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; sfit = CInt(100 * smin) / 100<BR>&nbsp;&nbsp;&nbsp; sx = smin<BR>&nbsp;&nbsp;&nbsp; sy = smin<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; blnCancelled = False<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; If blnCancelled = False Then<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim sc As Double<BR>&nbsp;&nbsp;&nbsp; sc = ThisDrawing.Utility.GetReal("请输入缩放比例" &amp; "(回车使用默认值" &amp; (CInt(100 * smin) / 100) &amp; "):")<BR>&nbsp;&nbsp;&nbsp; If sc &lt;&gt; nil Then smin = VBA.Abs(sc)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ss.Erase<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set blkrefobj = ThisDrawing.ModelSpace.InsertBlock(inspt, "tempblock", smin, smin, smin, 0)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim topt(0 To 2) As Double<BR>&nbsp;&nbsp;&nbsp; topt(0) = inspt(0) + ((d(0) - e(0) * smin) / 2)<BR>&nbsp;&nbsp;&nbsp; topt(1) = inspt(1) + ((d(1) - e(1) * smin) / 2)<BR>&nbsp;&nbsp;&nbsp; topt(2) = 0<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; blkrefobj.Move inspt, topt<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; blkrefobj.Update<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ActiveDocument.Utility.Prompt "接下来请选择插入的图块!炸碎后可进行文字高度调整和旋转角度的工作!"<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ThisDrawing.SendCommand "_explode" + Chr(13)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 'blkrefobj.Explode<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 'blkrefobj.Delete<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Application.Update<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>errhandle:<BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp; If ThisDrawing.SelectionSets.Count &lt;&gt; 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To ThisDrawing.SelectionSets.Count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item(i).Delete<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ThisDrawing.PurgeAll&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;</P>
<P>End Sub</P>

hunterah 发表于 2006-8-9 17:10:00

<P>侠之大者能帮忙解答吗?</P>
<P>&nbsp;</P>

wyj7485 发表于 2006-8-9 18:02:00

是分解的问题,当以不等的X,Y,Z比例系数插入时,分解后的图象与原图形不同,如果都是1:1则不会出现此问题

wyj7485 发表于 2006-8-9 18:17:00

<P>用以下语句代替ThisDrawing.SendCommand "_explode" + Chr(13)</P>
<P>Dim Handle1<BR>Handle1 = blkrefobj.Handle<BR>ThisDrawing.SendCommand "_explode" &amp; vbCr &amp; "(handent " &amp; Chr(34) &amp; Handle1 &amp; Chr(34) &amp; ")" &amp; vbCr &amp; vbCr</P>
<P>就不用手动干预了</P>

hunterah 发表于 2006-8-10 15:42:00

<P>谢谢楼上的答复,程序中插入比例X/Y/Z轴都是相等的(均为smin),我也曾注意到不等时炸碎出现的问题。楼上提供的方法帮我解决了大问题,再次表示谢意,希望今后能多得到您的指教。</P>
页: [1]
查看完整版本: 请教用CopyObjects方法产生的块炸碎后插入点偏移的问题