×
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

Macro to Toggle "Show Component Descriptions".

Macro to Toggle "Show Component Descriptions".

Macro to Toggle "Show Component Descriptions".

(OP)
Does anyone have a 2007 macro to toggle "Show Component Descriptions" from the Tree Display?
Thanks,
Sylvia

RE: Macro to Toggle "Show Component Descriptions".

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

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Macro to Toggle "Show Component Descriptions".

Or, in a one-liner:

CODE

Sub main()
Application.SldWorks.ActiveDoc.FeatureManager.ShowComponentDescriptions = Not Application.SldWorks.ActiveDoc.FeatureManager.ShowComponentDescriptions
End Sub

RE: Macro to Toggle "Show Component Descriptions".

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.

RE: Macro to Toggle "Show Component Descriptions".

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.

RE: Macro to Toggle "Show Component Descriptions".

(OP)
Sorry, I can't get either of them to work. Is there a secret you're not sharing? Sylvia

RE: Macro to Toggle "Show Component Descriptions".

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.

RE: Macro to Toggle "Show Component Descriptions".

(OP)
Nice sarcasm. Mine says "Run time error 438". Sylvia

RE: Macro to Toggle "Show Component Descriptions".

Both work fine for me also.

cheers

RE: Macro to Toggle "Show Component Descriptions".

Could be a problem w/ your VBA.

RE: Macro to Toggle "Show Component Descriptions".

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!).

RE: Macro to Toggle "Show Component Descriptions".

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

RE: Macro to Toggle "Show Component Descriptions".

(OP)
We just upgraded to 2008 over the weekend. It works great now. Thanks for your help. Sylvia

RE: Macro to Toggle "Show Component Descriptions".

Wow!  Installing SW2008 actually fixed something?

RE: Macro to Toggle "Show Component Descriptions".

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!

RE: Macro to Toggle "Show Component Descriptions".

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

RE: Macro to Toggle "Show Component Descriptions".

... but that would be a mouse move and TWO clicks!!

cheers

RE: Macro to Toggle "Show Component Descriptions".

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.

RE: Macro to Toggle "Show Component Descriptions".

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

RE: Macro to Toggle "Show Component Descriptions".

(OP)
macduff-
I'm with a new company where previous employees created numerous Toolbox items with catalog p/ns. We are in the process of assigning random, consecutive p/ns and obsoleting the originals. Many of our assemblies are unique, and can be revised during a slow time, so we are only replacing on an "as needed" basis. As we obsolete, we created a component description that shows what it was replaced with. This macro allows me to toggle the description on to replace and then off when completed. It also helps when searching through the tree for specific items, because we use random p/ns. It was just inconvenient the othe way, and we will use it multiple times a day. Sylvia

RE: Macro to Toggle "Show Component Descriptions".

Thanks for you reply Sylvia. Sounds like you got your work cutout for you.

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

RE: Macro to Toggle "Show Component Descriptions".

handleman:

I've never made much use of the Application keywork in VB.  Can you expound?  Got any links?

Can't use Google for this.  Keywords "VB Application keyword" yields way to much junk.

RE: Macro to Toggle "Show Component Descriptions".

Tick,

I'm not really sure.  Maybe it's VBA-specific?  Program-specific?  I'm pretty much self-taught with all this stuff, so there are some pretty large gaps in my knowledge.  I do know that the object returned is dependent on what program is running the VBA.  For example, if you're using Excel VBA to drive SolidWorks, you can't use Application.SldWorks to get the SolidWorks object.  That's pretty much the limit of my knowledge.  In the code I posted, I'm not really using it any differently than you are.  I just chained a bunch of objects together.

RE: Macro to Toggle "Show Component Descriptions".

I've had spotty results with object chaining in SW API.  That's how I got in the habit of writing variables for each object.

RE: Macro to Toggle "Show Component Descriptions".

Yeah, normally I do as well.  I like to get the IntelliSense (I think that's what they call that dropdown box) help eliminate typos.  I just wanted to rib ya about line count.  big smile

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