wanghere 发表于 2007-5-24 16:10:00

新人报道,问个初级的问题

<p>我现在做工程老要算管道的长度,我想用vba来帮我完成,有点vb的基础。不过对这个还是蛮陌生,我想算同一颜色的线的长度,看了少少书,知道可以获取他的起点和终点,但是我还不会让它自动。麻烦大侠给个例子我瞧瞧吧!就给个获取红色直线的长度吧?谢谢拉</p>

laoliu09 发表于 2007-5-24 16:57:00

<p>凡事不能急于求成哦,还是从基本学起好,祝你成功!你需要的功能大致如下:</p><p>Sub test()<br/>&nbsp;&nbsp;&nbsp; Dim ss As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; Dim ft(1) As Integer, fd(1) As Variant<br/>&nbsp;&nbsp;&nbsp; Dim l As AcadLine<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '安全创建选择集<br/>&nbsp;&nbsp;&nbsp; Set ss = ThisDrawing.SelectionSets.Add("ss1")<br/>&nbsp;&nbsp;&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set ss = ThisDrawing.SelectionSets.item("ss1")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ss.Clear<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '过滤设置<br/>&nbsp;&nbsp;&nbsp; ft(0) = 0: fd(0) = "line"<br/>&nbsp;&nbsp;&nbsp; ft(1) = 62: fd(1) = 1<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '过滤选择<br/>&nbsp;&nbsp;&nbsp; ss.Select acSelectionSetAll, ft, fd<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '距离累加<br/>&nbsp;&nbsp;&nbsp; Dim dis As Double<br/>&nbsp;&nbsp;&nbsp; For Each l In ss<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dis = dis + l.Length<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; MsgBox "管线总长为:" &amp; dis<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '删除选择集<br/>&nbsp;&nbsp;&nbsp; ss.Delete<br/>End Sub</p>

wanghere 发表于 2007-5-24 17:18:00

<p>选择集是这样用的呀!谢谢!非常感谢<strong><font face="Verdana" color="#61b713">laoliu09</font></strong>!</p>

wanghere 发表于 2007-5-24 17:34:00

<p>ss.Select acSelectionSetAll, ,,ft, fd</p><p></p><p>太高兴了。我决定每天进来学一点。呵呵</p>

laoliu09 发表于 2007-5-24 18:54:00

<p>选择集很多用法的,也很容易犯莫名错误,建议先熟悉cad对像模型!</p>
页: [1]
查看完整版本: 新人报道,问个初级的问题