ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • AutoCAD VBA - 선택객체 레이어만 남기기
    토목 이야기 2021. 3. 25. 20:31

    캐드 작업을 하다보면 너무 많은 객체가 있어서 수정이나 작성이 어려운 경우가 많이 있다. 이럴때 선택된 객체의 레이어만 남기고 나머지는 꺼버리면 작업을 보다 수월하게 할 수 있다. 오토캐드의 기본 명령어에는 이런 기능이 없으므로 VBA 작성을 통해 사용할 수 있다. 이와 비슷한 명령어로는 Layiso로 선택한 객체를 제외하고 동결시킨다. 동결이라 계속 화면에 남아 있어 복잡한 도면에서는 불편할 때가 있으므로 이럴때는 아래 VBA를 사용하면 된다. 

     

     

    Sub Layeroff()

     

    Dim SelLayer As Variant

    Dim SelGroup As Object

    Dim GroupObj As Object

    Dim LayerName As String

    Dim SelObj As Object

     

    Dim i As Integer

    Dim layer As Variant

     

    On Error Resume Next

    If ThisDrawing.SelectionSets("TEMP") Then

       ThisDrawing.SelectionSets("TEMP").Delete

    End If

    On Error GoTo 0

     

    Set SelGroup = ThisDrawing.SelectionSets.Add("TEMP")

     

    AppActivate Application.Caption

     

    SelGroup.SelectOnScreen

    If SelGroup.Count < 1 Then GoTo 에러처리

     

    For i = 0 To ThisDrawing.Layers.Count - 1

       ThisDrawing.Layers.Item(i).LayerOn = False

    Next i

     

    For Each GroupObj In SelGroup

    LayerName = GroupObj.layer

    ThisDrawing.Layers(LayerName).LayerOn = True

    Next GroupObj

     

    ThisDrawing.SelectionSets("TEMP").Delete

     

    에러처리:

    Application.Update

     

     

    End Sub

     

     

    댓글

Designed by Tistory.