Newbie- Label Showing Active Layer

Newbie- Label Showing Active Layer

Anonymous
Not applicable
808 Views
10 Replies
Message 1 of 11

Newbie- Label Showing Active Layer

Anonymous
Not applicable
Why won't the following show the Active Layer? (Keep getting the debugger bugging me!)

Private Sub Userform_Activate()
Label3.Caption = ThisDrawing.ActiveLayer
End Sub
0 Likes
809 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
Label3.Caption = ThisDrawing.ActiveLayer.Name

wrote in message news:[email protected]...
Why won't the following show the Active Layer? (Keep getting the debugger
bugging me!)

Private Sub Userform_Activate()
Label3.Caption = ThisDrawing.ActiveLayer
End Sub
0 Likes
Message 3 of 11

Anonymous
Not applicable
Thank you Joe!

I'm also trying to make a listbox showing all of the layers in CAD. When the user selects the layer it becomes active.....

Somebody advised the following but it doesn't seem to do anything:

Private Sub ListBox1_Click()
Dim layerObj As AcadLayer
Set layerObj = ThisDrawing.Layers.Item(ListBox1.Text)

End Sub

??
0 Likes
Message 4 of 11

Anonymous
Not applicable
That won't work, use the code below:

ThisDrawing.ActiveLayer = ThisDrawing.Layers(ListBox1.Text)


wrote in message news:[email protected]...
Thank you Joe!

I'm also trying to make a listbox showing all of the layers in CAD. When
the user selects the layer it becomes active.....

Somebody advised the following but it doesn't seem to do anything:

Private Sub ListBox1_Click()
Dim layerObj As AcadLayer
Set layerObj = ThisDrawing.Layers.Item(ListBox1.Text)

End Sub

??
0 Likes
Message 5 of 11

Anonymous
Not applicable
To the OP: Note that the solution to both of your problems in this drawing
had to do with data types. You're on the right track, don't get
discouraged. Just note that data types are extremely important, as you're
seeing. Once you get a fair understanding of the differences between
objects (such as AcadLayer), doubles, integers, strings, etc., it will ar
start flowing very nicely.

..........and books like Mr. Sutphin's don't hurt, either. I'd highly
recommend anything he's written about VBA.

"Joe Sutphin" wrote in message
news:[email protected]...
That won't work, use the code below:

ThisDrawing.ActiveLayer = ThisDrawing.Layers(ListBox1.Text)
0 Likes
Message 6 of 11

Anonymous
Not applicable
I'm struggling a bit. I am using a combination of Mr Sutphins book (very good BTW) and also my own trial and error.
The following seems to always return the MsgBox before I select the entity......sorry if I'm being annoying 😞

Private Sub CommandButton1_Click()
'Allows user to pick entity that contains desired layer
Dim objDrawingObject As AcadEntity
Dim varEntityPickedPoint As Variant

On Error Resume Next
ThisDrawing.Utility.GetLayer objDrawingObject, varEntityPickedPoint, _
"Choose object to take layer from: "
If objDrawingObject Is Nothing Then
MsgBox "You did not choose an object"
Exit Sub
End If

ThisDrawing.ActiveLayer = objDrawingObject

End Sub
0 Likes
Message 7 of 11

Anonymous
Not applicable
My last example must have slipped past you ...

Private Sub CommandButton1_Click()
'Allows user to pick entity that contains desired layer
Dim objDrawingObject As AcadEntity
Dim varEntityPickedPoint As Variant
Dim NewLayer As AcadLayer

Me.Hide

'On Error Resume Next

ThisDrawing.Utility.GetEntity objDrawingObject, varEntityPickedPoint, _
"Choose object to take layer
from: "

If objDrawingObject Is Nothing Then
MsgBox "You did not choose an object"
Exit Sub
End If

'change active layer to that of the object selected
Set NewLayer = ThisDrawing.Layers(objDrawingObject.Layer)
ThisDrawing.ActiveLayer = NewLayer
End Sub

Be carefully how you use On Error Resume Next


wrote in message news:[email protected]...
I'm struggling a bit. I am using a combination of Mr Sutphins book (very
good BTW) and also my own trial and error.
The following seems to always return the MsgBox before I select the
entity......sorry if I'm being annoying 😞

Private Sub CommandButton1_Click()
'Allows user to pick entity that contains desired layer
Dim objDrawingObject As AcadEntity
Dim varEntityPickedPoint As Variant

On Error Resume Next
ThisDrawing.Utility.GetLayer objDrawingObject, varEntityPickedPoint, _
"Choose object to take layer
from: "
If objDrawingObject Is Nothing Then
MsgBox "You did not choose an object"
Exit Sub
End If

ThisDrawing.ActiveLayer = objDrawingObject

End Sub
0 Likes
Message 8 of 11

Anonymous
Not applicable
So close! It all works fine apart from when the user picks nothing and the MsgBox is shown, the program kicks the user out - instead of waiting for another entity to be picked......

I promise that I'll read your chapter on "User Interaction and the Utility Object" before asking any more dumb questions after this one!
0 Likes
Message 9 of 11

Anonymous
Not applicable
Private Sub CommandButton1_Click()
'Allows user to pick entity that contains desired layer
Dim objDrawingObject As AcadEntity
Dim varEntityPickedPoint As Variant
Dim NewLayer As AcadLayer

Me.Hide

On Error Resume Next

Do
ThisDrawing.Utility.GetEntity objDrawingObject, varEntityPickedPoint, _
"Choose object to take layer from:
"
If Not objDrawingObject Is Nothing Then Err.Number = 0
Loop While Err <> 0

'change active layer to that of the object selected
Set NewLayer = ThisDrawing.Layers(objDrawingObject.Layer)
ThisDrawing.ActiveLayer = NewLayer
End Sub


wrote in message news:[email protected]...
So close! It all works fine apart from when the user picks nothing and the
MsgBox is shown, the program kicks the user out - instead of waiting for
another entity to be picked......

I promise that I'll read your chapter on "User Interaction and the Utility
Object" before asking any more dumb questions after this one!
0 Likes
Message 10 of 11

Anonymous
Not applicable
Excellent, you are as tolerant as a mother with a screaming infant. Consider me back under my rock whilst I do a little more learning. Mind you, smoke me a kipper, as I will probably be back for breakfast! (blooming Inputbox - cancel is annoying me now but I'll save that delight for another time).

Cheers.
0 Likes
Message 11 of 11

Anonymous
Not applicable
The user interaction is actually one of the hardest things to get a handle
on, IMO, particularly if you have any background in lisp.

wrote in message news:[email protected]...
So close! It all works fine apart from when the user picks nothing and the
MsgBox is shown, the program kicks the user out - instead of waiting for
another entity to be picked......

I promise that I'll read your chapter on "User Interaction and the Utility
Object" before asking any more dumb questions after this one!
0 Likes