2006-10-17

Now for my next trick...

How to make the invisible disappear. Why bother you say. What I found out recently is, what I can't see can hurt me. We convert our files to our customers formats once we have completed their jobs. We convert our layer/linetype structure to their layer/linetype structure. I have created macros to do that for us and they work pretty well. Recently these macros would take an inordinate amount of time to work or even crashing AutoCAD after processing a single drawing for an hour or so. What's happening? The macro would purge the drawings and process all blocks to redefine their "innards". I would see blocks flash on that were not in the drawing. Hmmmm... I thought about it. They are either referenced by something in the drawing and can't be purged or.... they were invisible. AutoCAD now has the power to make things invisible (if you did not know). So, I pulled up a trusty macro I built from some other posts and then like magic, the drawing went from 22 mb to 5 mb and converting layers took 10 seconds. Wow. I am posting this gem in case you need some "magic" also.


Public Sub DeleteInvisibleEnts()
'------------------------------------------------------------------------------
'DeleteInvisibleEnts: Makes all objects in an AutoCAD drawing visible.
'
'------------------------------------------------------------------------------
Dim acSs As AcadSelectionSet
Dim dPt1(0 To 2) As Double
Dim dPt2(0 To 2) As Double
Dim acObj As AcadObject
Dim acLyr As AcadLayer
Dim acLyrs As AcadLayers
Dim sCurrLyr As String
Dim iCode(0) As Integer
Dim vVal(0) As Variant
'''''''''''''''''''''''''''''''''''''''

Set acLyrs = ThisDrawing.Layers
iCode(0) = 60 'visibilty pair
vVal(0) = 1 '1=invisible, 0=visible

Set acSs = ThisDrawing.SelectionSets.Add("INVIS")
acSs.Select acSelectionSetAll, dPt1, dPt2, iCode, vVal 'ALL OBJECTS
'------------------------------------------------------------------------------
'Cycle through all objects
'------------------------------------------------------------------------------
For Each acObj In acSs
If acObj.Visible = False Then
sCurrLyr = acObj.layer
Set acLyr = acLyrs.Item(sCurrLyr)
'Check for locked layer, and unlock it if it is
If acLyr.Lock Then
acLyr.Lock = False 'Unlock the Layer.
acObj.Visible = True 'Display the invisible item
acLyr.Lock = True 'Re-lock the Layer.
Else
acObj.Visible = True
End If
End If
acObj.Update
Next acObj
'------------------------------------------------------------------------------
'If you stop here, all invisible items are now visible
'------------------------------------------------------------------------------
Call DeleteAllObjsFromSelSet(acSs) 'A macro to cycle thru and delete the items
ThisDrawing.PurgeAll
If Not acSs Is Nothing Then
acSs.Delete
End If

End Sub


No comments: