repeating a click event

repeating a click event

a.kouchakzadeh
Advocate Advocate
1,034 Views
6 Replies
Message 1 of 7

repeating a click event

a.kouchakzadeh
Advocate
Advocate

Hi

I've got a code that populates a listbox with available blocks. then when an item is clicked it triggers the listbox_click() procedure , which inserts the selected block in a specific point, gets the block bounding box, zooms to the bounding box the exports an Image "wmf" file so i can use it to preview the block in an image contro.

I have 2 questions: 1) how to get the current view coordinates so i can return to the current view after the image is created, instead of staying on the bounding box view

2) how to repeat the Listbox_click() procedure for each time the user picks a block from the listbox until a command button is hit or until the user clicks an item from the second list box

 

here is the code:

 

Private Sub UserForm_Activate()


Dim B As AcadBlocks
Dim i As Integer
Set B = ThisDrawing.Blocks
For i = 0 To B.Count - 1
lstblock.AddItem B(i).Name
Next i


Dim ly As AcadLayer
For Each ly In ThisDrawing.Layers
lstlayer.AddItem ly.Name
Next


End Sub

 

Private Sub lstblock_click()

'///////////////////////////////////////////////// image ///////////////////////////////////////////////////////////////////////

'While lstlayer_Click() Is Nothing



Dim selected_block As String
selected_block = lstblock.Text

Dim blockRefObj As AcadBlockReference
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0: insertionPnt(1) = 0: insertionPnt(2) = 0

'Insert Block
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, selected_block, 1#, 1#, 1#, 0)

Dim minPt As Variant
Dim maxPt As Variant

blockRefObj.GetBoundingBox minPt, maxPt
minPt(0) = minPt(0) - 2
minPt(1) = minPt(1) - 2
maxPt(0) = maxPt(0) + 2
maxPt(1) = maxPt(1) + 2

ZoomWindow minPt, maxPt

ThisDrawing.Regen acActiveViewport

'Make SelectionSets

On Error Resume Next
ThisDrawing.SelectionSets("set3").Delete
On Error GoTo 0
Set preview_sset = ThisDrawing.SelectionSets.Add("set3")

Dim filter_type(1) As Integer
Dim filter_data(1) As Variant

filter_type(0) = 0
filter_type(1) = 2
filter_data(0) = "insert"
filter_data(1) = selected_block

preview_sset.Select acSelectionSetAll, , , filter_type, filter_data

'Block Export image(wmf)

image_file = ThisDrawing.Path & "\" & selected_block

ThisDrawing.Export image_file, "wmf", preview_sset

image_file = image_file & ".wmf"

UserForm1.Controls("thumbnail").Picture = LoadPicture(image_file)
UserForm1.Controls("thumbnail").PictureAlignment = fmPictureAlignmentCenter
UserForm1.Controls("thumbnail").PictureSizeMode = fmPictureSizeModeZoom

preview_sset.Item(0).Delete
preview_sset.Delete

ThisDrawing.Application.Update

MsgBox "end of preview"

 

"rest of the code"

 

end sub()

 

Capture.JPG

 

edit: is there any better way to create a thumbnail of a block?

0 Likes
Accepted solutions (2)
1,035 Views
6 Replies
Replies (6)
Message 2 of 7

seabrahenrique
Advocate
Advocate

Hi mate

 

To use a Listbox_click() procudure u have to use something we call a "programation oriented by events". Put this code here in the same place that u puted the code "Userform_Activate()":

 

Private Sub ListBox1_Click()

'First way
MsgBox Me.ListBox1.Value

'Second way
For i = 0 To ListBox1.ListCount - 1
    If Me.ListBox1.Selected(i) = True Then MsgBox Me.ListBox1.List(i)
Next i

End Sub

 

He calls two ways to show the active value in yout list box by a trigger "Listbox1_Click()"

 

So, now for another question, about the current view coords...

 

The block reference.insertion point is not better than this procediment?

0 Likes
Message 3 of 7

a.kouchakzadeh
Advocate
Advocate

Unfortunately non of these methods worked.

my problem is how to repeat the click event every time the user clicks on an item in the list box.

when an item is clicked, the programs runs the click procedure and i need a way to make the program to go back to one step before the lstblock_click() procedure.

actually what I want is the user be able to click as many times on the lstblock list box and see the block preview.

 

0 Likes
Message 4 of 7

seabrahenrique
Advocate
Advocate
Accepted solution

Look that discussion here:

 

https://www.cadtutor.net/forum/topic/14065-how-to-get-the-current-views-coords-with-vba/ 

 

I guess can help u about return the current view case!

 

(I’ll understand better about the other question)

0 Likes
Message 5 of 7

a.kouchakzadeh
Advocate
Advocate

Thanks, at least one of my problems were solved.

Im so frustrated with the repeating click event

0 Likes
Message 6 of 7

seabrahenrique
Advocate
Advocate
Accepted solution

I readed u case again, and if i got your situation, u need a code that run every time the user click on listbox, right?

 

Something like this video in attachment, right?

 

Code of vídeo:

 

Private Sub ListBox1_Click()

MsgBox Me.ListBox1.Text

End Sub

Private Sub UserForm_Activate()
Me.ListBox1.AddItem 1
Me.ListBox1.AddItem 2
Me.ListBox1.AddItem 3
End Sub

 

I did not understand what u need other than that. Can u explain better?

0 Likes
Message 7 of 7

a.kouchakzadeh
Advocate
Advocate

exactly what I needed. thanks very much.
I found out what was my problem. too stupid, I had a me.hide command

Edit: errgh I just waisted so much time on this 

thanks for the help @seabrahenrique 

0 Likes