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.
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?
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.
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.
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
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:
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.
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.
You could combine this macro with this macro. For each iteration, you would run the code that gets the bounding box using IBody2.GetBodyBox on each part.
Is there any way by which I could fetch all the custom properties from a part/ assembly file without actually opening the file in SolidWorks and have them exported in a .csv or excel file?
Yes, but you would need to use the Document Manager API to obtain the custom properties. You can use a StreamWriter easily enough to create a CSV. I would highly recommend using a CSV instead of Excel so that you don’t need to involve the Excel API.
Ready to start learning the SolidWorks API? Sign up for FREE membership here.Keep up with new videos, macros, and training events by joining our mailing list:
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
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.
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.
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
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
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.
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.
Hi,
How should I modify this macro to create a bounding box (Reference Geometry toolbar) in each part of the assembly?
thanks
Rafa
You could combine this macro with this macro. For each iteration, you would run the code that gets the bounding box using IBody2.GetBodyBox on each part.
Hi Keith,
Is there any way by which I could fetch all the custom properties from a part/ assembly file without actually opening the file in SolidWorks and have them exported in a .csv or excel file?
Yes, but you would need to use the Document Manager API to obtain the custom properties. You can use a StreamWriter easily enough to create a CSV. I would highly recommend using a CSV instead of Excel so that you don’t need to involve the Excel API.