29 Replies Latest reply on May 19, 2014 7:57 AM by Nazar Chaykin

    2009 BOM API examples??

    Christina Seay
      Hey guys... We're finally getting upgraded to PDM 2009!! Yippee!!

      And I got the API help file and I'm going through it looking at all the neat new BOM commands... and there are NO examples at all in the help documentation!!!!

      Does anyone have any BOM API examples for PDM that they would be willing to share? I'll gladly post some of mine up here when I get some put together...
        • 2009 BOM API examples??
          I'm working on this too, but only found PDM 2009 BOM's API and no example. If anyone has examples please share!
          • 2009 BOM API examples??
            Attached is a simple solution I created. It should give you a basic understanding on how to read the BOMS. To be honest, this was my first attempt, and while it works, the code may need to be cleaned up a bit. I just whipped this up today to mess around with the BOM methods.

            Let me know if you have any questions.
            • 2009 BOM API examples??
              Christina Seay
              Thank-You soooooo much Lee for taking the time to do that!

              I can't open it though... I have Visual Studio 2005 and it says it was created with a newer version... any chance you could save it off where it's compatible with 2005?
              • 2009 BOM API examples??
                Christina Seay
                Very Very Nice interface!!! My IT department is in the process of upgrading our PDM system today, so I can't test it out right now... but I will as soon as they're done.

                THANK-YOU THANK-YOU Again!!!

                I've got several things I've got to do with BOM functions, so I'll make sure to post my code up here when I've got something that works.
                • 2009 BOM API examples??
                  Christina Seay
                  Ok.. they're finally done with our upgrade and I was testing out your program...

                  I created a custom BOM in the admin called AutoPlot and when I run the program it logs me into the vault just fine, but when I tried to retrieve the BOM it says "0 BOMs found."

                  Any idea what might be causing that?
                  • 2009 BOM API examples??
                    Christina Seay

                    Were you suggesting that because that's how Lee's program is set up, or is that the only way to use the BOM features is with a Named BOM?

                    I was really really hoping to be able to do it to where the users don't have to go through and save out the BOM first.

                    Thanks again for all your help Joy and Lee!!!!!
                    • 2009 BOM API examples??
                      The BOM interface is only for named BOMs. It's the only option; how would one manage a computed BOM?

                      [edit] Actually, there should be an AddBOM() method, but I don't see one. [/edit]
                      • 2009 BOM API examples??
                        Christina Seay
                        It seems like that since the information is there for computed BOM's that you'd be able to retrieve it... if you can't work with computed BOMs... what is this part in the API help file for:

                        This method returns an interface of a computed bill of materials.

                        If you have to save out a named BOM to be able to work with it via the API, that's really not much better than just saving out a CSV file and working with that, and it wouldn't have needed any extra API controlls to do it with.

                        Sorry... still an awesome program... and thank-you sooooo much for taking the time to make it... it's a really great example.. I'm just not sure how I'm going to do what I need to do if I can't work with computed BOMs... kind a bubble-burster... lol
                        • 2009 BOM API examples??
                          You're right and I missed that. Sorry. So you should be able to work with computed BOMs.

                          Try working with the example gy calling GetComputedBOM instead of GetDerivedBOMs. I'm not sure you'll be able to call Commit(), but it's worth a try. Like I said, that was my first attempt, so I don't have a lot of experience with these interfaces. At any rate, you're welcome.
                            • 2009 BOM API examples??
                              Christina Seay
                              I'll play around with it... I finally found the part in your code that had the GetDerivedBoms so I'll see what I can do with tweaking that bit. Am I the only one that has major issues converting this:


                              HRESULT GetComputedBOM( [in] VARIANT oBomLayoutNameOrID,
                              [in] long lVersionNo,
                              [in] BSTR bsConfiguration,
                              [in] long lEdmBomFlags,
                              [out,retval] IEdmBomView **ppoRetView );

                              Into usable code???? It's like a whole other language that I've missed the translation guide on... lol

                              I'll post what I get up on here if I can make it work.

                              And no worries... 2009 that has these interfaces just came out, the only ones with experience with it are the ones that made it.. lol.. and they obviously didn't feel like making examples, or they'd be in the API help file.

                              Now.... let's see if I can tweak it into submission.... he he he
                            • 2009 BOM API examples??
                              I'll see what I can do about tweaking my example to give you something to go by. Stand by.
                                • 2009 BOM API examples??
                                  Christina Seay
                                  You are AWESOME!!!! Thank-You Thank-You Thank-You!!!!!!!!!!

                                  I've been messing with it and I can't get it to stop erring out... but then again... I'm just starting to get the hang of VB.NET and this is written in C#... so that's making it a tad bit more confusing... lol...

                                  Look like I need to be adding a new coding language to my list of ones to learn... man... that list is getting longer and longer by the day...
                                • 2009 BOM API examples??
                                  You're welcome Christina. Hopefully others can benefit from the example.

                                  I prefer C# over VB.NET mainly because of the syntax. There aren't any real advantages of one language over the other IMO as it all targets the same framework in the end.
                                    • 2009 BOM API examples??
                                      Christina Seay
                                      The fact that this topic has already had 98 views means that there are probably more people other than me that have already benefited from it. It's good to have an actual working program to look at as a reference when you're learning to do something and even better when there are no examples at all in the help file.

                                      Thank-You for sharing your opinion of C# vs VB.NET as well... I'm coming from web programming, so application programming and it's structure is still very new to me. I was noticing that the syntax seemed a bit more simplified with your program vs. the VB.NET programs... but it looks like the project structure is the same.

                                      Thank-You again soooo much for your help!!
                                    • 2009 BOM API examples??
                                      Christina Seay
                                      I think that we can consider this question answered - Lee's program is a very good example of using the API to access the BOM's - both computed and named.
                                      • 2009 BOM API examples??
                                        Christina Seay
                                        Ok... of course I would have another question... lol...

                                        When I'm looking at the BOM in PDM, I have the option to see only the Top-Level items in the BOM... but I'm not seeing that option in the API help files anywhere.

                                        Is there a way to restrict to the BOM that you get through the API to only Top-Level just like what you see when you're in the vault?
                                        • 2009 BOM API examples??
                                          Christina Seay
                                          hmmmmm... would this have anything to do with whether or not something is a top-level item:

                                          This method returns the cell's tree level. (This is applicable for computed BOMs.)

                                          Geez.. you'd think if they couldn't include examples, they could at least give better descriptions of what it does... (sigh)
                                          • 2009 BOM API examples??
                                            The treeLevel will give you what you need. Level 1 is the root, level 2 is the first indent and so on...
                                            • 2009 BOM API examples??
                                              Christina Seay
                                              Thank-You for clearing that up for me Lee!!!!

                                              Has anyone seen anything that would tell you what the parent Assembly is... like if I have:

                                              Assembly 1
                                              -->Assembly 2
                                              ------>Part 1
                                              ------>Part 3
                                              -->Assembly 3
                                              ------>Part 4
                                              ------>Part 5

                                              and I want to know that the Parent Assembly of Part 5 is Assembly 3, the Parent Assembly of Assembly 3 is Assembly 1... etc etc.

                                                • 2009 BOM API examples??
                                                  When you loop through the rows, your assemblies and parts are returned in reverse order. So, your parent assembly will be the file you choose (obviously) and then the parts are returned followed by the sub-assemblies.

                                                  Given your example you would end up with the following;

                                                  Part 5 (2)
                                                  Part 4 (2)
                                                  Assembly 3 (1)
                                                  Part 3 (2)
                                                  Part 1 (2)
                                                  Assembly 2 (1)

                                                  Where (#) is the level.

                                                  If you were looking for a what assembly are part belongs to, you would loop through until you found the part, and then keep looping until you find the next assembly whose level is one less than the part.

                                                  For example, say I have the following structure [level in ()]:

                                                  Assembly 1 (0)
                                                  --> Assembly 2 (1)
                                                  ----> Part 1 (2)
                                                  ----> Part 2 (2)
                                                  ----> Assembly 3 (2)
                                                  --------> Part 3 (3)
                                                  --------> Part 4 (3)

                                                  If I wanted to find what assembly Part 2 is in, I would look for the next assembly after the part whose level is 1.

                                                  Make sense?
                                                    • 2009 BOM API examples??
                                                      Christina Seay
                                                      Oh my gosh... that makes perfect sense... !!! I didn't realize that it returned it in the reverse order.... that actually makes that a little simpler.

                                                      It would be nice if they would include a command to return the parent assembly.. but this looks like it would work!! I've been going crazy all morning trying to find a way to make that work knowing the levels.


                                                      You are my hero!!
                                                  • 2009 BOM API examples??
                                                    Jeff Sweeney
                                                    Way to go Lee! Thanks for taking the time on this one!

                                                    Christina, you are missing what would be nice...it would be nice if the API had an object written for us to do this! I say we storm the enhancement request castle's gates!
                                                    • 2009 BOM API examples??
                                                      Christina Seay
                                                      I know it... Lee has been just awesome with this question.. I'm sure that I'm not the only one benefiting from it either, it's had a lot of views.

                                                      Now if I can just get my little program to quit crashing PDM I'll be in business... lol... but at least it's coming along thanks to Lee's wonderful examples!!! I'll post it up here if/when I get it working so we've got another example.

                                                      And I totally agree... It would be very very nice if they an object written to do this... sometimes I wonder if the people that write any of these programs (PDM, SolidWorks, etc...) actually use them ever... lol