[VBA]关于图块使用问题 请教!急
编制了一个绘制轴的程序但是在一个图形内只能使用一次 之后无论怎么修改参数 绘制的都是第一次参
数绘出的图形。 图块设置上有点搞不懂<BR>那个高手帮我修改一下,使它可以连续使用
<BR>'******************************************************<BR>'<BR>' <BR>'******************************************************<BR>Private Sub cmdsure_Click()<BR> <BR> '定义变量 读入数据<BR> Dim D1 As Double<BR> Dim D2 As Double<BR> Dim D3 As Double<BR> Dim D4 As Double<BR> Dim L1 As Double<BR> Dim L2 As Double<BR> Dim L3 As Double<BR> Dim L4 As Double<BR> Dim jianL As Double<BR> Dim jianW As Double<BR> <BR> D1 = txtd1.Text<BR> D2 = txtd2.Text<BR> D3 = txtd3.Text<BR> D4 = txtd4.Text<BR> L1 = txtl1.Text<BR> L2 = txtl2.Text<BR> L3 = txtl3.Text<BR> L4 = txtl4.Text<BR> jianL = txtjianL.Text<BR> jianW = TxtjianW.Text<BR> <BR> '隐藏窗口<BR> frmzhou.Hide<BR> <BR> Dim sysOSMODE As Integer<BR> sysOSMODE = ThisDrawing.GetVariable("osmode")<BR> ThisDrawing.SetVariable "osmode", 0<BR> '定义点<BR> Dim p(1 To 22), pa, pb, insertPt As Variant<BR> Dim di1, di2, di3, di4 As Variant<BR> Dim o1, o2, o3, o4, o5, o6 As Variant<BR> Dim jian(1 To 6) As Variant<BR> Dim utilObj As Object<BR> Set utilObj = ThisDrawing.Utility<BR> '获取输入点<BR> insertPt = ThisDrawing.Utility.GetPoint(, "输入插入点:")<BR> <BR> utilObj.CreateTypedArray p(1), vbDouble, insertPt(0), insertPt
(1) + 2 - D1 / 2, 0<BR> utilObj.CreateTypedArray p(2), vbDouble, insertPt(0), insertPt
(1) - 2 + D1 / 2, 0<BR> utilObj.CreateTypedArray p(3), vbDouble, insertPt(0) + L1,
insertPt(1) - D2 / 2, 0<BR> utilObj.CreateTypedArray p(4), vbDouble, insertPt(0) + L1,
insertPt(1) + D2 / 2, 0<BR> utilObj.CreateTypedArray p(5), vbDouble, insertPt(0) + L1 + L2,
insertPt(1) - D3 / 2, 0<BR> utilObj.CreateTypedArray p(6), vbDouble, insertPt(0) + L1 + L2,
insertPt(1) + D3 / 2, 0<BR> utilObj.CreateTypedArray p(7), vbDouble, insertPt(0) + L1 + L2 +
L3, insertPt(1) - D3 / 2, 0<BR> utilObj.CreateTypedArray p(8), vbDouble, insertPt(0) + L1 + L2 +
L3, insertPt(1) + D3 / 2, 0<BR> utilObj.CreateTypedArray p(9), vbDouble, insertPt(0) + L1 + L2 +
L3 + L4, insertPt(1) + 2 - D4 / 2, 0<BR> utilObj.CreateTypedArray p(10), vbDouble, insertPt(0) + L1 + L2
+ L3 + L4, insertPt(1) - 2 + D4 / 2, 0<BR> <BR> utilObj.CreateTypedArray p(11), vbDouble, insertPt(0) + L1,
insertPt(1) - (D2 + D1) / 4, 0<BR> utilObj.CreateTypedArray p(12), vbDouble, insertPt(0) + L1 - (D2
- D1) / 4, insertPt(1) - D1 / 2, 0<BR> utilObj.CreateTypedArray p(13), vbDouble, insertPt(0) + L1,
insertPt(1) + (D2 + D1) / 4, 0<BR> utilObj.CreateTypedArray p(14), vbDouble, insertPt(0) + L1 - (D2
- D1) / 4, insertPt(1) + D1 / 2, 0<BR> utilObj.CreateTypedArray p(15), vbDouble, insertPt(0) + L1 + L2,
insertPt(1) - (D3 + D2) / 4, 0<BR> utilObj.CreateTypedArray p(16), vbDouble, insertPt(0) + L1 + L2
- (D3 - D2) / 4, insertPt(1) - D2 / 2, 0<BR> utilObj.CreateTypedArray p(17), vbDouble, insertPt(0) + L1 + L2,
insertPt(1) + (D3 + D2) / 4, 0<BR> utilObj.CreateTypedArray p(18), vbDouble, insertPt(0) + L1 + L2
- (D3 - D2) / 4, insertPt(1) + D2 / 2, 0<BR> utilObj.CreateTypedArray p(19), vbDouble, insertPt(0) + L1 + L2
+ L3, insertPt(1) - (D4 + D3) / 4, 0<BR> utilObj.CreateTypedArray p(20), vbDouble, insertPt(0) + L1 + L2
+ L3 - (D4 - D3) / 4, insertPt(1) - D4 / 2, 0<BR> utilObj.CreateTypedArray p(21), vbDouble, insertPt(0) + L1 + L2
+ L3, insertPt(1) - (D4 + D3) / 4, 0<BR> utilObj.CreateTypedArray p(22), vbDouble, insertPt(0) + L1 + L2
+ L3 - (D4 - D3) / 4, insertPt(1) + D4 / 2, 0<BR> <BR> <BR> utilObj.CreateTypedArray di1, vbDouble, insertPt(0) + 2,
insertPt(1) - D1 / 2, 0<BR> utilObj.CreateTypedArray di2, vbDouble, insertPt(0) + 2,
insertPt(1) + D1 / 2, 0<BR> utilObj.CreateTypedArray di3, vbDouble, insertPt(0) + L1 + L2 +
L3 + L4 - 2, insertPt(1) - D4 / 2, 0<BR> utilObj.CreateTypedArray di4, vbDouble, insertPt(0) + L1 + L2 +
L3 + L4 - 2, insertPt(1) + D4 / 2, 0<BR> <BR> <BR> utilObj.CreateTypedArray pa, vbDouble, insertPt(0) - 20,
insertPt(1), 0<BR> utilObj.CreateTypedArray pb, vbDouble, insertPt(0) + L1 + L2 +
L3 + L4 + 20, insertPt(1), 0<BR> <BR> <BR> utilObj.CreateTypedArray o1, vbDouble, insertPt(0) + L1 - (D2 -
D1) / 4, insertPt(1) - (D2 + D1) / 4, 0<BR> utilObj.CreateTypedArray o2, vbDouble, insertPt(0) + L1 - (D2 -
D1) / 4, insertPt(1) + (D2 + D1) / 4, 0<BR> utilObj.CreateTypedArray o3, vbDouble, insertPt(0) + L1 + L2 -
(D3 - D2) / 4, insertPt(1) - (D3 + D2) / 4, 0<BR> utilObj.CreateTypedArray o4, vbDouble, insertPt(0) + L1 + L2 -
(D3 - D2) / 4, insertPt(1) + (D3 + D2) / 4, 0<BR> utilObj.CreateTypedArray o5, vbDouble, insertPt(0) + L1 + L2 +
L3 - (D4 - D3) / 4, insertPt(1) - (D4 + D3) / 4, 0<BR> utilObj.CreateTypedArray o6, vbDouble, insertPt(0) + L1 + L2 +
L3 - (D4 - D3) / 4, insertPt(1) + (D4 + D3) / 4, 0<BR> <BR> utilObj.CreateTypedArray jian(1), vbDouble, insertPt(0) + L1 +
L2 + L3 / 2 - jianL / 2 + jianW / 2, insertPt(1) - jianW / 2, 0<BR> utilObj.CreateTypedArray jian(2), vbDouble, insertPt(0) + L1 +
L2 + L3 / 2 - jianL / 2 + jianW / 2, insertPt(1) + jianW / 2, 0<BR> utilObj.CreateTypedArray jian(3), vbDouble, insertPt(0) + L1 +
L2 + L3 / 2 + jianL / 2 - jianW / 2, insertPt(1) - jianW / 2, 0<BR> utilObj.CreateTypedArray jian(4), vbDouble, insertPt(0) + L1 +
L2 + L3 / 2 + jianL / 2 - jianW / 2, insertPt(1) + jianW / 2, 0<BR> utilObj.CreateTypedArray jian(5), vbDouble, insertPt(0) + L1 +
L2 + L3 / 2 - jianL / 2 + jianW / 2, insertPt(1), 0<BR> utilObj.CreateTypedArray jian(6), vbDouble, insertPt(0) + L1 +
L2 + L3 / 2 + jianL / 2 - jianW / 2, insertPt(1), 0<BR> <BR> <BR> Dim bl As String<BR> bl = "block"<BR> <BR> Dim flagno As Integer<BR> flagno = 0<BR> <BR> Dim iblock As Integer<BR> iblock = ThisDrawing.Blocks.Count<BR> While (iblock > 0)<BR> If ThisDrawing.Blocks.Item(iblock - 1).Name = mx Then<BR> flagno = 1<BR> End If<BR> iblock = iblock - 1<BR> Wend<BR> <BR> If flagno = 0 Then<BR> <BR> <BR> <BR> '创建块 连线,画弧<BR> Set blockobj = ThisDrawing.Blocks.Add(insertPt, bl)<BR> Dim line(1 To 21), linec As AcadLine<BR> Dim arc(1 To 8) As AcadArc<BR> <BR> Set line(1) = blockobj.AddLine(p(1), p(2))<BR> Set line(2) = blockobj.AddLine(di1, di2)<BR> Set line(3) = blockobj.AddLine(p(1), di1)<BR> Set line(4) = blockobj.AddLine(p(2), di2)<BR> Set line(5) = blockobj.AddLine(di1, p(12))<BR> <BR> Set line(6) = blockobj.AddLine(di2, p(14))<BR> Set line(7) = blockobj.AddLine(p(3), p(4))<BR> Set line(8) = blockobj.AddLine(p(3), p(16))<BR> Set line(9) = blockobj.AddLine(p(4), p(18))<BR> Set line(10) = blockobj.AddLine(p(5), p(6))<BR> Set line(11) = blockobj.AddLine(p(5), p(7))<BR> Set line(12) = blockobj.AddLine(p(6), p(8))<BR> Set line(13) = blockobj.AddLine(p(7), p(8))<BR> <BR> Set line(14) = blockobj.AddLine(p(22), di4)<BR> Set line(15) = blockobj.AddLine(p(20), di3)<BR> Set line(16) = blockobj.AddLine(di3, di4)<BR> Set line(17) = blockobj.AddLine(di3, p(9))<BR> Set line(18) = blockobj.AddLine(p(10), di4)<BR> Set line(19) = blockobj.AddLine(p(9), p(10))<BR> Set line(20) = blockobj.AddLine(jian(1), jian(3))<BR> Set line(21) = blockobj.AddLine(jian(2), jian(4))<BR> <BR> Set linec = blockobj.AddLine(pa, pb)<BR> <BR> Set arc(1) = blockobj.AddArc(o1, (D2 - D1) / 4, 0#, 1.5707963)<BR> Set arc(2) = blockobj.AddArc(o2, (D2 - D1) / 4, 1.5 * 3.1415926,
0#)<BR> Set arc(3) = blockobj.AddArc(o3, (D3 - D2) / 4, 0#, 1.5707963)<BR> Set arc(4) = blockobj.AddArc(o4, (D3 - D2) / 4, 1.5 * 3.1415926,
0#)<BR> Set arc(5) = blockobj.AddArc(o5, (D3 - D4) / 4, 1.5707963,
3.1415926)<BR> Set arc(6) = blockobj.AddArc(o6, (D3 - D4) / 4, 3.1415926, 1.5 *
3.1415926)<BR> Set arc(7) = blockobj.AddArc(jian(5), jianW / 2, 1.5707963, 1.5
* 3.1415926)<BR> Set arc(8) = blockobj.AddArc(jian(6), jianW / 2, 1.5 *
3.1415926, 1.5707963)<BR> '设置线形<BR> ThisDrawing.Linetypes.Load "CENTER", "acadiso.lin"<BR> linec.Linetype = "CENTER"<BR> '设置颜色<BR> Dim color As AcadAcCmColor<BR> Set color = AcadApplication.GetInterfaceObject
("AutoCAD.AcCmColor.16")<BR> Call color.SetRGB(80, 14, 24)<BR> linec.TrueColor = color<BR> <BR> End If<BR> '插入图块<BR> Dim blockrefobj As AcadBlockReference<BR> Set blockrefobj = ThisDrawing.ModelSpace.InsertBlock(insertPt,
bl, 1#, 1#, 1#, 0)<BR> <BR> <BR> ThisDrawing.Regen acActiveViewport<BR> <BR> <BR> <BR>End Sub<BR>Private Sub cmdexit_Click()<BR> End<BR>End Sub 用无名块
bl="*U" OK 尝试一下 谢谢啊
页:
[1]