BOM Sorting Issue

Programming and macros
User avatar
gupta9665
Posts: 357
Joined: Thu Mar 11, 2021 10:20 am
Answers: 20
Location: India
x 376
x 412

BOM Sorting Issue

Unread post by gupta9665 »

I'm using the attached BOM Sorting macro to sort the BOMs in my drawing. The macro works perfectly for smaller sized BOMs but give inconsistent results when using with a BOM of large assembly (100 + rows). Anyone has faced similar issues? If yes where you able to find any solution or workaround?

Unfortunately I can not share the files.

Thank you in advance for any help.
BOM SORTING.swp
(29.5 KiB) Downloaded 252 times
by Hansjoerg » Mon Sep 19, 2022 3:31 am
What a coincidence, I ran into the exact same problem last week. I have also written a macro to sort the parts list, and also with me the sorting results were partly not correct.

However, for me it was not dependent on the number of lines in the BOM, but on the type of BOM used.

With the type "only parts" it worked correctly. With the type "top level only" the sorting was not usable.

My VAR gave me great support in solving the problem.
He found out that a missing setting in my templates triggered the problem.

I used the following command in the macro to set the missing setting in the template:

IModelDocExtension::SetUserPreferenceToggle(swUserPreferenceToggle_e.swOneConfigOnlyTopLevelBom, swUserPreferenceOption_e.swDetailingNoOptionSpecified, <OnFlag>)

After that, the BOM of the top level were also sorted correctly
Go to full post
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
josh
Posts: 238
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 10
x 18
x 417

Re: BOM Sorting Issue

Unread post by josh »

Have you tried doing a manual sort through the UI using he exact same parameters?

How is it inconsistent? Does the same BOM sort the same every time, just not as you expect? Or does the same BOM sort differently if you run it twice?

You've specified literal sort order. This will cause 10, 11, 12, etc to come before 2. Is that what you're expecting?
User avatar
Hansjoerg
Posts: 106
Joined: Thu Apr 01, 2021 4:17 pm
Answers: 3
x 72
x 55

Re: BOM Sorting Issue

Unread post by Hansjoerg »

What a coincidence, I ran into the exact same problem last week. I have also written a macro to sort the parts list, and also with me the sorting results were partly not correct.

However, for me it was not dependent on the number of lines in the BOM, but on the type of BOM used.

With the type "only parts" it worked correctly. With the type "top level only" the sorting was not usable.

My VAR gave me great support in solving the problem.
He found out that a missing setting in my templates triggered the problem.

I used the following command in the macro to set the missing setting in the template:

IModelDocExtension::SetUserPreferenceToggle(swUserPreferenceToggle_e.swOneConfigOnlyTopLevelBom, swUserPreferenceOption_e.swDetailingNoOptionSpecified, <OnFlag>)

After that, the BOM of the top level were also sorted correctly
All the "good" news about SWX makes me feel like I'm driving a truck with two trailers straight into a dead end.
User avatar
AlexLachance
Posts: 1935
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2079
x 1802

Re: BOM Sorting Issue

Unread post by AlexLachance »

Hansjoerg wrote: Mon Sep 19, 2022 3:31 am What a coincidence, I ran into the exact same problem last week. I have also written a macro to sort the parts list, and also with me the sorting results were partly not correct.

However, for me it was not dependent on the number of lines in the BOM, but on the type of BOM used.

With the type "only parts" it worked correctly. With the type "top level only" the sorting was not usable.

My VAR gave me great support in solving the problem.
He found out that a missing setting in my templates triggered the problem.

I used the following command in the macro to set the missing setting in the template:

IModelDocExtension::SetUserPreferenceToggle(swUserPreferenceToggle_e.swOneConfigOnlyTopLevelBom, swUserPreferenceOption_e.swDetailingNoOptionSpecified, <OnFlag>)

After that, the BOM of the top level were also sorted correctly


Now, this is the kind of support we should be having and expecting.
User avatar
gupta9665
Posts: 357
Joined: Thu Mar 11, 2021 10:20 am
Answers: 20
Location: India
x 376
x 412

Re: BOM Sorting Issue

Unread post by gupta9665 »

josh wrote: Sun Sep 18, 2022 6:35 pm Have you tried doing a manual sort through the UI using he exact same parameters?

How is it inconsistent? Does the same BOM sort the same every time, just not as you expect? Or does the same BOM sort differently if you run it twice?

You've specified literal sort order. This will cause 10, 11, 12, etc to come before 2. Is that what you're expecting?
Thank you for your reply Josh.

Manually sorting is working prefect every time with same settings. And this macro works perfect on small top level BOMs but give incorrect results when used on a large assembly BOM.

I've tried changing literal to numeric but macro still doesn't work.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
gupta9665
Posts: 357
Joined: Thu Mar 11, 2021 10:20 am
Answers: 20
Location: India
x 376
x 412

Re: BOM Sorting Issue

Unread post by gupta9665 »

Hansjoerg wrote: Mon Sep 19, 2022 3:31 am My VAR gave me great support in solving the problem. He found out that a missing setting in my templates triggered the problem.

I used the following command in the macro to set the missing setting in the template:

IModelDocExtension::SetUserPreferenceToggle(swUserPreferenceToggle_e.swOneConfigOnlyTopLevelBom, swUserPreferenceOption_e.swDetailingNoOptionSpecified, <OnFlag>)

After that, the BOM of the top level were also sorted correctly
Thank you for your inputs Hansjoerg, let me check with this setting and confirm.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
gupta9665
Posts: 357
Joined: Thu Mar 11, 2021 10:20 am
Answers: 20
Location: India
x 376
x 412

Re: BOM Sorting Issue

Unread post by gupta9665 »

Hansjoerg wrote: Mon Sep 19, 2022 3:31 am I used the following command in the macro to set the missing setting in the template:

IModelDocExtension::SetUserPreferenceToggle(swUserPreferenceToggle_e.swOneConfigOnlyTopLevelBom, swUserPreferenceOption_e.swDetailingNoOptionSpecified, <OnFlag>)

After that, the BOM of the top level were also sorted correctly
Hansjoerg, this setting did the trick. The macro is working perfect now. Thank you for your help.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
Hansjoerg
Posts: 106
Joined: Thu Apr 01, 2021 4:17 pm
Answers: 3
x 72
x 55

Re: BOM Sorting Issue

Unread post by Hansjoerg »

The thanks do not belong to me but to this user -> @RonE
He is the one who found the solution.
All the "good" news about SWX makes me feel like I'm driving a truck with two trailers straight into a dead end.
Post Reply