11 Replies Latest reply on May 27, 2009 2:36 PM by Wayne Tiffany

    EditConfiguration3 options

    Wayne Tiffany
      I have a macro that I wrote long ago that has always had a slight bug in it. I have now decided to try to fix it.

      I am using a statement like this [retval = Doc.EditConfiguration3(Name, Name, "", "", OnOff)] to turn on or turn off the Suppress new features and mates box for each config. Works fine except that it turns off the other options also, such as the value used in the BOM for a part number.

      So I decided to look into it and I find that I am stuck on a couple questions.


      The SW help lists the options as this:

      swConfigurationOptions2_e
      swConfigOption_UseAlternateName - TRUE to use an alternate configuration name, FALSE to not

      swConfigOption_DontShowPartsInBOM - TRUE to show sub-assemblies in the Bill of Materials, FALSE to list child components listed in the Bill of Materials

      swConfigOption_SuppressByDefault - TRUE to suppress newly added features and mates in this configuration, FALSE to not

      swConfigOption_HideByDefault - TRUE to hide newly added components to be hidden, FALSE to not

      swConfigOption_MinFeatureManager - TRUE to suppress new components, FALSE to not

      swConfigOption_InheritProperties - Obsoleted

      swConfigOption_LinkToParent - TRUE to link component to parent configuration, FALSE to not

      swConfigOption_DontActivate


      But upon looking in the swconst.tlb file for the values, I find this list:

      Public Enum swConfigurationOptions2_e
      swConfigOption_UseAlternateName = &H1
      swConfigOption_DontShowPartsInBOM = &H2
      swConfigOption_SuppressByDefault = &H4
      swConfigOption_HideByDefault = &H8
      swConfigOption_MinFeatureManager = &H10
      swConfigOption_InheritProperties = &H20
      End Enum

      As you can see, they don't exactly match. Which one is correct?

      The next question is how do I query each config as to each of those settings such that I can build the proper value to put back into the EditConfiguration3 statement? I want to modify the Suppress new features and mates value but leave the others as they are currently set.

      Any thoughts?

      WT
        • EditConfiguration3 options
          Josh Brady
          Here's my thought: Don't use EditConfiguration3. Instead, use the method in http://forum.solidworks.com/fo...atid=26&threadid=21431
            • EditConfiguration3 options
              Wayne Tiffany
              Josh,

              Interesting approach - I wonder if that call was available years ago when i originally wrote the macro.

              Does it also work with an assy file? In my existing one, I determine if the active doc is a part or assy file and the set things accordingly.

              What was killing me on the old one was that we set our BOM part number as the user defined value. If I then ran the macro on a file that had all those part numbers set, such as our angle or channel raw material template, then it would reset all configs to use the doc name instead. Thus the desire to fix it. I'll look into this tomorrow when I get to work.

              WT
            • EditConfiguration3 options
              jm sculley
              <snip><br /><br /><br /><br />As you can see, they don't exactly match.  Which one is correct?<br /><br /><br /><br />Both technically.  The docs aren't very well written.  The option is a bitmask.  To understand bitmasks it helps to have a background in programming beyond VB.  <br /><br />You can set the bits you want by adding them together.  So, if you want<br /><br />swConfigOption_SuppressByDefault(4) <br />and <br />swConfigOption_HideByDefault(8) <br /><br />you pass in the value 12.<br /><br /><div class='jive-quote'><p style='min-height: 8pt; padding: 0px;'> </p><p><i><br />The next question is how do I query each config as to each of those settings such that I can build the proper value to put back into the EditConfiguration3 statement?  I want to modify the Suppress new features and mates value but leave the others as they are currently set.<br /><br /></i></p></div>Checking or unsetting bits is a little trickier.  Say you have the bits set as above.  In binarry, 12 looks like this:<br /><br />1100<br /><br />The 1's are set bits, the 0's are unset.  The bits read right to left and the value associated with a bit is 2 raised to the power 'x' where 'x' is the bit position.  So, the right most bit is 2^0 or 1.  The next bit is 2^1 or 2. And so on.  Bottom line, the values double as you move to the left.  1...2...4...8...16...32...64.<br /><br />To check a bit, you need to do a bitwise AND of the bitmask with the value you want to check for.  The bitwise AND checks each bit of the numbers you want to check and if the bits match, a 1 is output for that bit in the result.  Otherwise a zero is output.  <br /><br />result = bitmask And bitToCheck<br /><br />Since each discrete value of a bitmask has only one bit set in it, the result will either be 0 or the bit you are checking for.<br /><br /><br />For example, to check if our bitmask (12) has the swConfigOption_SuppressByDefault bit (4) set you do this:<br /><br />result = bitmask And bitToCheck<br /><br />or<br /><br />result = 12 And 4<br /><br />In binary:<br /><br />1100<br />0100<br />------<br />0100   <------  This is just our bit (4)<br /><br />So:<br /><br />If (bitmask And bitToCheck) = bitToCheck Then<br />    'Bit is Set<br />Else<br />    'Bit is not set<br />End If<br /><br />To unset a bit, just subtract it from the bitmask.  Using our example to unset the swConfigOption_SuppressByDefault bit (4):<br /><br />bitmask = bitmask - bitToSet<br />bitmask = 12 - 4 <br /><br />The result is bitmask is now 8 which represents only the swConfigOption_HideByDefault(8)  being set.<br /><br /><br />In binary:<br /><br />  1100<br />- 0100<br />--------<br />  1000<br /><br /><br />Clear as mud?<br /><br /><br />Jim S.<br /><br />
                • EditConfiguration3 options
                  Wayne Tiffany
                  My main question on the differences was that the help file listed more items than the tlb file. I would think that the enumerated values in the tlb file would be the gospel as that controls the possible values. If that's so, then how would the additional values described in the help file be counted?

                  As for the values, your description of the bitmask was good - thanks. I did understand the hex & binary value scheme. Kind of a neat thing, actually. And it makes sense in that you are saying that since I want to change only one parameter and not affect the others, and I know the value of that parameter, then I can either add or subtract that value and I don't really even care what the others are as they stay the same. Ok, then what would be the call to ask for that existing value?

                  WT
                    • EditConfiguration3 options
                      J Sculley

                      Wayne Tiffany wrote:

                       

                      My main question on the differences was that the help file listed more items than the tlb file. I would think that the enumerated values in the tlb file would be the gospel as that controls the possible values. If that's so, then how would the additional values described in the help file be counted?

                      The two files match on my machine. Did you miss a help file or API update perhaps?

                      I program using C++, so I'm using a .tlh file that is generated from the .tlb file. In the .tlh file, the enumeration looks like this:


                      swConfigurationOptions2_e
                      {
                      swConfigOption_UseAlternateName = 1,
                      swConfigOption_DontShowPartsInBOM = 2,
                      swConfigOption_SuppressByDefault = 4,
                      swConfigOption_HideByDefault = 8,
                      swConfigOption_MinFeatureManager = 16,
                      swConfigOption_InheritProperties = 32,
                      swConfigOption_LinkToParent = 64,
                      swConfigOption_DontActivate = 128
                      };


                      The sldworksapi.chm file on my machine has a creation date of December 11,2008 at 3:38:32 PM. File size is 16,488,931 bytes. The swconst.tlb file was created March 19,2009 at 2:49:46 AM. File size is 440,912 bytes. Compare these with yours.

                      This is Windows XP x64. SW 2009 SP3.0.

                      In any event the discrepancy in values would seem to be a moot point. The 'Remarks' section of my API docs state that the only valid bits for this particular method are


                      swConfigOption_SuppressByDefault
                      swConfigOption_HideByDefault
                      swConfigOption_MinFeatureManager


                      I believe my testing has shown that


                      swConfigOption_UseAlternateName


                      is also allowed.


                       


                      As for the values, your description of the bitmask was good - thanks. I did understand the hex & binary value scheme. Kind of a neat thing, actually. And it makes sense in that you are saying that since I want to change only one parameter and not affect the others, and I know the value of that parameter, then I can either add or subtract that value and I don't really even care what the others are as they stay the same. Ok, then what would be the call to ask for that existing value?

                      There doesn't seem to be one for this particular method.



                        • EditConfiguration3 options
                          Wayne Tiffany

                          J Sculley wrote:

                           

                          The sldworksapi.chm file on my machine has a creation date of December 11,2008 at 3:38:32 PM. File size is 16,488,931 bytes. The swconst.tlb file was created March 19,2009 at 2:49:46 AM. File size is 440,912 bytes. Compare these with yours.

                          Same here.

                          J Sculley wrote:

                           

                          This is Windows XP x64. SW 2009 SP3.0.

                          Same here.


                          J Sculley wrote:

                           

                          I believe my testing has shown that


                          swConfigOption_UseAlternateName


                          is also allowed.

                          I have found that also. Interesting, eh?


                          J Sculley wrote:

                           

                          There doesn't seem to be one for this particular method.

                          Bummer!
                    • EditConfiguration3 options
                      Josh Brady
                      As far as I know, the SuppressNewFeatures property works the same for both parts and assemblies. The checkbox is just different on assemblies ("Suppress new features and mates"). As far as SW is concerned, a mate is just another type of feature.
                        • EditConfiguration3 options
                          Wayne Tiffany

                          Josh Brady wrote:

                           

                          As far as I know, the SuppressNewFeatures property works the same for both parts and assemblies. The checkbox is just different on assemblies ("Suppress new features and mates"). As far as SW is concerned, a mate is just another type of feature.

                          I thought this would be a simpler way to do it, but then I found this:

                          Remarks
                          This setting applies only to inactive configurations. This property applies to new mates and features for assembly configurations.

                          That complicates things a bit. My old program would turn the setting on or off for all configs based on the choice in a box. If this new call doesn't change the current active config, then you have set all but one. Hmmm.

                          WT
                        • EditConfiguration3 options
                          Josh Brady
                          Yes, I had also noticed that remark in the help, but found as you did that it doesn't seem to be accurate. I didn't feel it needed mentioning in that other (non-API) thread. Would have just caused confusion.
                            • EditConfiguration3 options
                              Wayne Tiffany
                              Josh,

                              Thanks for the point in the right direction. I took your original code, and pulled some of my old code into it to create a new version of the macro called SuppressFeaturesLoop.swp.

                              I added some checking at the beginning that checks the active doc for a part or assy file, and not a drawing, and not nothing, and feeds a message back stating such if necessary.

                              I added a message box that gives the user the choice of whether to check all the Suppress boxes or uncheck them all. Or oops, get me out of here! :-)

                              Then cleared the memory at the end to clean up.

                              I generally use the macro to uncheck them all, make a change to all, then check them all agin to lock the doors. Or the opposite. The point is that you can have them set one way, run it to flip that setting, make your change, then run it again to reset the boxes back the other way. This new code runs much faster than my old macro.

                              The new macro can be found on our KCSWUG site. Go to http://www.kcswug.com/programs/macros/ and grab the file SuppressFeaturesLoop.swp


                              WT