hardwired Posted August 14, 2008 Posted August 14, 2008 Hi, I have this code built into our templates that if any dimension has been text edited, it will flag up (changing the text colour) any dimension that is not dynamic.. But if any dimension is on a locked layer, the routine crashes out. In the code below i added lines of code that i think should be in there (in red), but it doesn't seem to work - flagging up an error of invalid identifier on the '' line Private Sub AcadDocument_BeginSave(ByVal FileName As String) Dim block As AcadBlock Dim ent As AcadEntity Dim DimEnt As AcadDimension Dim override As String Dim LayerX As AcadLayer For Each block In ThisDrawing.Blocks 'Loop through blocks for layouts.. If block.IsLayout Then 'Is the block a layout.. For Each ent In block 'Loop through objects in the layout.. If ent.ObjectName Like "AcDb*Dimension" Then Set DimEnt = ent [color=red]Set LayerX = DimEnt.Layer[/color] [color=red]If LayerX.Lock = False Then 'If layer is not locked..[/color] override = UCase$(DimEnt.TextOverride) If override = "" Then ' Not overridden, so normal dimtext colour should be "ByLayer".. DimEnt.TextColor = acByLayer ElseIf override Like "<>?*" Or override Like "?*<>" Or override Like "?*<>?*" Or override Like "?*\P<>?*" Or override Like "?*<>\P?*" Then ' Overridden but dynamic <>, so dimtext colour should be "ByLayer".. DimEnt.TextColor = acByLayer ElseIf IsNumeric(override) Then ' Overridden and NOT dynamic (dim value as text), so dimtext colour should be "Green".. DimEnt.TextColor = 80 ElseIf IsLike(override, "# [A-Z]*,## [A-Z]*,### [A-Z]*,#### [A-Z]*") Then ' Overridden with text and numerical, so dimtext colour should be "Green".. DimEnt.TextColor = 80 Else ' We failed to trap the override's characteristics so this is "Green".. DimEnt.TextColor = 80 End If 'End if for TextOverride checking.. End If [color=red]Else 'If layer is locked..[/color] [color=red] MsgBox "One or more dimensions are on locked layers. These will be ignored..", vbInformation, ThisDrawing.Name[/color] [color=red] End If 'Is Layer locked?[/color] Next ent 'End ent FOR loop.. End If 'If block is Layout.. Next block 'End main FOR loop.. End Sub Any ideas on how to check for locked layers? I just want to ignore anything on that layer really.. Quote
SEANT Posted August 14, 2008 Posted August 14, 2008 Entity.Layer only returns the name of the layer in which the entity resides. Instead of : Set LayerX = DimEnt.Layer Use: Set LayerX = Thisdrawing.Layers.Item(DimEnt.Layer) Quote
borgunit Posted August 14, 2008 Posted August 14, 2008 Here is one I run quite often... Public Sub UnlockAllLayers() '------------------------------------------------------------------------------ 'Cycle through layer collection, unlock any locked layer '------------------------------------------------------------------------------ Dim acLyrs As AcadLayers Dim acLyr As AcadLayer ''''''''''''''''''''''''''''''''''''''' On Error GoTo ErrHandler Set acLyrs = ThisDrawing.Layers For Each acLyr In acLyrs acLyr.Lock = False Next acLyr Exit Sub ErrHandler: Debug.Print Err.Number, Err.description, " In UnlockAllLayers" End Sub Quote
hardwired Posted August 14, 2008 Author Posted August 14, 2008 I like that idea of unlocking all layers first, but wouldn't that just take more processing time and also, how do i code it so that whatever layers were locked before, will again be locked afterwards? Quote
borgunit Posted August 14, 2008 Posted August 14, 2008 Well, you have to determine what you want to do. If you need to get the layer, check its state, unlock, do something, return it to its previous state, do the next thing. That is fairly straight forward. if you want to remember where everything is set at and then return it to that state later, then you would probably make an array of layer names and their states, do something, and then pull up the array and return them to their previous states. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.