yuangw1234 发表于 2006-4-8 10:09:00

变为当前层失败,有没有方法

<P>请教大师:</P>
<P>本人编了一个将所选层变为当前层的Vba程式,</P>
<P>可是失败,请了解的朋友指点</P>
<P>Public Sub dq()<BR>Dim ssetobj1 As AcadSelectionSet<BR>Dim icount1 As Integer<BR>icount1 = ThisDrawing.SelectionSets.Count<BR>While (icount1 &gt; 0)<BR>&nbsp;&nbsp;&nbsp; If ThisDrawing.SelectionSets.Item(icount1 - 1).Name = "yuan" Then<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item(icount1 - 1).Delete<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; icount1 = icount1 - 1<BR>&nbsp;&nbsp;&nbsp; Wend<BR>&nbsp;&nbsp;&nbsp; Set ssetobj1 = ThisDrawing.SelectionSets.Add("yuan")<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.Prompt "please select object"<BR>&nbsp;&nbsp;&nbsp; ssetobj1.SelectOnScreen<BR>&nbsp; Dim i1 As Integer<BR>&nbsp; Dim selobj1 As AcadEntity<BR>&nbsp; On Error Resume Next<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set selobj1 = ssetobj1.Item(i1)<BR><BR>&nbsp; Dim str As String<BR>&nbsp; str = selobj1.Layer<BR>&nbsp;&nbsp;ThisDrawing.ActiveLayer = str<BR></P>

xinghesnak 发表于 2006-4-8 10:51:00

<P>大哥,ThisDrawing.ActiveLayer是个对象,str是个字符串,看你最后的三行,应该改为:</P>
<P>&nbsp;Dim str As String<BR>&nbsp;str = selobj1.layer<BR>&nbsp;Dim layer As AcadLayer<BR>&nbsp;For Each layer In ThisDrawing.Layers<BR>&nbsp;&nbsp;&nbsp; If layer.Name = str Then ThisDrawing.ActiveLayer = layer<BR>&nbsp;Next</P>
<P>&nbsp;</P>

雪山飞狐_lzh 发表于 2006-4-8 15:41:00

ThisDrawing.ActiveLayer =ThisDrawing.Layers( str )

xinghesnak 发表于 2006-4-8 16:08:00

<A name=6949><FONT color=#990000><B>lzh741206</B></FONT></A>斑竹,你的经验很丰富啊,我总是想不起来用简单的方法。。。谢啦!以后改进!

yuangw1234 发表于 2006-4-8 17:28:00

谢谢各位大师,你们太利害了
页: [1]
查看完整版本: 变为当前层失败,有没有方法