27 | 06 | 2017

Search and Zoom object

The Function below shows how to search modelspace for blocks and them Zoom them in to the center of the screen.

Function ZmBlock1(ByVal Blockname As String)


'****************************************
'*** Code from VisibleVisual.com ********
'****************************************

On Error Resume Next
'Search All blocks in Modelspace and Zoom when found
Dim minPt As Variant
Dim maxPt As Variant
Dim varPt As Variant
Dim objBlkRef As AcadBlockReference
Dim StrYesNo As String
For Each objBlkRef In ThisDrawing.ModelSpace

'Set Blockname to search
If objBlkRef.Name = Blockname Then

'If found then Zoom object
objBlkRef.GetBoundingBox minPt, maxPt
ZoomWindow minPt, maxPt

'Ask Users Input to search for more
ThisDrawing.Utility.InitializeUserInput 0, "Y N"
StrYesNo = ThisDrawing.Utility.GetKeyword(vbCr & "Do you wish to search modelspace for the next block?[Y/N]:")

If StrYesNo <> "Y" Then Exit Function

End If

ThisDrawing.Utility.Prompt "Done. No more blocks found..."
Next


End Function
 

Sub test()

'Add blockname to Search
ZmBlock1 "Blockname"

End Sub

 
  
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2288496
Latest Articles