Export only selected part as STL
Export only selected part as STL
(OP)
I'd like to export only the selected part (in an assembly) as STL, but my code exports all of the parts as stl. Do you know how I can achieve this?
My code:
My code:
CODE --> C#
ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;
SelectionMgr swSelectionMgr = (SelectionMgr)swModel.SelectionManager;
int intSelectedObjectCount = swSelectionMgr.GetSelectedObjectCount2(-1);
Component2 swComponent = (Component2)swSelectionMgr.GetSelectedObjectsComponent4(1, -1);
swModel = (ModelDoc2)swComponent.GetModelDoc();
int intError = 0;
int intWarning = 0;
swApp.SetUserPreferenceDoubleValue((int)swUserPreferenceDoubleValue_e.swSTLAngleTolerance, 2.0);
swModel.Extension.SetUserPreferenceString((int)swUserPreferenceStringValue_e.swFileSaveAsCoordinateSystem, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, null);
bool boolstatus = swModel.Extension.SaveAs(swModel.GetPathName()+".stl", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref intError, ref intWarning); 





RE: Export only selected part as STL
RE: Export only selected part as STL
RE: Export only selected part as STL
RE: Export only selected part as STL
Suppress parts you don't want to include in stl.
Save assembly as a part.
Open newly created part and save as an stl.
RE: Export only selected part as STL
neshom, if all the parts in your assembly are unsuppressed then for a person skilled in macros/api programming perhaps it would be easy to a) select a part, b) suppress all others (OR suppress all and unsuppress the desired part, but you would have to know what that part is by name since you'd not be able to select it graphically), c) Save As STL, d) unsuppress all.
Hope this helps.
- - -Updraft
RE: Export only selected part as STL
RE: Export only selected part as STL
The problem with suppress/unsuppress is that there maybe several parts in the main or sub assemblies that are already supprssed. Either I must record their name (which doesn't sound easy for me) to avoid unsuppressing them or I need to suppress them back manually. Plrase correct me if I am wrong.
So, I now beleive that the simplest way would be to open the selected part and then save it as STL.
Thanks again.
RE: Export only selected part as STL
You have your assembly open and decide you need an STL file for a particular component, correct?
RE: Export only selected part as STL
Thanks for your response. This sounds to be the right solution. Do you know how I can put a part in an assembly in Edit mode using API functions and also return it to the initial state (not Edit mode)?
Thanks in advance.
RE: Export only selected part as STL