Cancel
Showing results for 
Search instead for 
Did you mean: 

BOM - SOA get BOMWindow with packed BomLines

Creator
Creator

Hi, comunity

 

I' m programing a software to get from TeamCenter via SOA an item/revision BOM.
My code in C# is this:

 

 

using System;
using Teamcenter.Soa.Client.Model;
using Teamcenter.Soa.Client.Model.Strong;
using Teamcenter.Services.Strong.Cad._2007_01.StructureManagement;
using Teamcenter.Soa.Exceptions;
using Teamcenter.Services.Strong.Core;
using Teamcenter.Soa.Common;
using System.Data;

namespace SOA_Interface_Test.logical
{
    class ShowBOM
    {
        private String ItemUID;
        private String ItemRevUID;
        private DataTable BOMListTable;

        private BOMWindow bomWindow = null;

        private DataManagementService dmService;
        private Teamcenter.Services.Strong.Cad.StructureManagementService smService;
        private Item item;

        public ShowBOM()
        {
            dmService = DataManagementService.getService(Teamcenter.ClientX.Session.getConnection());
            smService = Teamcenter.Services.Strong.Cad.StructureManagementService.getService(Teamcenter.ClientX.Session.getConnection());

            BOMListTable1 = new DataTable();
            BOMListTable1.TableName = "BOM_LIST_TABLE";
            SetColumns(BOMListTable1);
        }

        public string ItemUID1 { get => ItemUID; set => ItemUID = value; }
        public string ItemRevUID1 { get => ItemRevUID; set => ItemRevUID = value; }
        public DataTable BOMListTable1 { get => BOMListTable; set => BOMListTable = value; }

        public bool loadItem()
        {
            ServiceData sData = dmService.LoadObjects(new String[] { ItemUID1 });

            if (sData.sizeOfPlainObjects() > 0)
            {
                ModelObject mObj = sData.GetPlainObject(0);

                if (mObj is Item)
                {
                    item = (Item)mObj;     
                    
                    //Properties ofBOMList
                    dmService.GetProperties(new ModelObject[] { mObj }, new String[] { "bom_view_tags", "revision_list" });

                    return true;
                }
            }

            return false;
        }


        public bool showBOMWindowStructure()
        {
            try
            {
                ModelObject[] itemRevs = item.Revision_list;
                ModelObject[] bomViews = item.Bom_view_tags;

                foreach (ModelObject bomView in bomViews)
                {
                    foreach (ModelObject itemRev in itemRevs)
                    {
                        CreateBOMWindowsInfo bomWinInfo = new CreateBOMWindowsInfo();
                        {
                            bomWinInfo.Item = item;
                            bomWinInfo.ItemRev = (ItemRevision)itemRev;
                            bomWinInfo.BomView = (PSBOMView)bomView;
                        };
                        CreateBOMWindowsResponse bomResp = smService.CreateBOMWindows(new CreateBOMWindowsInfo[] { bomWinInfo });
                        if (bomResp.Output.Length > 0)
                        {                            
                            BOMLine bomLine = bomResp.Output[0].BomLine;               

                            expandBOMLines(bomLine);
                        }                                
                    }
                }
            }
            catch (NotLoadedException e)
            {
                Console.WriteLine(e.Message);
            }
            return false;
        }


        public bool showBOMWindowStructure_ItemRev()
        {
            try
            {
                ModelObject[] itemRevs = item.Revision_list;
                ModelObject[] bomViews = item.Bom_view_tags;

                foreach (ModelObject bomView in bomViews)
                {
                    foreach (ModelObject itemRev in itemRevs)
                    {
                        if (ItemRevUID == itemRev.Uid)
                        {
                            CreateBOMWindowsInfo BOMWindows = new CreateBOMWindowsInfo();
                            {

                                BOMWindows.Item = item;
                                BOMWindows.ItemRev = (ItemRevision)itemRev;
                                BOMWindows.BomView = (PSBOMView)bomView;                                
                            };

                            CreateBOMWindowsResponse bomResp = smService.CreateBOMWindows(new CreateBOMWindowsInfo[] { BOMWindows });

                            bomWindow = bomResp.Output[0].BomWindow;

                            if (bomResp.Output.Length > 0)
                            {
                                BOMLine bomLine = bomResp.Output[0].BomLine;

                                expandBOMLines(bomLine);
                            }
                            break;
                        }
                    }
                }
            }
            catch (NotLoadedException e)
            {
                Console.WriteLine(e.Message);
            }
            return false;
        }

