×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Export only selected part as STL
3

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:

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

Open the part separately first.

RE: Export only selected part as STL

(OP)
Thanks for your solution, but Is there anyway to avoid openning the part?

RE: Export only selected part as STL

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.

RE: Export only selected part as STL

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.

RE: Export only selected part as 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

RE: Export only selected part as STL

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.

RE: Export only selected part as STL

(OP)
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.

RE: Export only selected part as STL

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?
  1. Right click on the component you want to write the STL file for
  2. Select "Edit Part", FYI: If you are in shaded mode, everything but your selected component will become translucent
  3. 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"
  4. 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

RE: Export only selected part as STL

(OP)

Quote (djhurayt)

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.

RE: Export only selected part as STL

no, sorry, not that advanced

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources