Hi Eric / Bryco,
I have tried both your suggestions but it just doesn't change the layer of the block..
Just so i have it right in my head, where do i put the function? I'm taking it that it goes before the sub of the main command button or procedure inserting the block, so it calculates the function first. I have it this way but i can't get it to work..
If i post my whole code below (i can't post the userform to go with it but i'm sure you guys can imagine it lol) - oh and excuse any crudeness of coding, i'm pretty much self-taught so any pointers on clean code would be greatly appreciated if you have time:
Option Explicit
Dim response As Integer 'Yes/No..
Dim BlockPoint As Variant 'First Insertion point..
Dim RMblock As AcadBlockReference 'Inserted Revision Marker block..
Dim AttribZ As Variant
Dim CountX As Integer 'Counter..
Dim RMlayer As AcadLayer
' FINISHED..
Private Sub FINISHEDbtn_Click()
Unload Me
End Sub
' HELP..
Private Sub HELPbtn_Click()
'Dim retval
'retval = Shell("C:\Program Files\Internet Explorer\IExplore.exe ""X:\CAD_Tools\Help\RM_help.html""", vbMaximizedFocus)
End Sub
Private Function DoesLayerExist() As AcadLayer
Dim LayerName As String
Dim objLayer As AcadLayer
LayerName = "LSC-REVISIONS_" & revnumCOMBO.Text
For Each objLayer In ThisDrawing.Layers
If UCase(objLayer.Name) = UCase(LayerName) Then
DoesLayerExist = True
RMlayer = objLayer
MsgBox "Layer Does Exist: " & objLayer
Exit Function
End If
Next objLayer
DoesLayerExist = False
MsgBox "Layer Does Not Exist: " & objLayer
RMlayer = ThisDrawing.Layers.Add("LSC-REVISIONS_" & revnumCOMBO.Text)
RMlayer.Plottable = False
End Function
'********************************************
'******** INSERT MARKERS ***********
'********************************************
Private Sub AddMArkersBTN_Click()
revmarkform.Hide
' Check if input is present..
If revnumCOMBO.Text = "" Then
MsgBox "Please enter or select the Revision Number..", vbExclamation, "Revision Markers.."
Exit Sub
End If
If revdateTXT.Text = "" Then
MsgBox "Please enter or select the revision date..", vbExclamation, "Revision Markers.."
Exit Sub
End If
'Get pick point..
'Error Test for GetPoint method..
On Error Resume Next
TryAgain:
BlockPoint = ThisDrawing.Utility.GetPoint(, vbCr & "Pick the first insertion point for the Revision Marker..")
'Insert block..
Set RMblock = ThisDrawing.PaperSpace.InsertBlock(BlockPoint, "P:\CAD_Blocks\PaperSpace Stuff\Program Blocks\Revision Marker.dwg", 1#, 1#, 1#, 0)
RMblock.Layer = DoesLayerExist(objLayer.Name)
AttribZ = RMblock.GetAttributes ' Get Block attributes..
For CountX = LBound(AttribZ) To UBound(AttribZ)
Select Case AttribZ(CountX).TagString
Case "REV_NUM_INDICATOR"
AttribZ(CountX).TextString = UCase(revnumCOMBO.Text)
Case "COMMENTS_DATE"
AttribZ(CountX).TextString = revdateTXT.Text
End Select
Next CountX
ErrHndlr:
If Err.Number <> 0 Then
If Err.Number = -2145320928 Then
GoTo END_DO
End If
Err.Clear
GoTo TryAgain
End If
On Error GoTo ErrHndlr
'*******************************
'** Start the point pick loop **
'*******************************
Do
CountX = CountX + 1 'Add 1 to the counter..
' Error Test for GetPoint method..
'On Error Resume Next
TryAgain2:
BlockPoint = ThisDrawing.Utility.GetPoint(, vbCr & "Pick the insertion point for the next Revision Marker..")
'Insert block..
Set RMblock = ThisDrawing.PaperSpace.InsertBlock(BlockPoint, "P:\CAD_Blocks\PaperSpace Stuff\Program Blocks\Revision Marker.dwg", 1#, 1#, 1#, 0)
RMblock.Layer = DoesLayerExist(objLayer.Name)
AttribZ = RMblock.GetAttributes ' Get Block attributes..
For CountX = LBound(AttribZ) To UBound(AttribZ)
Select Case AttribZ(CountX).TagString
Case "REV_NUM_INDICATOR"
AttribZ(CountX).TextString = UCase(revnumCOMBO.Text)
Case "COMMENTS_DATE"
AttribZ(CountX).TextString = revdateTXT.Text
End Select
Next CountX
ErrHndlr2:
If Err.Number <> 0 Then
If Err.Number = -2145320928 Then
GoTo END_DO
End If
Err.Clear
GoTo TryAgain2
End If
'On Error GoTo ErrHndlr2
On Error GoTo END_DO 'Exit the loop if ENTER or another key is hit (basically an error)..
Loop
'*******************************
'******** End the loop *********
'*******************************
END_DO:
revmarkform.Show
End Sub
'********************************************
'******** INSERT MARKERS ***********
'********************************************
Private Sub revdateTXT_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
revdateTXT.Text = Format(Date, "DD/MM/YYYY")
End Sub
'********************************************
'*************** FORM LOAD ******************
'********************************************
Private Sub UserForm_Initialize()
ThisDrawing.ActiveSpace = acPaperSpace
With revnumCOMBO
.AddItem ("P2")
.AddItem ("P3")
.AddItem ("P4")
.AddItem ("P5")
.AddItem ("P6")
.AddItem ("P7")
.AddItem ("P8")
.AddItem ("P9")
.AddItem ("P10")
.AddItem ("C1")
.AddItem ("C2")
.AddItem ("C3")
.AddItem ("C4")
.AddItem ("C5")
.AddItem ("C6")
.AddItem ("C7")
.AddItem ("C8")
.AddItem ("C9")
.AddItem ("C10")
.AddItem ("AB")
End With
End Sub
'********************************************
'*************** FORM LOAD ******************
'********************************************
'********************************************
'*************** FORM UNLOAD ****************
'********************************************
Private Sub UserForm_QueryClose(Cancel As Integer, closemode As Integer)
response = MsgBox("Are you sure you've finished with the 'Revision Markers'?..", vbQuestion + vbYesNo, "End the Program..")
If response = vbNo Then
Cancel = 1
End If
If response = vbYes Then
Unload Me
End If
End Sub
'********************************************
'*************** FORM UNLOAD ****************
'********************************************