        private void expandBOMLines(BOMLine bomLine)
        {
            ExpandPSOneLevelInfo  levelInfo = new ExpandPSOneLevelInfo();
            ExpandPSOneLevelPref levelPref = new ExpandPSOneLevelPref();
    
            levelInfo.ParentBomLines = new BOMLine[] { bomLine };
            levelInfo.ExcludeFilter = "None";
            levelPref.ExpItemRev = false;
            levelPref.Info = new RelationAndTypesFilter[0];
           
            ExpandPSOneLevelResponse levelResp = smService.ExpandPSOneLevel(levelInfo, levelPref);

            try
            {
                LoadProperties(bomLine);

                PrintBomLine(bomLine);
                     
                BomLineTable(bomLine, BOMListTable1);
            }
            catch (NotLoadedException e)
            {
                Console.WriteLine(e.Message);
            }

            if (levelResp.Output.Length > 0)
            {
                foreach (ExpandPSOneLevelOutput levelOut in levelResp.Output)
                {
                    foreach (ExpandPSData psData in levelOut.Children)
                    {
                        expandBOMLines(psData.BomLine);
                    }
                }
            }
        }

        private void LoadProperties(BOMLine bomLine)
        {
            dmService.GetProperties(new ModelObject[] { bomLine }, new String[] {   "bl_line_name",
                                                                                    "bl_item_object_name",
                                                                                    "bl_is_last_child",
                                                                                    "bl_formatted_parent_name",
                                                                                    "bl_sequence_no",
                                                                                    "bl_rev_vv4_tipo",
                                                                                    "bl_level_starting_0"
                                                                                });
        }

        //muestra los datos de la bomline por consola
        private void PrintBomLine(BOMLine bomLine)
        {
            Console.WriteLine("BOMLine: " + bomLine.Bl_line_name +
                                   "\t | Name: " + bomLine.Bl_item_object_name +
                                   "\t | Last_Child: " + bomLine.Bl_is_last_child +
                                   "\t | Formatted Parent Name: " + bomLine.Bl_formatted_parent_name +
                                   "\t | Sequence Number: " + bomLine.Bl_sequence_no +
                                   //propiedad definida (no está en el estándar de TC)
                                   "\t | Type: " + bomLine.GetPropertyDisplayableValue("bl_rev_vv4_tipo") +
                                   "\t | Type: " + bomLine.Bl_level_starting_0
                                   );
        }

        //exporta las properties de la bomLine a una datatable
        private void BomLineTable(BOMLine BOMLine, DataTable BomListTable)
        {
            DataRow row;

            row = BomListTable.NewRow();
            row["BOMLINE_NAME"] = BOMLine.Bl_line_name;
            row["ITEM_NAME"] = BOMLine.Bl_item_object_name;
            row["LAST_CHILD"] = BOMLine.Bl_is_last_child;
            row["FATHER_NAME"] = BOMLine.Bl_formatted_parent_name;
            row["SEQU_NO"] = BOMLine.Bl_sequence_no;
            row["TYPE"] = BOMLine.GetPropertyDisplayableValue("bl_rev_vv4_tipo");
            row["LEVEL"] = BOMLine.Bl_level_starting_0;

            BomListTable.Rows.Add(row);
        }

        private void SetColumns(DataTable BomListTable)
        {
            DataColumn column;

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "BOMLINE_NAME";
            column.ReadOnly = true;
            column.Unique = false;
            BomListTable.Columns.Add(column);

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ITEM_NAME";
            column.ReadOnly = true;
            column.Unique = false;
            BomListTable.Columns.Add(column);

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "LAST_CHILD";
            column.ReadOnly = true;
            column.Unique = false;
            BomListTable.Columns.Add(column);

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "FATHER_NAME";
            column.ReadOnly = true;
            column.Unique = false;
            BomListTable.Columns.Add(column);

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "SEQU_NO";
            column.ReadOnly = true;
            column.Unique = false;
            BomListTable.Columns.Add(column);

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TYPE";
            column.ReadOnly = true;
            column.Unique = false;
            BomListTable.Columns.Add(column);

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "LEVEL";
            column.ReadOnly = true;
            column.Unique = false;
            BomListTable.Columns.Add(column);
        }
    }
}

 

I store the BOM in a DataTable and I get the Item/Rev from a query (wich is not in this code).

I get the BOM, but the lines are not packed. For example, i get this:

 

