Unable to Select and Unsuppress Center of Mass Feature

Programming and macros
User avatar
loeb
Posts: 69
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

Unable to Select and Unsuppress Center of Mass Feature

Unread post by loeb »

When I insert a Center of Mass feature, it ends up being suppressed in all the unactive configurations even though I have the "Suppress Feature" setting unchecked in the properties for every configuration. So, I wrote a macro that will iterate through every configuration and every feature, looking for a feature of type "CenterOfMass", then unsuppress it. The problem is that my SelectByID2 statement is returning FALSE. Here's a code snipit. Thanks for your help.

Code: Select all

    While Not swFeat Is Nothing
        If swFeat.GetTypeName = "CenterOfMass" Then
            BoolStatus = swModelDocExt.SelectByID2(swFeat.Name, swFeat.GetTypeName, 0, 0, 0, False, 0, Nothing, 0)
            BoolStatus = swModel.EditUnsuppress2()
        End If
        Set swFeat = swFeat.GetNextFeature
    Wend
by josh » Wed Sep 27, 2023 9:39 am
Don't use SelectByID2. SelectByID is what the macro recorder uses, but it's almost always the wrong thing to use when you're actually writing a macro. In this case, you already have a pointer to the Feature object, which has a Select2 method.

But, in fact, since you already have a pointer to the Feature object, just use the SetSuppression method of the feature. Selecting it is a waste of time because SW will take the time to update the graphics etc to show the selection.

In fact, if you use SetSuppression2 method, you can unsuppress in all configurations at once without having to cycle through.
Go to full post
acmall
Posts: 26
Joined: Wed Mar 17, 2021 7:54 am
Answers: 0
x 30

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by acmall »

To give you another option you can select the Center of Mass in the Feature Tree then go to Edit - Unsuppress - All configurations

I did a quick check in SW2022 SP5.0 and I am not seeing the Center of Mass being suppressed in the non active configurations.
User avatar
gupta9665
Posts: 405
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 426
x 445

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by gupta9665 »

Try this
BoolStatus = swModelDocExt.SelectByID2(swFeat.Name, ucase(swFeat.GetTypeName), 0, 0, 0, False, 0, Nothing, 0)
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
josh
Posts: 293
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 16
x 22
x 500

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by josh »

Don't use SelectByID2. SelectByID is what the macro recorder uses, but it's almost always the wrong thing to use when you're actually writing a macro. In this case, you already have a pointer to the Feature object, which has a Select2 method.

But, in fact, since you already have a pointer to the Feature object, just use the SetSuppression method of the feature. Selecting it is a waste of time because SW will take the time to update the graphics etc to show the selection.

In fact, if you use SetSuppression2 method, you can unsuppress in all configurations at once without having to cycle through.
User avatar
AlexLachance
Posts: 2174
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2353
x 2008

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by AlexLachance »

acmall wrote: Wed Sep 27, 2023 9:04 am To give you another option you can select the Center of Mass in the Feature Tree then go to Edit - Unsuppress - All configurations

I did a quick check in SW2022 SP5.0 and I am not seeing the Center of Mass being suppressed in the non active configurations.
He is looking to do it through API.
User avatar
loeb
Posts: 69
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by loeb »

gupta9665 wrote: Wed Sep 27, 2023 9:34 amTry this
UCASE? That's nuts when swFeat.GetTypeName literally returns "CenterOfMass"

Thanks
User avatar
loeb
Posts: 69
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by loeb »

josh wrote: Wed Sep 27, 2023 9:39 am Don't use SelectByID2. SelectByID is what the macro recorder uses, but it's almost always the wrong thing to use when you're actually writing a macro. In this case, you already have a pointer to the Feature object, which has a Select2 method.

But, in fact, since you already have a pointer to the Feature object, just use the SetSuppression method of the feature. Selecting it is a waste of time because SW will take the time to update the graphics etc to show the selection.

In fact, if you use SetSuppression2 method, you can unsuppress in all configurations at once without having to cycle through.
Thanks, Josh. That works. When I find a feature of the right type, I use
BoolStatus = swFeat.SetSuppression2(swUnSuppressFeature, swAllConfiguration, Nothing)
to unsuppress it in every config all at once.

Now my problem is that this only works for preexisting COM and COMRP features. If I try to do it immediately after creating a COM or COMRP, using
Set COM = swModel.FeatureManager.InsertCenterOfMass
or
COMRP = swModel.FeatureManager.InsertCenterOfMassReferencePoint
they remain suppressed in every other configuration, even after unsuppressing them like you suggested.

I even tried rebuilding after inserting the features, but before unsuppressing them with no luck using:
BoolStatus = swModelDocExt.Rebuild(swRebuildOptions_e.swRebuildAll)
User avatar
gupta9665
Posts: 405
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 426
x 445

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by gupta9665 »

loeb wrote: Wed Sep 27, 2023 11:58 am UCASE? That's nuts when swFeat.GetTypeName literally returns "CenterOfMass"

Thanks
Yes because recorder was spiting "CenterOfMass" as "CENTEROFMASS".
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
loeb
Posts: 69
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by loeb »

gupta9665 wrote: Thu Sep 28, 2023 6:56 am Yes because recorder was spiting "CenterOfMass" as "CENTEROFMASS".
I don't use the macro recorder. When I use print.debug to print the type, it was in mixed case..
User avatar
gupta9665
Posts: 405
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 426
x 445

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by gupta9665 »

loeb wrote: Thu Sep 28, 2023 9:38 am I don't use the macro recorder. When I use print.debug to print the type, it was in mixed case..
That is correct and that is how I started to check. But when it did not worked, then I use the recorder and then found the mystery of upper case.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
acmall
Posts: 26
Joined: Wed Mar 17, 2021 7:54 am
Answers: 0
x 30

Re: Unable to Select and Unsuppress Center of Mass Feature

Unread post by acmall »

AlexLachance wrote: Wed Sep 27, 2023 11:17 am He is looking to do it through API.
Point taken!

When I read the original post I was not sure if the API route was being taken because he was not aware there is a built in option to unsuppress features in all configurations hence the suggestion. If he already knew about this well and good but I think it is always good to make sure.
Post Reply