Do two things:
1. Save a STL file manually and check if that is working OK.
2. Uncheck the SOLIDWORKS utilities library from your macro references.
1. Saving the STL file manually works like it should. When you have a solid body selected it brings up a screen to ask you what part(s) to save: the selected body or the entire part.
Is there any way I can specify "export selected bodies" within my macro? Using the macro this questions does NOT pop up.
2. Unchecking the Solidworks utility library does not seem to have any effect on the outcome of this macro.
It works for whole part but not with a body selected.
Did you ever find the solution. I am running into this issue as well. 2018, clean install as well. I am only saving .stl's of 1 kb file size.
Unfortunately not.. I had to switch back to manual export.
So here are few workarounds:
1. Delete the other bodies and then export the remaining body as STL and then delete the delete body feature.
2. Insert the selected body into a new part and export that part as STL. Do not save the new file and delete save bodies feature if needed.
3. Export selected body as STEP/Parasolid, open that file and export that as STL.
Hey thanks for the Ideas! I am dusting off my university programming skills and my head hurts looking at VB script
I just finished making a kulge along lines if (1). Rather, I Hide all the bodies. Then I cycle and turn only one on, then show it, then save it then hide it. Then show all at the end.
In this way, the SaveAs3 function works. The limitation seems to be with SW STL SaveAs3. When the body is selected, the user is forced via the manual method to answer a dialog box. However, the API method fails at this point and gives you the 1 kb file.
Key commands (took 4 hours of searching to figure out lol)
Dim swModel As SldWorks.ModelDoc2
Dim vBody As Variant
Dim swModExt As SldWorks.ModelDocExtension
Dim swBody As SldWorks.Body2
vBody = swPart.GetBodies2(swSolidBody, True)
sBodySelStr = swBody.GetSelectionId
sBodyTypeSelStr is "SOLIDBODY" or "SURFACEBODY "
bRet = swModExt.SelectByID2(sBodySelStr, sBodyTypeSelStr, 0#, 0#, 0#, True, 0, Nothing, swSelectOptionDefault): Debug.Assert bRet
swModel.FeatureManager.HideBodies 'This is also key
swModel.FeatureManager.ShowBodies 'This is also key
swModel.ClearSelection2 True ' THIS IS KEY, use this before saving. Otherwise, if a body is selected, you may get the 1kb file size
Here is my messy code... includes a nice reference of a SW Help file for selecting a solid body.
Attached the code directly because someone pointed out the advanced editor lets you do this!! Woot woot!
Adding this to my tool bar saves me like 5 to 10 min a day and so much less stress... thank you forums!
VBA Question. Does anyone know why I cannot pass an 'i' from a for loop to a function within the same loop? I would get an error with the following code...
For i = 1 to 5
subABC (i, "")
sub subABC ( i as integer, sText as String)
SaveBodiesSTL_0.swp.zip 14.5 KB
Another option in addition to Deepak's suggestion is to reimplement STL output by getting the tessellation data. Here is an example which exports component to STL from assembly (which is not supported in SOLIDWORKS): Export Component To STL
This can be modified to export body/bodies or even faces, etc.