BOMLine: RT20150604000/c/CONJUNTO EJEMPLO (View)                                      //Level 0   
BOMLine: RT20150604003/A0/PIEZA 3                                    -- Quantity 1            //Level 1
BOMLine: RT20150604003/A0/PIEZA 3                                   --  Quantity 1            //Level 1
BOMLine: RT20141217001/--/Granpa(View)                          --  Quantity 1            //Level1
BOMLine: RT20141217003/--/Father (View)                             --  Quantity 1            //Level 2
BOMLine: RT20141217004/--/Son                                             --  Quantity 1           //Level 3
BOMLine: RT20150604002/--/PIEZA 2                                       --  Quantity 1           //Level1
BOMLine: RT20150602001/A0/PIEZA 1 REV2                           --  Quantity 1           //Level 1

 

And I want to get something like this:

 

BOMLine: RT20150604000/c/CONJUNTO EJEMPLO (View)                                      //Level 0   
BOMLine: RT20150604003/A0/PIEZA 3                                   -- Quantity 2            //Level 1
BOMLine: RT20141217001/--/Granpa(View)                          --  Quantity 1            //Level1
BOMLine: RT20141217003/--/Father (View)                           --  Quantity 1            //Level 2
BOMLine: RT20141217004/--/Son                                            --  Quantity 1           //Level 3
BOMLine: RT20150604002/--/PIEZA 2                                      --  Quantity 2           //Level1
BOMLine: RT20150602001/A0/PIEZA 1 REV2                           --  Quantity 1           //Level 1

 

Thank you so much!!

 

16 REPLIES

Re: BOM - SOA get BOMWindow with packed BomLines

Solution Partner Legend Solution Partner Legend
Solution Partner Legend
You may want to try method StructureService.PackOrUnpack() to achive this.

Re: BOM - SOA get BOMWindow with packed BomLines

Creator
Creator

Ok, I try to set BOM lines unpacked. I add this code to my expandBOMLines method:

 

 ....
using Teamcenter.Services.Strong.Structuremanagement;

private StructureService stService;

        public ShowBOM()
        {
            dmService = DataManagementService.getService(Teamcenter.ClientX.Session.getConnection());
            smService = Teamcenter.Services.Strong.Cad.StructureManagementService.getService(Teamcenter.ClientX.Session.getConnection());
            stService = StructureService.getService(Teamcenter.ClientX.Session.getConnection());
......
}


private void expandBOMLines(BOMLine bomLine) { ExpandPSOneLevelInfo levelInfo = new ExpandPSOneLevelInfo(); ExpandPSOneLevelPref levelPref = new ExpandPSOneLevelPref(); levelInfo.ParentBomLines = new BOMLine[] { bomLine }; levelInfo.ExcludeFilter = "None"; levelPref.ExpItemRev = false; levelPref.Info = new RelationAndTypesFilter[0]; stService.PackOrUnpack(levelInfo.ParentBomLines, 1); ExpandPSOneLevelResponse levelResp = smService.ExpandPSOneLevel(levelInfo, levelPref); .......

}

But there is no changes in the result... Maybe I have not initzialice correctly the object? Or I have to use this in other place, not in the expand method??

 

Thank you so much.

Re: BOM - SOA get BOMWindow with packed BomLines

Solution Partner Legend Solution Partner Legend
Solution Partner Legend

As far as I understand, you want to PACK the lines, but the parameter value you gave in code is to unpack.
------------------------------------------------------------
0:  pack the lines
1:  unpack the lines
2:  pack all lines
3:  unpack all lines
------------------------------------------------------------


Also, according to what I understood from doc, you need to give Child-BOMlines when you want to pack and parent BOMLine as input when you want to unpack.
------------------------------------------------------------
Use Cases:

User calls the operation with some lines to pack them, the lines will be packed.
User calls the operation with root line to unpack the whole structure, all loaded packed lines in the structure will be unpacked.
------------------------------------------------------------

Also, I think you may have to call this function AFTER the BOMLine expansion has been done.

Re: BOM - SOA get BOMWindow with packed BomLines

Solution Partner Legend Solution Partner Legend
Solution Partner Legend

May be option 2 (pack all) and 3 (unpack all) will work with the root/parent BOMLine itself. I have never used this API, so just giving suggestions. I would be interested to know results of your tests.

Re: BOM - SOA get BOMWindow with packed BomLines

Siemens Legend Siemens Legend
Siemens Legend

If you use CreateBOMWindows2 then in the CreateWindowsInfo2 structure you pass to it you can set a number of flags in the BomWinPropFlagMap member.  One of the flags you can set is "is_packed_by_default".  Set this to "true" and your BOMLines should be packed for you.

