Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to Toggle "Show Component Descriptions". 1

Status
Not open for further replies.

felix7502

Mechanical
Mar 24, 2003
222
Does anyone have a 2007 macro to toggle "Show Component Descriptions" from the Tree Display?
Thanks,
Sylvia
 
Replies continue below

Recommended for you

Code:
Dim swApp As SldWorks.SldWorks
Dim aMod As SldWorks.ModelDoc2
Dim FM As SldWorks.FeatureManager
Dim CurSet As Boolean

Sub main()
On Error GoTo ExitStrategy

Set swApp = Application.SldWorks
Set aMod = swApp.ActiveDoc
Set FM = aMod.FeatureManager
CurSet = FM.ShowComponentDescriptions
If CurSet Then CurSet = False Else CurSet = True
FM.ShowComponentDescriptions = CurSet
ExitStrategy:
Set FM = Nothing
Set aMod = Nothing
Set swApp = Nothing
End Sub

[bat]Honesty may be the best policy, but insanity is a better defense.[bat]
-SolidWorks API VB programming help
 
Or, in a one-liner:

Code:
Sub main()
Application.SldWorks.ActiveDoc.FeatureManager.ShowComponentDescriptions = Not Application.SldWorks.ActiveDoc.FeatureManager.ShowComponentDescriptions
End Sub
 
I knew someone was going to ding me on line count! I did start more compact but some things were not working as advertised. That oddball "If" statement is there because "CurSet = Not Cusret" was not yielding expected result. There were other VB problems, too.
 
I'm guessing your difficulties stemmed from the difference between VBA's Boolean and SolidWorks' VARIANT_BOOL. As I posted elsewhere earlier today, VBA's Boolean True is 1. SW's VARIANT_BOOL True is -1. If you notice, when you record a macro the recorder declares the default Boolstatus variable as a Long rather than a Boolean. VBA usually handles that fairly well, but certain logical comparison constructions come out unexpectedly. If you notice, when you record a macro the recorder declares the default Boolstatus variable as a Long rather than a Boolean. I'm sure SW had a good reason to do what they did, but it sure doesn't make much sense to me, and has really caused me some major head-scratching.
 
Sorry, I can't get either of them to work. Is there a secret you're not sharing? Sylvia
 
Perhaps the secret of copy-and-paste?

Start a brand new macro, delete EVERYTHING, and paste in the code.

I tried handleman's code. Works for me.
 
Nice sarcasm. Mine says "Run time error 438". Sylvia
 
438 ~= "Object does not support this method". Most likely due to VBA not properly connecting w/ SW. Check undet "Tools --> References" in your macro editor to be sure SW API is selected. Also try a reboot (yay!).
 
handleman,

My experience is that most SW API calls return 1 for true bool value wereas VBA returns -1 (cint(True)). What am I missing here?

Regards,

Regg
 
We just upgraded to 2008 over the weekend. It works great now. Thanks for your help. Sylvia
 
Regg,

After re-reading the pertinent section in the API help, it looks like they are saying that there's no way (other than by testing) to know whether any given call that returns a true or false value will return a 1 or -1 for "true". This is not quite what I had posted previously. The help suggests to always compare the returned value to "false". Sorry for any confusion or frustration my previously incorrect posts may have caused!
 
Sylvia,
What's this macro for? You can turn this on manually, no?
I must be missing something here...

Macduff [spin]
Colin Fitzpatrick
Mechanical Design Engineer
Solidworks 2007 SP 5.0
Dell 390 XP Pro SP 2
Intel 2 Duo Core, 2GB RAM
nVida Quadro FX 3450 512 MB

 
Sometimes you want a keyboard shortcut for a command that can't be mapped. The only solution for that is to write a macro. This one is a whole lot simpler than another that I wrote to save two mouse clicks.
 
I guess it depends on how often a function is needed as to whether a macro {assigned key or not) makes sense.

If the function is only used once a week and saves 10 clicks, IMO its not worth assigning and remembering a key. (I have too little working grey matter left for such things). If it's used several times a day but saves only one click then it's probably worth allocating a few brain cells for.

[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor