xljz 发表于 2006-7-17 11:45:00

求助VBA。

<P>怎样能将CAD图形中特定的数字(单行的)选择,然后自动相加,结果(单行的)放在特定的位子?如何做?请教各位高手。</P>

68651521 发表于 2006-7-17 15:39:00

<P>把想操作的数字 放进一个选择集中</P>
<P>遍历他 依次相加 </P>
<P>最后输出结果。</P>

xljz 发表于 2006-7-18 10:44:00

<P>2楼你说的我明白,可是我是CAD VBA新手,虽然有VB的基础,可是对于CAD VBA,还是很陌生,可否写出来,我可以看懂的。谢谢。</P>

taimen1234 发表于 2006-7-18 19:03:00

<P>我也是啊!请高手指点</P>
<P>&nbsp;</P>

68651521 发表于 2006-7-19 08:57:00

本帖最后由 作者 于 2006-7-19 9:25:03 编辑 <br /><br /> <P>Private Sub CommandButton1_Click()<BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp; On Error Resume Next<BR>&nbsp;&nbsp;&nbsp; Dim txtObJ As AcadText<BR>&nbsp;&nbsp;&nbsp; Dim txtInsPos(0 To 2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim Sum As Double<BR>&nbsp;&nbsp;&nbsp; Dim txtHeight As Double<BR>&nbsp;&nbsp;&nbsp; Dim SsetObj As AcadSelectionSet<BR>&nbsp;&nbsp;&nbsp; Dim Entry As AcadEntity<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set SsetObj = ThisDrawing.SelectionSets("Sset1")<BR>&nbsp;&nbsp;&nbsp; If Err Then Set SsetObj = ThisDrawing.SelectionSets.Add("Sset1")<BR>&nbsp;&nbsp;&nbsp; SsetObj.Clear<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Me.Hide<BR>&nbsp;&nbsp;&nbsp; SsetObj.SelectOnScreen<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Sum = 0<BR>&nbsp;&nbsp;&nbsp; txtHeight = 0<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; For Each Entry In SsetObj<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If TypeName(Entry) Like "IAcad*Text*" Then Sum = Sum + Entry.TextString<BR>&nbsp;&nbsp;&nbsp; Next Entry<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; txtInsPos(0) = 0<BR>&nbsp;&nbsp;&nbsp; txtInsPos(1) = 0<BR>&nbsp;&nbsp;&nbsp; txtInsPos(2) = 0<BR>&nbsp;&nbsp;&nbsp; txtHeight = 10<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set txtObJ = ThisDrawing.ModelSpace.AddText(Str(Sum), txtInsPos, txtHeight)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; SsetObj.Clear<BR>&nbsp;&nbsp;&nbsp; MsgBox "计算结果显示在在(0,0,0)处"<BR>End Sub<BR></P>
<P></P>
<P></P>
页: [1]
查看完整版本: 求助VBA。