Run code on every part in assembly

You need to be logged in to view this content. Please login or become a member.

 Richard Sherman Womens Jersey

13 Comments

  1. jwinborn

    Kevin,

    Is it possible to export flat patterns for an entire assembly?

    Regards
    Jay Winborn

    • Jay,

      The only API call I know of that lets you export flat patterns is for parts only, because it is a member of the IPartDoc interface. I don’t know if this would help, but you could try saving the assembly as a part and then exporting the flat pattern using IPartDoc::ExportFlatPatternView.

      By the way, don’t forget that we have a free macro example called “Export sheet metal flat pattern to specified location” in our Macro Library.

      Keith

  2. fafin

    Hi,

    this macro is doing perfectly in basic assembly that I’ve created just for testing purposes. Unfortunately in actual assy that i need to modify it keep telling me:
    “Object variable or With block variable not set” (in line 27).
    This look like basic mistake that Keith has covered in one of his videos. I haven’t change a single character in this code. Any idea why it throwing error?

    • Hi fafin,

      The error is occurring because you have lightweight or suppressed components in your assembly. You can test if a component is lightweight or suppressed using IComponent2::GetSupression.

  3. jeff2xmen

    Hi Keith,

    why this macro doesn’t work on mine.I am using SW2013.

    • Based on the error messages you sent me, it appears that your assembly has lightweight or suppressed components. You will need to test for these states using IComponent2::GetSuppression2.

  4. chrisc

    Hi Keith,
    Just download and run
    Thank you for sharing this macro. Info of associated parts from an assembly can be extracted from this macro. This is very nice
    Thanks again, Chris

  5. Shak

    Hi Keith,

    How would I use the code IComponent::GetSuppression2

    or remove the conditional that tests if its a part?

    I have a few suppressed parts in my assembly and the Macro keeps failing cause of them.

    Thanks,
    Shak

    • Hi Shak, I have another macro here that shows how to use IComponent2::GetSuppression, but it requires the Power User membership. You can also see several examples in the SolidWorks API Help involving this API call. As for your second question — you simply remove the lines that create the conditional block:

      If swCompModel.GetType = swDocPART Then
      End If

  6. nnamenroh_dnreb

    Hi Keith,
    does Solidworks.Component2 give access to dimensions of a sketch?

    • No, you would need to get the pointer to the sketch feature (IFeature) and use traverse the dimensions using IFeature::GetFirstDisplayDimension and IFeature::GetNextDisplayDimension. There is an API Help example called “Traverse Annotations Example (VBA)” that shows you how to do this.

  7. Yonas89

    I am wondering how it should look if I need to get components only from specific folder in assembly design tree?

    • Don’t use this macro. Use this one. When you hit a feature folder, use IFeatureFolder.GetFeatures to get the array of features and then IFeature.GetSpecificFeature2 for each feature in that array to get the IComponent2 pointer.

Questions and Comments

You must be logged in to post a comment.