[求助]关于循环!
<p>我在VB.NET中开发CAD中,我一直用不好循环,想请大家帮个忙!</p><p>我想连续选择多个不同图层上的实体,从而获得几个图层,直到我点击右键,图面上只显示这几个图层,其他图层都关闭!<br/>是否需要循环,怎么用呢?</p> <p>简单写下流程</p><p>1、使用选择集选择实体</p><p>2、遍历选择集,获取实体的图层ID集合</p><p>3、只显示这几个图层,其他图层都关闭</p> 需要用到循环么?看我的代码,我感觉这个代码写的不好!
<CommandMethod("CloseOtherAllLayer")> Public Sub CloseOtherAllLayer()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Try
Dim entIdCollection As New ObjectIdCollection
Do
Dim optEntity As New PromptEntityOptions(vbCrLf & "请选择图层上的实体")
Dim resEntity As PromptEntityResult = ed.GetEntity(optEntity)
If resEntity.Status = PromptStatus.OK Then
Dim entId As ObjectId = resEntity.ObjectId
entIdCollection.Add(entId)
Else
Exit Do
End If
Loop
If entIdCollection.Count = 0 Then
Exit Sub
End If
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim lt As LayerTable = trans.GetObject(db.LayerTableId, OpenMode.ForRead)
db.Clayer = lt.Item("0")
For Each objId As ObjectId In lt
Dim ltr As LayerTableRecord = trans.GetObject(objId, OpenMode.ForWrite)
If ltr.Name <> "0" Then
ltr.UpgradeOpen()
ltr.IsFrozen = True
End If
Next
For Each entId As ObjectId In entIdCollection
Dim ent As Entity = trans.GetObject(entId, OpenMode.ForRead)
Dim ltr As LayerTableRecord = trans.GetObject(lt.Item(ent.Layer), OpenMode.ForWrite)
ltr.IsFrozen = False
Next
trans.Commit()
End Using
Catch ex As Exception
ed.WriteMessage("有错误,请重试!")
End Try
End Sub
<p>嗯,很不好,呵呵</p><p>1、选择的部分用选择集ed.GetSelect()</p><p>2、先遍历选择的实体集合,把图层Id放在一个集合中,要考虑去除重复项</p><p>3、遍历图层Id集合,依次改变</p><p></p> 懂了,谢谢版主!我再试试! 但是我想单个单个的选,ed.getselection()是框选呀!怎么办呢? 单个的选 GetEntity() 我也试试!
页:
[1]