<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Recursively store values in data structure and getting BOM Structure level in Windchill Customization</title>
    <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Recursively-store-values-in-data-structure-and-getting-BOM/m-p/848534#M2667</link>
    <description>&lt;P&gt;Hi All. I have a requirement to store parts while traversing through a multi level BOM structure. So far I have been able to recursively print all the child parts but having a problem add all parts to a list or map ( only adds values of 1st level BOM but not other levels).&lt;/P&gt;&lt;P&gt;Here is the code I am using;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public static List&amp;lt;WTPart&amp;gt; getChildParts(WTPart parentPart) throws WTException {&lt;BR /&gt;ArrayList&amp;lt;WTPart&amp;gt; info = new ArrayList&amp;lt;WTPart&amp;gt;();&lt;BR /&gt;Map&amp;lt;String, List&amp;lt;String&amp;gt;&amp;gt; map = new HashMap&amp;lt;String,List&amp;lt;String&amp;gt;&amp;gt;();&lt;BR /&gt;&lt;BR /&gt;QueryResult queryResult= WTPartHelper.service.getUsesWTParts(parentPart, new LatestConfigSpec());&lt;BR /&gt;// int structure = 1;&lt;BR /&gt;WTPart part=null;&lt;/P&gt;&lt;P&gt;if (queryResult != null){&lt;BR /&gt;while(queryResult.hasMoreElements()){&lt;BR /&gt;Persistable[] persistable=(Persistable[])queryResult.nextElement();&lt;/P&gt;&lt;P&gt;part=(WTPart)persistable[1];&lt;BR /&gt;printMessageToConsole(part.getNumber());&lt;BR /&gt;info.add(part);&lt;BR /&gt;//WTPartUsageLink partLink=(WTPartUsageLink)persistable[0];&lt;BR /&gt;&lt;BR /&gt;getChildParts(part);&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;return info;&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am also trying to get the BOM Structure level. Is there anyway to get this using this piece of code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Mar 2024 14:03:52 GMT</pubDate>
    <dc:creator>WM_9965332</dc:creator>
    <dc:date>2024-03-15T14:03:52Z</dc:date>
    <item>
      <title>Recursively store values in data structure and getting BOM Structure level</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Recursively-store-values-in-data-structure-and-getting-BOM/m-p/848534#M2667</link>
      <description>&lt;P&gt;Hi All. I have a requirement to store parts while traversing through a multi level BOM structure. So far I have been able to recursively print all the child parts but having a problem add all parts to a list or map ( only adds values of 1st level BOM but not other levels).&lt;/P&gt;&lt;P&gt;Here is the code I am using;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public static List&amp;lt;WTPart&amp;gt; getChildParts(WTPart parentPart) throws WTException {&lt;BR /&gt;ArrayList&amp;lt;WTPart&amp;gt; info = new ArrayList&amp;lt;WTPart&amp;gt;();&lt;BR /&gt;Map&amp;lt;String, List&amp;lt;String&amp;gt;&amp;gt; map = new HashMap&amp;lt;String,List&amp;lt;String&amp;gt;&amp;gt;();&lt;BR /&gt;&lt;BR /&gt;QueryResult queryResult= WTPartHelper.service.getUsesWTParts(parentPart, new LatestConfigSpec());&lt;BR /&gt;// int structure = 1;&lt;BR /&gt;WTPart part=null;&lt;/P&gt;&lt;P&gt;if (queryResult != null){&lt;BR /&gt;while(queryResult.hasMoreElements()){&lt;BR /&gt;Persistable[] persistable=(Persistable[])queryResult.nextElement();&lt;/P&gt;&lt;P&gt;part=(WTPart)persistable[1];&lt;BR /&gt;printMessageToConsole(part.getNumber());&lt;BR /&gt;info.add(part);&lt;BR /&gt;//WTPartUsageLink partLink=(WTPartUsageLink)persistable[0];&lt;BR /&gt;&lt;BR /&gt;getChildParts(part);&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;return info;&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am also trying to get the BOM Structure level. Is there anyway to get this using this piece of code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 14:03:52 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/Recursively-store-values-in-data-structure-and-getting-BOM/m-p/848534#M2667</guid>
      <dc:creator>WM_9965332</dc:creator>
      <dc:date>2024-03-15T14:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Recursively store values in data structure and getting BOM Structure level</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Recursively-store-values-in-data-structure-and-getting-BOM/m-p/848727#M2668</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/446940"&gt;@WM_9965332&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to write own function&amp;nbsp;&lt;SPAN&gt;recursively.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;// root function 	
public static void ProjectsTest2(HTTPRequest req, HTTPResponse resp) throws WTException
	{
		WTPart wtp = UtilWTPart.getPartLatestIteration("0000000017"); // own function to search wtp
		List&amp;lt;WTPart&amp;gt; collectedWTPStructure = new ArrayList&amp;lt;&amp;gt;(); // list of all wtparts from all levels
		getAllMultiLevelStructure(wtp,1,collectedWTPStructure); // call recursive funtion
	}
// recursive function
		private static void getAllMultiLevelStructure(WTPart parent, int level, List&amp;lt;WTPart&amp;gt; structureParts) throws WTException
	{
		QueryResult queryResult = WTPartHelper.service.getUsesWTParts(parent, new LatestConfigSpec());

		while (queryResult.hasMoreElements())
		{
			Persistable[] subWTPObj = (Persistable[]) queryResult.nextElement();
			if (subWTPObj[1] instanceof WTPart)
			{
				WTPart subWTP = (WTPart) subWTPObj[1];
				if (!structureParts.contains(subWTP))
				{
					structureParts.add(subWTP);
				}
				getAllMultiLevelStructure(subWTP, level++, structureParts); //recursive call until the wtpart does not have children
			}
		}
	}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PetrH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 12:05:08 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/Recursively-store-values-in-data-structure-and-getting-BOM/m-p/848727#M2668</guid>
      <dc:creator>HelesicPetr</dc:creator>
      <dc:date>2023-01-11T12:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Recursively store values in data structure and getting BOM Structure level</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Recursively-store-values-in-data-structure-and-getting-BOM/m-p/848748#M2669</link>
      <description>&lt;P&gt;Thanks for the reply&amp;nbsp;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/241117"&gt;@HelesicPetr&lt;/a&gt;&amp;nbsp;. One thing I've found is that the parts do not come in order. I'm trying to recreate the multi level BOM report and I need the parts and level to show in a way that the user can interpret which parts are parents and which ones are children&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 12:53:47 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/Recursively-store-values-in-data-structure-and-getting-BOM/m-p/848748#M2669</guid>
      <dc:creator>WM_9965332</dc:creator>
      <dc:date>2023-01-11T12:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Recursively store values in data structure and getting BOM Structure level</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Recursively-store-values-in-data-structure-and-getting-BOM/m-p/848759#M2670</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/446940"&gt;@WM_9965332&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is just example how to use recursive call.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to collect all BOM level information then you need to use different type of variable to save the information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my example I just used a List with WTPart. You can see that I used a level number to show you how to get that information. but the example does not use it.&lt;/P&gt;
&lt;P&gt;You can.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to know the information as a parent-child and so on you need to use better solution to save that information form multilevel structure&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example, use the UsageLink instead of WTPart in the List&amp;lt;&amp;gt; (subWTPObj&lt;STRONG&gt;[0]&lt;/STRONG&gt; instanceof &lt;STRONG&gt;WTPartUsageLink&lt;/STRONG&gt;)&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;use a&amp;nbsp;&lt;STRONG&gt;Map&amp;lt;WTPartUsageLink, int&amp;gt; dataMap&lt;/STRONG&gt; to collect all usageLinks and save a bom level&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;create own Class where you can store variables as parentWTPart, childWTPArt, usageParameters and so on.&lt;/P&gt;
&lt;P&gt;Then you put new own class for each usageLink to a list to process it in the end of collation from all BOM levels.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PetrH&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 13:15:25 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/Recursively-store-values-in-data-structure-and-getting-BOM/m-p/848759#M2670</guid>
      <dc:creator>HelesicPetr</dc:creator>
      <dc:date>2023-01-11T13:15:25Z</dc:date>
    </item>
  </channel>
</rss>

