×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Instant Measure
10

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.

-handleman, CSWP (The new, easy test)

RE: Instant Measure

Hi handleman
  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

10
(OP)
Did you try running it?

All the actual code is in the Class module called "MyListeningClass"

-handleman, CSWP (The new, easy test)

RE: Instant Measure

Agreed cool macro it might replace the measuring I do with the measure tool also.

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

Thanks handleman. Nice macro. How would I change it to show inches instead of mm?

Regards, Diego

RE: Instant Measure

(OP)
All the measure results are reported by SolidWorks in system units, which are meters and radians.  The code changes the units to mm and degrees.

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

It has to be changed to 1000/25.4 to convert to inches.

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

(OP)
Here's an updated version.  It includes a few more constants at the top for ease of setup.  To change the number of decimals, just add or remove "#" symbols from the DISTFMT or ANGFMT constants.

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

I tried running this in 2009 SP2.1 and it worked but never popped up the tool-tip style box beneath the cursor. It did show up in the bottom left of the status bar. It also is only showing mm measurements.

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

It's fine with x64 just wasn't hitting the ctrl key while second clicking...

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

lol Handleman you beat me to the punch. Now I'll have to try and merge the docs. XD

RE: Instant Measure

(OP)
Do make it launch the macro with SW, you need to create a new shortcut to SolidWorks and add "/m" and then the macro path, like:

"C:\Program Files\SolidWorks 2009\SolidWorks\SLDWORKS.exe" /m  "c:\swmacrostuff\smartmeasure.swp"

-handleman, CSWP (The new, easy test)

RE: Instant Measure

(OP)
Possible warning:

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

Yes I've had plenty of problems running SW across two monitors on many different versions. I've personally never seen the need, I like having other stuff on my second monitor anyhow. I know that was terribly helpful. =P

RE: Instant Measure

(OP)
Here's a VSTA .Net DLL version. It should be lighter weight than the text macro version.  I've incorporated Dissymmetry's changes (using an ellipsis rather than an asterisk to indicate rounding).

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

Handleman, how do you run the .DLL files?  There are 5 of them, do you double-click the "SmartMeasure.dll" or what?

Flores

RE: Instant Measure

(OP)
You can't just double-click it from Windows Explorer.  You have to run it by going to Tools->Macro->Run and browsing to it.  You may have to change the file type filter to "SW VSTA Macros (*.dll)" to get it to show up.  Let me know if that doesn't work.

-handleman, CSWP (The new, easy test)

RE: Instant Measure

Thanks Handleman, I had to change it to "SW VSTA Macros (*.dll)".  Works great!

Flores

RE: Instant Measure

How do you select now the number of decimals?

RE: Instant Measure

(OP)
Shoot, I knew there was something I was forgetting.  I need to figure out how to put that into an .ini file or something since the .dll isn't editable.  GetCurrentMacroPathName doesn't seem to work from the .dll.

-handleman, CSWP (The new, easy test)

RE: Instant Measure

handleman,
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

If you're thinking of using an .ini file to store settings, consider using registry entries instead.

RE: Instant Measure

When you state to change it to "SW VSTA Macros (*.dll)" how and what are we changing.  New at this so more help would be great.

Thanks in advance

RE: Instant Measure

(OP)
The VSTA macros only work on 2009, so if you're running something earlier than that it won't work.  If you are on 2009, go to Tools->Macro->Run.  It will bring up a dialog box to browse for files.  Change the file type filter in that dialog to "SW VSTA...." and browse to wherever you put the unzipped .dll files.  Choose SmartMeasure.dll.

-handleman, CSWP (The new, easy test)

RE: Instant Measure

handleman,
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

Dim Listener As New MyListeningClass
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

(OP)
That's a tough one to debug.  I'm guessing that the real error is happening somewhere inside the MyListeningClass.  The VBA debugger often has problems highlighting the actual error when it's inside a form or class.

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

Dissymmetry,

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

Using SW 09 and I downloaded the zip file for smartmeasure, now I changed the properties in the icon that starts SW with
"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

DOH! ShowSmartMessage doesn't exist until SW2009 (I think).

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

(OP)
Ken,
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.  smile

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'll work on a back-to VBA version of what you have. I'd like to incorporate the changes you've made, but I'm going to stay with VBA so I can make my own edits easily. =P I'll post it when it's done.

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

Attached is version VBA 2.0a

' 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

One thing I noticed the VBA version is not doing is showing the information of a single entity like the vsta version does. I must have missed something or not had all the code?

RE: Instant Measure

(OP)
You might want to look at the VBA version I uploaded in response to Ken, which uses the callout rather than a SmartMessage.  Using the callout extends the usability to 2008.  If you really wanted to get fancy, you could detect which version is running and decide which to use.  

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

Yea I fixed the single pick issue in 0.2c

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

Handleman,

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

Has anyone else out there used the SW2008 version? I had tested it in assembly mode, but I have not spent any real time in Assembly mode using it...Turns out SW2008 crashes if I try to mate anything with the SmartMeasure active.

Ken

RE: Instant Measure

(OP)
Wow, it really crashes, doesn't it?  The line it doesn't seem to like is the one where it actually is supposed to set the callout.  I can comment that line out and debug.print the content of WriteString while mating, etc, with no problem.  Alternately, with the callout line un-commented, I can add mates with my mating macros but SW crashes immediately if I try to add mates through the standard UI.  About the only semi-solution I can think of would be to write the string to the Status Bar.  Not exactly ideal because you have to look down in the corner of the screen for the result.

-handleman, CSWP (The new, easy test)

RE: Instant Measure

Yea I primarily us the mating macros too, so it took a while to surface.

Thanks for the input. Talk to you later,
Ken

RE: Instant Measure

I modified the SW2008 version:

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

(OP)
Ken,
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

(OP)
I was thinking about this over lunch.  It's currently not all that efficient, because every time SW is idle it runs through that sub.  So I changed it a bit.  Now, at the end of the MeasureIt routine, the SldWorks.SldWorks object "swSessionToWriteTo" is set to the current application instance.  This instance is monitored for the OnIdleNotify event, but then set = Nothing by that code so that it's not triggered again until after MeasureIt runs again.  This should reduce the processor load.

-handleman, CSWP (The new, easy test)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources