This work is licensed under a
Creative
Commons Attribution-ShareAlike 2.5 License.
' Visibility Program
' Make AutoCAD objects Visible or Invisible
' Created by:
' Frank Zander
' Contract CADD Group
' Website http://www.contractcaddgroup.com
' Phone: 604-591-1140
Option
Explicit
Sub cmdHideObjects_Click()
' The cmdHideObjects_Click
Function gets Hides
' objects in
AutoCAD drawings.
Dim objNewSS As Object 'AcadSelectionSet
Dim strCurrLayer As String
Dim objLayer As Object ' AcadLayers
Dim objLayers As Object 'AcadLayers
Dim SSentity As Object
' Set the
objLayers Object to the AutoCAD active document layers.
Set objLayers =
ThisDrawing.Layers
' Set the
objNewSS Object to a new selection set called VBA.
Set objNewSS =
ThisDrawing.SelectionSets.Add("VBA")
' Hide the
Visibility Form.
frmVisibility.Hide
' Select Objects
on Screen in AutoCAD's display
' window.
objNewSS.SelectOnScreen
' Start
processing every SSentity (Object) in the
' selection set
objNewSS.
For Each SSentity In objNewSS
' Find the layer information for a
selected Object.
strCurrLayer = SSentity.layer
' Set the objLayer information to the
selected
' Object.
Set objLayer = objLayers.Item(strCurrLayer)
' Check for locked layer...
' If the selected object is on a locked
layer,
' Then…
If objLayer.Lock Then
' Unlock the Layer.
objLayer.Lock = False
' Change the visibility of the selected
Object to
' False so it will not display.
SSentity.Visible = False
' Re-lock the Layer.
objLayer.Lock = True
' Else If the selected object is not on
a
' locked layer.
Else
' Change the visibility of the selected
Object to
' False so it will not display.
SSentity.Visible = False
' End of the If statement for checking
for a locked ' layer.
End If
SSentity.Update
' Process the
Next SSentity in objNewSS.
Next
' Show a Message
dialog box explaining that the
' processing is
done with the number of drawing
' objects
processed.
MsgBox "Done
Processing: " & _
Str(objNewSS.Count) & _
" Drawing
Objects", vbInformation, _
strProduct_Control &
strVersion_Control
' Display the
visibility Form.
' Delete the
selection set - A2K requirement
If Not objNewSS Is Nothing Then
objNewSS.Delete
End If
frmVisibility.Show
' End of the sub
program cmdHideObjects_Click.
End Sub
Sub cmdShow_Click()
' The
cmdShow_Click Function makes all objects
' in an AutoCAD
drawing visible.
' Dim objAcad As
AcadApplication
' Dim objDoc As
AcadDocument
Dim objElem As Object
Dim objLayer As Object 'AcadLayer
Dim objLayers As Object 'AcadLayers
Dim objNewSS As Object 'AcadSelectionSet
Dim dblPT1(0 To 2) As Double
Dim dblPT2(0 To 2) As Double
Dim strCurrLayer As String
Dim intGPC(0) As Integer
Dim varGPV(0) As Variant
' AutoCAD group code
60 sets the visibility of objects in AutoCAD
intGPC(0) = 60
' this is used
along long whith the setting 1 for invisible and 0 for visible.
' we are
searching for invisible objects...
varGPV(0) = 1
' Set the
objLayers Object to the AutoCAD active document layers.
Set objLayers =
ThisDrawing.Layers
' Hide the
visibility Form.
frmVisibility.Hide
' Create a
selection set of everything in the drawing and process it
' Set the
objNewSS Object to a new selection set
' called VBA.
Set objNewSS = ThisDrawing.SelectionSets.Add("VBA")
' Hide the
Visibility Form.
frmVisibility.Hide
' make the
selection set from every invisible object in AutoCAD
objNewSS.Select acSelectionSetAll, dblPT1,
dblPT2, intGPC, varGPV
' Start
processing each element in the active
' document
For Each objElem In objNewSS
' If an element
is not visible in Model Space,
' Then.
If objElem.Visible = False Then
' Get the layer name of the current
element being
' processed.
strCurrLayer = objElem.layer
' Set the objLayer to the layer
information in the
' layer table.
Set objLayer = objLayers.Item(strCurrLayer)
' Check for locked layer...
' If the selected object is on a locked
layer, Then
If objLayer.Lock Then
' Unlock the Layer.
objLayer.Lock = False
' Change the visibility of the selected
Object to
' True so it will display.
objElem.Visible = True
' Re-lock the Layer.
objLayer.Lock = True
' Else if the selected object is not on
a
' locked layer.
Else
' Change the visibility of the selected
Object to
' True so it will display.
objElem.Visible = True
' End if for checking for a locked
layer.
End If
' End if for checking for a non-visible
drawing
' element.
End If
objElem.Update
' Process the next drawing element.
Next
' Display a
message dialog box explaining that the
' processing for
the entire drawing is done.
MsgBox "Done Processing
entire drawing.", _
vbInformation,
strProduct_Control & _
strVersion_Control
' Delete the
selection set - A2K requirement
If Not objNewSS Is Nothing Then
objNewSS.Delete
End If
' Display the
visibility Form.
frmVisibility.Show
' End of the Sub
program cmdShow_Click
End Sub
Sub cmdExit_Click()
'Unload the
current form
Unload Me
End Sub