Re: BOM - SOA get BOMWindow with packed BomLines

Creator
Creator

Thank you for your response.

I tried to apply this solution:

 

  CreateWindowsInfo2 BomWindows2 = new CreateWindowsInfo2();
                            {
                                BomWindows2.Item = item;
                                BomWindows2.ItemRev = (ItemRevision)itemRev;
                                BomWindows2.BomView = (PSBOMView)bomView;
                                BomWindows2.BomWinPropFlagMap.Add("is_packed_by_default", true);
                            };

                            CreateBOMWindowsResponse bomResp = smService.CreateBOMWindows2(new CreateWindowsInfo2[] { BomWindows2 });

                            bomWindow = bomResp.Output[0].BomWindow;
                            
                            dmService.GetProperties(new ModelObject[] { bomWindow }, new String[] { "is_packed_by_default" });                            
                            Console.WriteLine("BOMWindow is packed: " + bomWindow.Is_packed_by_default);

 

When I get the value of "is_packed_by_default" key I see nothing changes:

 

BOMWindow is packed: False

 So, the BOMLines are not packed.

Re: BOM - SOA get BOMWindow with packed BomLines

Creator
Creator

Thank you for your response.

 

How can I pass the rootBomLine in the call?

 

The expandBOMLines method is a recursive algorithm. In the first call push the first BOMLine:

 

CreateBOMWindowsResponse bomResp = smService.CreateBOMWindows2(new CreateWindowsInfo2[] { BomWindows2 });

                            bomWindow = bomResp.Output[0].BomWindow;
                            
                            dmService.GetProperties(new ModelObject[] { bomWindow }, new String[] { "is_packed_by_default" });                            
                            Console.WriteLine("BOMWindow is packed: " + bomWindow.Is_packed_by_default);

                            if (bomResp.Output.Length > 0)
                            {
                                BOMLine bomLine = bomResp.Output[0].BomLine;                                
                                expandBOMLines(bomLine);  //ROOT BOM LINE??
                            }

In the call I try to call PackOrUnpack function with the Child Lines as parameter:

 

        private void expandBOMLines(BOMLine bomLine) //PARENT LINE
        {
            ExpandPSOneLevelInfo  levelInfo = new ExpandPSOneLevelInfo();
            ExpandPSOneLevelPref levelPref = new ExpandPSOneLevelPref();
    
            levelInfo.ParentBomLines = new BOMLine[] { bomLine };
            levelInfo.ExcludeFilter = "None";
            levelPref.ExpItemRev = false;
            levelPref.Info = new RelationAndTypesFilter[0];

            stService.PackOrUnpack(levelInfo.ParentBomLines, 2);  //CHILD LINES??

            ExpandPSOneLevelResponse levelResp = smService.ExpandPSOneLevel(levelInfo, levelPref);

So, What I am doing wrong??

 

Thank you so much.

Regards.

Re: BOM - SOA get BOMWindow with packed BomLines

Solution Partner Legend Solution Partner Legend
Solution Partner Legend

I think root bomline is nothing but the parent bomline, which you are already passing correctly.

According to the 1st use case specified in doc (User calls the operation with some lines to pack them, the lines will be packed.), I think child lines have to be passed to PACK. So may be you need to call packOrUnpack after ExpandPSOneLevel ??

Also, have you checked what is the outout coming from stService.PackOrUnpack() ? your code does not seem to capture output from this function.
I hope it works with these hints.

Re: BOM - SOA get BOMWindow with packed BomLines

Creator
Creator

Ok, I modify my code, and I assing the PackOrUnpack() result to the ExpandPSOneLevelResponse levelResp  ServiceData property:

 

 

private void expandBOMLines(BOMLine bomLine)
{
ExpandPSOneLevelInfo levelInfo = new ExpandPSOneLevelInfo();
ExpandPSOneLevelPref levelPref = new ExpandPSOneLevelPref();

levelInfo.ParentBomLines = new BOMLine[] { bomLine };
levelInfo.ExcludeFilter = "None";
levelPref.ExpItemRev = false;
levelPref.Info = new RelationAndTypesFilter[0];

ExpandPSOneLevelResponse levelResp = smService.ExpandPSOneLevel(levelInfo, levelPref);

levelResp.ServiceData = stService.PackOrUnpack(levelInfo.ParentBomLines, 2);

I call the PackOrUnpack function after the ExpandPSOneLevel.

Is correct the argument levelInfo.ParentBomLines as BOMLine array in the PackOrUnpack call?