Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Export only selected part as STL 3

Status
Not open for further replies.

neshom

Mechanical
Feb 7, 2016
43
0
0
AU
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:

Code:
            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);
 
Replies continue below

Recommended for you

Well maybe you could open it for editing in place within the assembly. Either way you are first isolating the part within the SW environment, then exporting it. I'm not a SW certified pro like some of the other folks on here. Maybe there is a way to do what you want. Its never been a need for me.
 
This might be a solution.

Suppress parts you don't want to include in stl.
Save assembly as a part.
Open newly created part and save as an stl.

 
samuelm, there's no need to save as a part and then open it to save as STL. That would defeat the OP's desired effort anyway. You are on the right track, however. Suppress everything but the one part, then do a Save As STL, then unsuppress the parts to get back to the original state.

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
 
Question for the gurus: What about the SW "Isolate" command? Does it actually suppress all other parts? I use it a lot in complex assemblies to find smaller parts. Can he just Isolate the part in question and then do a Save As STL? Might be worth a try.
 
Thanks for all of the suggestions and comments.
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.
 
From what I see Updraft has the closest answer but it can be done with even less chance for confusion in the suppress/un-suppress operation.

You have your assembly open and decide you need an STL file for a particular component, correct?
[ol 1]
[li]Right click on the component you want to write the STL file for[/li]
[li]Select "Edit Part", FYI: If you are in shaded mode, everything but your selected component will become translucent[/li]
[li]Select "Save As..." (from the File dropdown menu), and select "Save as copy and continue", then select "STL (*.stl) as your "Save as type:" selection, give it a new name if you want and/or different directory and "Save"[/li]
[li]Close out off the "Edit Part" mode (icon in upper right corner, looks similar the edit part icon but with a return arrow below it) and you are back to square one with your assembly and its components all in there original state of display and an .stl file save out to whatever name & directory you gave it[/li]
[/ol]
 
djhurayt said:
Right click on the component you ...

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.
 
Status
Not open for further replies.
Back
Top