- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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()
edit: is there any better way to create a thumbnail of a block?
Solved! Go to Solution.