API: InsertBOMTable2 with top level only

Discussion in 'SolidWorks' started by Jonathan Anderson, Mar 3, 2005.

  1. I'm trying to insert a bill of materials with View::InertBOMTable2, and
    it works when I use the parts only or indented style, but when I use
    the top level only style, SolidWorks crashes (from an addin - if I do
    it in a macro, SW doesn't crash but I get a nice error "The object
    invoked has disconnected from its clients" on that statement). I'm not
    specifying a configuration (as documented in the API docs), and even
    when I do it doesn't work. Here's what my call looks like:

    (macro)
    Set MyBOM = MyView.InsertBomTable2(False, 0, 0, 1, 2, "", _
    "C:\Program Files\SolidWorks\lang\english\bom-standard.sldbomtbt")

    (C++)
    pView->InsertBomTable2(VARIANT_FALSE, 0, 0,
    swBOMConfigurationAnchor_BottomRight,
    swBomType_TopLevelOnly, CComBSTR(L""),
    CComBSTR(L"C:\\Program
    Files\\SolidWorks\\lang\\english\\bom-standard.sldbomtbt"), &pBomTA);


    Anyone know what's up or how to work around it?

    Thanks in advance,
    Jonathan Anderson
     
    Jonathan Anderson, Mar 3, 2005
    #1
  2. Jonathan Anderson

    CS Guest

    Sounds like your view object changed somehow and the reference to it was no
    longer valid. Look up persistent references, this may help solve the
    problem.

    Corey
     
    CS, Mar 4, 2005
    #2
  3. Actually, nothing is wrong with the view object, because it works fine
    with the other BOM types. I also sent a message to api support, and I
    received this reply:

    ---------
    This is a known issue scheduled to be fixed in 2005 SP02.

    256221 "View::InsertBOMTable2 does not insert a table and crashes."

    I apologize for the inconvenience.
    ---------

    So at least they're planning on fixing it. For now, I'm working around
    the problem by inserting the BOM with a different type and then
    changing the type to top level only. This is a little bit of a hassle
    because doing it this way I also have to set the proper configuration
    for the BOM rather than letting SW do it automatically.

    Now if I could figure out how to get the BOM table from the view, I'd
    be in business. Unfortunatly, since SW creates the feature for the BOM
    at the top level instead of under a view, using
    View::GetFirstTableAnnotation followed by View::GetNext doesn't find
    the BOM table.

    Jonathan Anderson
     
    Jonathan Anderson, Mar 4, 2005
    #3
  4. Jonathan Anderson

    CS Guest

    So they lost the reference to an object. That'll make a guy feel better.



    I wanted to do the same thing. You can do this with the old Excel Based
    BOM, but as you stated you cannot reference the view that it was created
    from. This really sucks because I hate assuming that the view used to
    create the bom is the view specified in the Sheet Properties this could
    cause problems if you start using views of more than one model on a single
    drawing or if there are multiple configurations shown on a single sheet. If
    you figure anything out that I may have missed please let me know.
     
    CS, Mar 4, 2005
    #4
  5. I've been pondering this and here's a couple of things I came up with:

    You can't get the attached BOM object from the View, but maybe you
    could match it with a good probability.

    The BomTableAnnotation object doesn't really provide any useful
    information, but the BomFeature object does allow you to get the
    configuration shown as well as the configurations available for a BOM
    (BomFeature::GetConfigurations). You can also get the referenced
    configuration from the View object (View.ReferencedConfiguration), so
    in theory you could look for a BomFeature and View object that
    referenced the same configuration. However, if they reference
    different models that have the same configuration name, you would be in
    trouble. There isn't any easy way that I can think of to get the
    referenced model from the BOM. You could theoretically match the
    configurations like I described, and then you could iterate through the
    BOM table as well as the feature tree of the model referenced in the
    view, and if the same parts are in the BOM and the feature tree then
    you would have a match. That's a lot of work to do something simple,
    but in theory it would work. And hey, you only have to write it once
    ;) I'm running SW 2004, so they may have some way in 2005 to get the
    referenced model from the BOM, which would make things easier.

    That's the only way I can think of if you don't know anything else
    beforehand. For my purposes, my program is going to be creating the
    BOM on a certain drawing view, and then needs to get the correct view
    and BOM later (after a save and quit). So I'm going to get the
    persistent reference ID of the view and the BOM when I create the BOM
    and save those (ModelDocExtension::GetPersistReference). Then I can
    come back later and pick the appropriate BOM and view. I'm actually
    creating a macro feature that will drive the BOM order from a back end
    database that we use with product structures, so it's easy for me to
    save those in my macro feature data properties. You could possible
    save something like that in a custom property. Or for that matter, you
    could just assign a unique custom property to the BOM and the view that
    would later allow your program to make the connection.

    Wow, that's a lot just to associate a BOM and view. Hope that helps,
    Jonathan Anderson
     
    Jonathan Anderson, Mar 4, 2005
    #5
  6. Jonathan Anderson

    CS Guest

    Nice.. I was thinking along the same lines and decided it was too much work
    for something that wouldn't feel exact. So I just went on the assumption
    that it was going to be the same as the Custom Properties View. It is alot
    less work and will be accurate at least 98% of the time the way we do things
    here. I too am working with 2004. Let me know how it works out with the
    BOM from MRP system that might be a nice project for later. The only
    things I am worried about is the baloons, will they stay linked to the
    numbering system. We leave most fasteners, fluids and other BULK items off
    of the models for feasability but it might be beneficial to have them show
    up on the Drawing when updated with the MRP system.

    Corey
     
    CS, Mar 7, 2005
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.