Instant Measure
Instant Measure
(OP)
I've always liked the way SW shows certain distance information in the status bar when you select certain entities without having to activate the "measure" tool. However, I use SW stretched across both monitors, so I often have to look to the opposite monitor to get my distance information. Also, it won't do certain things, such as center distance between two cylinders, etc.
With SW2008, we were given API access to the Measure tool and a way to put a popup message on the screen. With those, I've written a little macro that stays active and will auto-measure every time you select two (and only two) entities in a part or assembly. It puts the results in a little box that appears just below the mouse cursor.
While it's still not as powerful as the actual measure tool, I'm guessing this will eliminate about 90% of my uses of it. I can't really see any lag from it, although I haven't tested it on any really big assemblies yet.
With SW2008, we were given API access to the Measure tool and a way to put a popup message on the screen. With those, I've written a little macro that stays active and will auto-measure every time you select two (and only two) entities in a part or assembly. It puts the results in a little box that appears just below the mouse cursor.
While it's still not as powerful as the actual measure tool, I'm guessing this will eliminate about 90% of my uses of it. I can't really see any lag from it, although I haven't tested it on any really big assemblies yet.
-handleman, CSWP (The new, easy test)






RE: Instant Measure
Cool sounding macro, however when I download the file all I get is the following:
Dim Listener As New MyListeningClass
Sub main()
Listener.Connect2SW
End Sub
More?
Gerald W
RE: Instant Measure
All the actual code is in the Class module called "MyListeningClass"
-handleman, CSWP (The new, easy test)
RE: Instant Measure
But...
I ran it but didn't see any popup by my cursor. I very well might be doing something wrong... maybe a screen shot of what it looks like in action?
Thanks
Grant
Applications Engineer
SW2009 X64 SP 1.0
Dell Precision T5400
Nvidia Quadro FX 5600
Xeon 2.5GHz Quad Core, 4GB RAM
XP Pro X64 SP2.0
RE: Instant Measure
Regards, Diego
RE: Instant Measure
-handleman, CSWP (The new, easy test)
RE: Instant Measure
At the very top of the code in the MyListeningClass class module is a constant called "SF". It's currently 1000 to convert m to mm. If you'll change it to 100/2.54 it will convert m to in.
-handleman, CSWP (The new, easy test)
RE: Instant Measure
Is there a way to change the number of decimals shown? Is there a way to adjust the time the box is shown?
RE: Instant Measure
As far as the length of time displayed, there seems to be a 5 second limit, at least on my system. You can change MESSAGETIME to something less than 5, but anything more than 5 will just show the message for 5 seconds.
I've also fixed a little bug where coplanar surfaces report a normal distance of -1000. Now, coplanar surfaces will report a normal distance of 0 as you might expect.
-handleman, CSWP (The new, easy test)
RE: Instant Measure
In one case I select a vertical line and a point, since these do not come up as parallel, but the normal distance and the distance are the same, no results were shown.
Attached are edits that address these issues. I also added the ability to set a fixed decimal size and display a "*" after the numeric value if it's been rounded off. Next edits should probably use the SW unit functions to allow any of the units in the doc options to be used correctly.
RE: Instant Measure
is there a way to have it "load" when solidworks is started sort of like an add in?
Grant
Applications Engineer
SW2009 X64 SP 1.0
Dell Precision T5400
Nvidia Quadro FX 5600
Xeon 2.5GHz Quad Core, 4GB RAM
XP Pro X64 SP2.0
RE: Instant Measure
RE: Instant Measure
"C:\Program Files\SolidWorks 2009\SolidWorks\SLDWORKS.exe" /m "c:\swmacrostuff\smartmeasure.swp"
-handleman, CSWP (The new, easy test)
RE: Instant Measure
On my system I am experiencing some sort of conflict between SW and my display driver's multiple monitor management functions. I'm running a Quadro FX1700 with approved driver. When I have SW set to "enable window spanning across displays" and I launch SW with a shortcut that specifies a macro (any macro, even one that doesn't do anything), any file I open comes up with nothing visible in the graphics area or the feature tree. The window and title bar are still there, but the window contents don't update properly.
If I launch SW without the macro specified, everything works properly. Alternately, if I keep SW on a single screen and launch with macro, everything works.
-handleman, CSWP (The new, easy test)
RE: Instant Measure
RE: Instant Measure
I modified it to show more information as well:
Gives diameter for single-pick of cylinder or circular edge.
Gives length for edge or sketch segment.
For a partial cylinder or arc gives diameter and radius.
I think this has all you need to run the macro.
-handleman, CSWP (The new, easy test)
RE: Instant Measure
Flores
RE: Instant Measure
-handleman, CSWP (The new, easy test)
RE: Instant Measure
Flores
RE: Instant Measure
RE: Instant Measure
-handleman, CSWP (The new, easy test)
RE: Instant Measure
That is so way cool. Another star for you.
Standing
SolidWorks Pro 2009 x64, SP3.0
PDMWorks Workgroup, SolidWorks BOM,
HP xw8600, 64-bit Windows Vista Business, Service Pack 1
Intel Xeon CPU, 3.00 GHz, 16 GB RAM, Virtual memory 166682 MB,
nVidia Quadro FX 4600
RE: Instant Measure
RE: Instant Measure
Thanks in advance
RE: Instant Measure
-handleman, CSWP (The new, easy test)
RE: Instant Measure
I had it working just fine on Friday. Today, not so good.
Today I get:
Run-time error '91':
Object variable or With block variable not set
Then clicking Debug I get the following:
Macro stopped at CallListener
CODE
Sub main()
Listener.Connect2SW
End Sub
In the SolidWorks icon I have:
"C:\Program Files\SolidWorks Corp\SolidWorks\SLDWORKS.exe" /m "C:\Program Files\SolidWorks Corp\SolidWorks\Macros\SmartMeasure.swp"
Do you have any ideas as to what I am doing wrong?
Standing
SolidWorks Pro 2009 x64, SP3.0
PDMWorks Workgroup, SolidWorks BOM,
HP xw8600, 64-bit Windows Vista Business, Service Pack 1
Intel Xeon CPU, 3.00 GHz, 16 GB RAM, Virtual memory 166682 MB,
nVidia Quadro FX 4600
RE: Instant Measure
You may want to try the VSTA version. It does have more features than the VBA one. Here's the source for it, since it doesn't programmatically change precision. There are two constants ANGDEC and DISTDEC at the top of the MeasureClass to set the number of decimal places.
-handleman, CSWP (The new, easy test)
RE: Instant Measure
About the VBA version you updated for 2009...should it work for 2008 if I re-map the references?
I am getting an error and don't understand what call is the culprit.
Thanks,
Ken
RE: Instant Measure
"C:\Program Files\SolidWorks Corp\SolidWorks\SLDWORKS.exe" /m "C:\Program Files\SolidWorks Corp\SolidWorks\Macros\SmartMeasure.dll"
Why is it I still have to execute the macro through the tools menu? I have the dll's in the directory as described in the above. Puzzled in Milwaukee.
RE: Instant Measure
I already took Dissymmetry's version and modified it a little bit. I changed the number of decimals to 8, but set it to drop trailing zeros (my personal preference). Since I took the time to change it already, I figured I would pass it on if anyone else was interested. You'll have to update the References to SW2009, but hopefully it will work after that.
Later,
Ken
RE: Instant Measure
I hate for you to have done that work for nothing! Here's a version that works for 2008. It uses a callout rather than a SmartMessage. The callout looks exactly the same as the SmartMessage except it appears a little bit farther away from the cursor and it has a leader on it. I still have 2008 installed, so I tested and it works.... sort of:
I don't think you're going to like the results from your trailing zero removal routine... It removes the zeros from 100 and leaves you with 1.
I've included the text from my current VSTA version if you want to take a look at it. I think the end result of the VSTA version is going to be what you want as long as you change the constant at the top for precision. It currently rounds to the whatever precision is specified in the constants, but it does drop trailing zeros after the decimal. Rounding is indicated by an ellipsis(...). There were a couple of bugs in the version you had regarding different combinations of selections, etc. Also, the angle (in radians) was being reported by Measure to 8 decimals, but the conversion factor was a full double. That meant that it thought the angle was always being rounded off, and a true 90° was being. reported as 90.000000...°.
I wish I had time to back-convert the full VSTA version to VBA. Sorry!
-handleman, CSWP (The new, easy test)
RE: Instant Measure
I've got a lot of jobs on my desk, so it may be a bit before I get back to it.
RE: Instant Measure
RE: Instant Measure
' Changelog:
' Rev 0.2a
' - Now pulls conversion and unit strings from the current Document units settings.
' - Moved unit conversion and identification inside measure it. If user changes document settings
' after macro is started, now will keep current with document settings.
' Rev 0.2
' - Added ANGSF to convert angle units
' - Added DISTDEC to control displayed precision for linear units
' - Added DISTSYM to pull displayed linear unit symbol from document unit selection
' - Added ANGDEC to control displayed precision for angle units
' - Added ANGSYM to pull displayed angle symbol from document unit selection
' - Added all unit conversions
' - Added format control through FixNumFmt()
' - FixNumFormat also replaces IndicateRound() and now uses "..." instead of "*"
' Rev 0.1c
' - Added MESSAGETIME to allow easier control of tooltip display time
' - Fixed discrepancy in display value for coplanar planes.
' Rev 0.1b
' - Fixed ToolTip not showing
' - Fixed non-display of non parallel entities where normal dist and sit are equal
' - Added feature (set using UFIX constant) to round units to fixed size.
' Rounded values display with an asterisk following the value (IndicateRound Function)
Sorry it's still VBA but it should be very easy to update the vsta version from this code.
RE: Instant Measure
Sorry, dumb error is now fixed.
RE: Instant Measure
RE: Instant Measure
Found what I missed ...
The tool tip is no longer working on my machine now though. No matter which way I flip the switch.
RE: Instant Measure
The reason it's not doing the single-pick stuff is that the event handlers for selection change originally (and currently on your VBA code) only call MeasureIt when the number of selections is 2. The VSTA version calls MeasureIt when there are either 1 or 2 selections.
Not sure why it's not showing the tooltip. It's not showing on my machine either.
-handleman, CSWP (The new, easy test)
RE: Instant Measure
Take a look at the unit conversion method I used, you might like it better than what you have in your current file.
Have a great weekend!
RE: Instant Measure
Thanks for all the valuable info...YET AGAIN! I back-converted your Vista Version to SW2008-VBA. It is attached for anyone else out there stuck in SW2008 :)
To the VBA version, I included:
-Your "Callout" recommendation
-Got the trailing zero removal routine working correctly
-Added functionality to unload the Class...just run the macro a second time and it'll unload if the "swSecession" object already exists.
Thanks again for all the help.
Ken
RE: Instant Measure
Ken
RE: Instant Measure
-handleman, CSWP (The new, easy test)
RE: Instant Measure
Thanks for the input. Talk to you later,
Ken
RE: Instant Measure
For Parts:
-Callout Box still pops up.
-Measurement will also be displayed in lower right of Status Bar (no time limit on that, just waits for another selection to occur).
For Assemblies:
-Measurement will only display in lower right of Status Bar.
Thanks Handleman!
Ken
RE: Instant Measure
Give this one a shot. It uses Windows API DrawText to write the measurement string directly to the window at the mouse cursor location. All of the Windows API stuff is packaged in a separate module, so you can export it and use it again if you should ever want to, Excel, Word, whatever.
I had to make one small change due to the graphics redraw. When the command to write to the screen comes inside the MeasureIt sub, the text gets written to the screen before the view updates to highlight the selections. Of course, when the view updates, it overwrites the directly-written text. I had to make the macro wait for the OnIdleNotify event to actually write the text to the screen, so I turn on a global boolean flag in the MeasureIt sub and turn it back off after writing the text to the screen in the OnIdleNotify event.
-handleman, CSWP (The new, easy test)
RE: Instant Measure
-handleman, CSWP (The new, easy test)