SIR,
When nodes are selected and wanted to zoom to that selection is easier
if provided this to zoom to selection for nodes as well
regards
sriram
Here is a "Zoom to Selected Nodes" macro that I wrote:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
'2018-08-04 Option Explicit Sub JQ_Zoom_to_Selected_Nodes() Const strmacroname = "JQ Zoom to Selected Nodes" Dim sr As ShapeRange Dim srCurvesSel As ShapeRange Dim s As Shape Dim dblAllXMin As Double Dim dblAllXMax As Double Dim dblAllYMin As Double Dim dblAllYMax As Double Dim dblAllWidth As Double Dim dblAllHeight As Double Dim dblCrvXMin As Double Dim dblCrvXMax As Double Dim dblCrvYMin As Double Dim dblCrvYMax As Double Dim dblViewXMin As Double Dim dblViewXMax As Double Dim dblViewYMin As Double Dim dblViewYMax As Double Dim noderangeThis As NodeRange Dim blnFoundNodesSelected As Boolean Dim dblMinViewSizeDocUnits As Double '''''''''''''''''''''''''''''''''''''''''''''''''''' 'This sets the minimum view size in 1/10 micrometers. Const dblMinViewSizeTenthMicrons As Double = 500000 'This sets the "padding" of the view area as a percentage of the dimensions 'of the area that contains the selected nodes. Const dblPadPercentage As Double = 20 '''''''''''''''''''''''''''''''''''''''''''''''''''' On Error GoTo ErrHandler If ActiveDocument Is Nothing Then MsgBox "No document is active.", vbInformation, strmacroname GoTo ExitSub Else Set sr = ActiveSelectionRange Set srCurvesSel = sr.Shapes.FindShapes(, cdrCurveShape, False) If srCurvesSel.Count = 0 Then MsgBox "No Curves are selected.", vbInformation, strmacroname GoTo ExitSub End If End If For Each s In srCurvesSel Set noderangeThis = s.Curve.Selection With noderangeThis If .Count > 0 Then If blnFoundNodesSelected Then dblCrvXMin = .PositionX dblCrvXMax = .PositionX + .SizeWidth dblCrvYMax = .PositionY dblCrvYMin = .PositionY - .SizeHeight If dblCrvXMin < dblAllXMin Then dblAllXMin = dblCrvXMin End If If dblCrvXMax > dblAllXMax Then dblAllXMax = dblCrvXMax End If If dblCrvYMin < dblAllYMin Then dblAllYMin = dblCrvYMin End If If dblCrvYMax > dblAllYMax Then dblAllYMax = dblCrvYMax End If Else dblAllXMin = .PositionX dblAllXMax = .PositionX + .SizeWidth dblAllYMax = .PositionY dblAllYMin = .PositionY - .SizeHeight blnFoundNodesSelected = True End If End If End With Next s If blnFoundNodesSelected Then dblMinViewSizeDocUnits = ActiveDocument.ToUnits(dblMinViewSizeTenthMicrons, cdrTenthMicron) dblAllWidth = dblAllXMax - dblAllXMin If dblAllWidth > dblMinViewSizeDocUnits Then dblViewXMin = dblAllXMin - dblPadPercentage / 100 * dblAllWidth dblViewXMax = dblAllXMax + dblPadPercentage / 100 * dblAllWidth Else dblViewXMin = dblAllXMin - (dblMinViewSizeDocUnits - dblAllWidth) / 2 - dblPadPercentage / 100 * dblAllWidth dblViewXMax = dblAllXMax + (dblMinViewSizeDocUnits - dblAllWidth) / 2 + dblPadPercentage / 100 * dblAllWidth End If dblAllHeight = dblAllYMax - dblAllYMin If dblAllHeight > dblMinViewSizeDocUnits Then dblViewYMin = dblAllYMin - dblPadPercentage / 100 * dblAllHeight dblViewYMax = dblAllYMax + dblPadPercentage / 100 * dblAllHeight Else dblViewYMin = dblAllYMin - (dblMinViewSizeDocUnits - dblAllHeight) / 2 - dblPadPercentage / 100 * dblAllHeight dblViewYMax = dblAllYMax + (dblMinViewSizeDocUnits - dblAllHeight) / 2 + dblPadPercentage / 100 * dblAllHeight End If ActiveWindow.ActiveView.ToFitArea dblViewXMin, dblViewYMax, dblViewXMax, dblViewYMin Else MsgBox "No nodes are selected in the selected Curves.", vbInformation, strmacroname End If ExitSub: Exit Sub ErrHandler: MsgBox "Error occurred: " & Err.Description & vbCrLf & vbCrLf & "JQ_Zoom_to_Selected_Nodes()" Resume ExitSub End Sub
.
The code above was revised on 2018-08-04 after I found some errors. For selection areas smaller than the minimum view size, I was not applying the "padding". If a selection were just slightly smaller than the minimum view size, then the zoom would give it almost no padding.
I've made some changes to make it more convenient to change the settings for this macro, which is something that one might or might not wish to do fairly often. It would depend on the variety of work one is doing, and on personal preference.
The .GMS file:
JQ_Zoom_to_Selected_Nodes_2018_08_04_2343.zip
When that is installed, it looks like this in the Macro Manager:
The JQ_Zoom_to_Selected_Nodes sub is the one that is run to make the "zoom to selected nodes" take place. That's the sub to which one would assign a keyboard shortcut for frequent use, or perhaps a button on a CommandBar.
For this version, no editing of the VBA code is necessary to change the settings. Instead, there is a userform for that, launched by the Start_Zoom_to_Selected_Nodes_Settings sub:
Each of those ComboBoxes can remember up to ten "most recently used" values, and the information is persistent between sessions (stored in the Registry). The "Clear MRU Lists" button clears all values from both of these lists.
The Remove_Zoom_to_Selected_Nodes_Settings_Registry_Entries does just what the name implies.
Here's a video where I show this macro in use. I've assigned "N" as the keyboard shortcut.
Zoom to Selected Nodes demo 01
Edited 2018-08-04 - new .GMS file that fixes a problem where the "padding" was not being correctly figured for certain sizes of selections.
Thank you John for writing this awesome macro (and shark_ too of course), and thank you pkg_sriram for the request.This is an enhancement that I have been thinking about several times.It is incredibly useful and should of course be one of the standard zoom levels in Draw.The standard shortcut could be the same as Zoom to Selected (objects/nodes depending on selection).Funny that no one (myself included) to my knowledge has asked for this before.Thanks again, all of you.
In addition to what I wrote in previous post John (maybe I'm asking for too much), would it be possible to combine the Zoom to Selected/All macro that you wrote a while ago, with this Zoom to Selected Nodes macro?I'm thinking like this:With one single shortcut or button we can 1.) zoom to selected objects, or 2.) zoom to selected nodes, or 3.) if nothing is selected then zoom to all objects or maybe full page (optional)?Add the ability to adjust padding like you did with nodes.Wouldn't that be nice?
eskimo sir,
Can you give this for only one command for all types of graphics,
For instance... if i select the text , it zooms to selection. similarly it selects the nodes to zoom to selection, similarly if i select segement (like shen i select the segment using shape tool, where a small dot is displaed that segment is selected)
Only one command, not a separate commands for zoom to selection
Ronny Axelsson said:With one single shortcut or button we can 1.) zoom to selected objects, or 2.) zoom to selected nodes, or 3.) if nothing is selected then zoom to all objects or maybe full page (optional)?Add the ability to adjust padding like you did with nodes.
I really like that idea, Ronny!
I especially like the idea of having user-selectable "padding" and "minimum view area" applied when performing a zoom to selected objects. That would be especially useful when I have selected a very tiny object (usually from imported content).
pkg_sriram said:For instance... if i select the text , it zooms to selection. similarly it selects the nodes to zoom to selection, similarly if i select segement (like shen i select the segment using shape tool, where a small dot is displaed that segment is selected)
Selected text: yes, I think I could do that.
Selected segment: I don't know of a way to do that.
If I knew of a way to find out (through the API) if a segment is selected in that way, then I could do it. Perhaps someone knows how, and will share that information.