Michael527 发表于 2005-2-20 19:46:00

[求助]有关块方面的问题

我采用图块方式编的一个程序,运行时,第一次很正常,第二次以后都要多生成一些莫明其妙的图块,为什么?如何解决?谢谢!

mccad 发表于 2005-2-20 22:04:00

你的图块已经存在,再以同名的块名肯定会有问题。

Michael527 发表于 2005-2-21 19:42:00

那如何解决呢?谢谢明总!

雪山飞狐_lzh 发表于 2005-2-21 21:21:00

你的代码呢?

Michael527 发表于 2005-2-24 19:38:00

我的代码为:


Private Sub cmdDraw_Click()<BR>Dim objEllipse1 As AcadEllipse<BR>Dim objEllipse2 As AcadEllipse<BR>Dim linea, lineb, linec, lined, linee, linef, lineg As AcadLine<BR>Dim ptCen(0 To 2) As Double, radRatio1, radRatio2 As Double<BR>Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double, sca As Double<BR>Dim pt3(0 To 2) As Double, pt4(0 To 2) As Double<BR>Dim pt5(0 To 2) As Double, pt6(0 To 2) As Double<BR>Dim pt7(0 To 2) As Double, pt8(0 To 2) As Double<BR>Dim pt9(0 To 2) As Double, pt10(0 To 2) As Double<BR>Dim pt11(0 To 2) As Double, pt12(0 To 2) As Double<BR>Dim ptmajAxis1(0 To 2) As Double, ptmajAxis2(0 To 2) As Double<BR>Dim CenPt As Variant, OldCmdEcho As Variant<BR>OldCmdEcho = ThisDrawing.GetVariable("cmdecho")<BR>Dim objLayer As AcadLayer<BR>OldLayer = ThisDrawing.GetVariable("clayer")<BR>Set objLayer = ThisDrawing.Layers.Add("1轮廓实线层")<BR>ThisDrawing.ActiveLayer = objLayer<BR>frmHD.Hide


sca = cboSc.Text<BR>deg = (cboDeg.Text * 3.1415926) / 180<BR>CenPt = ThisDrawing.Utility.GetPoint(, "输入中心点:")<BR>       


pt1(0) = CenPt(0) - D / 2 * sca<BR>pt1(1) = CenPt(1)<BR>pt1(2) = CenPt(2)


pt2(0) = CenPt(0) - D / 2 * sca<BR>pt2(1) = CenPt(1) + H<BR>pt2(2) = CenPt(2)


pt3(0) = CenPt(0) + D / 2 * sca<BR>pt3(1) = CenPt(1) + H<BR>pt3(2) = CenPt(2)


pt4(0) = CenPt(0) + D / 2 * sca<BR>pt4(1) = CenPt(1)<BR>pt4(2) = CenPt(2)


pt5(0) = CenPt(0) - D / 2 * sca - t * sca<BR>pt5(1) = CenPt(1)<BR>pt5(2) = CenPt(2)


pt6(0) = CenPt(0) - D / 2 * sca - t * sca<BR>pt6(1) = CenPt(1) + H<BR>pt6(2) = CenPt(2)


pt7(0) = CenPt(0) + D / 2 * sca + t * sca<BR>pt7(1) = CenPt(1) + H<BR>pt7(2) = CenPt(2)


pt8(0) = CenPt(0) + D / 2 * sca + t * sca<BR>pt8(1) = CenPt(1)<BR>pt8(2) = CenPt(2)


pt9(0) = CenPt(0)<BR>pt9(1) = CenPt(1) - 5 * sca<BR>pt9(2) = CenPt(2)


pt10(0) = CenPt(0)<BR>pt10(1) = CenPt(1) + (H + h1 + t + 5) * sca<BR>pt10(2) = CenPt(2)


pt11(0) = CenPt(0) - D / 2 * sca - t * sca - 5 * sca<BR>pt11(1) = CenPt(1) + H<BR>pt11(2) = CenPt(2)


pt12(0) = CenPt(0) + D / 2 * sca + t * sca + 5 * sca<BR>pt12(1) = CenPt(1) + H<BR>pt12(2) = CenPt(2)


ptmajAxis1(0) = D / 2 * sca<BR>ptmajAxis1(1) = 0<BR>ptmajAxis1(2) = 0<BR>radRatio1 = 0.5


ptmajAxis2(0) = (D / 2 + t) * sca<BR>ptmajAxis2(1) = 0<BR>ptmajAxis2(2) = 0<BR>radRatio2 = (h1 + t) / (D / 2 + t)


<BR>        ptCen(0) = CenPt(0)<BR>        ptCen(1) = CenPt(1) + H * sca<BR>        ptCen(2) = CenPt(2)<BR>        <BR>Dim FT As String<BR>FT = "Head"<BR>Set blockObj = ThisDrawing.Blocks.Add(CenPt, FT)


Set objEllipse1 = blockObj.AddEllipse(ptCen, ptmajAxis1, radRatio1)<BR>objEllipse1.StartAngle = 0<BR>objEllipse1.EndAngle = 3.1415926


Set objEllipse2 = blockObj.AddEllipse(ptCen, ptmajAxis2, radRatio2)<BR>objEllipse2.StartAngle = 0<BR>objEllipse2.EndAngle = 3.1415926


<BR>Set linea = blockObj.AddLine(pt1, pt2)<BR>Set lineb = blockObj.AddLine(pt3, pt4)<BR>Set linec = blockObj.AddLine(pt5, pt6)<BR>Set lined = blockObj.AddLine(pt7, pt8)<BR>Set linee = blockObj.AddLine(pt5, pt8)


Set objLayer = ThisDrawing.Layers.Add("3中心线层")<BR>ThisDrawing.ActiveLayer = objLayer<BR>Set linef = blockObj.AddLine(pt9, pt10)<BR>Set lineg = blockObj.AddLine(pt11, pt12)


Set objLayer = ThisDrawing.Layers.Add("0")<BR>ThisDrawing.ActiveLayer = objLayer


Dim blockRefObj As AcadBlockReference<BR>Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(CenPt, FT, sca, sca, sca, deg)


ThisDrawing.Regen acActiveViewport


Set blockRefObj = Nothing<BR>Set blockObj = Nothing<BR>Unload Me<BR>ThisDrawing.SetVariable "cmdecho", OldCmdEcho<BR>ThisDrawing.SetVariable "clayer", OldLayer<BR>End Sub


第一次使用VB,请不要见笑,谢谢!

Michael527 发表于 2005-2-25 00:48:00

没有高手可以指点吗?遗憾!

mccad 发表于 2005-2-25 12:31:00

Dim FT As String
FT = "Head"
Set blockObj = ThisDrawing.Blocks.Add(CenPt, FT)问题就在以上这句。
如果块本身已经存在,则使用这一句是不能将块清空的。所以在后继的程序中向块中添加图元则是添加到原先已经存在的块中。所以会造成块中图元的重复。
解决的方法是,在添加块前先判断该名称的块是否存在,如果存在,则需要用其它名称。
对于自己编程的程序中使用到的块,最好使用一些统一前缀的名称,而且名称长一些,这样可以避免与其它人编程的程序中的块重复,影响自己程序的运行。如果是在调试过程中,则可以通过新建文件再调试。

Michael527 发表于 2005-2-25 18:41:00

谢谢明总指点!送你一朵鲜花!

桃花小妖 发表于 2005-9-28 10:40:00

<P>我的问题和你的一样</P>
<P>我想知道你是怎么解决的</P>
<P>谢谢</P>
页: [1]
查看完整版本: [求助]有关块方面的问题