Mads Hilligsoe

Insert .step into current assembly document

Discussion created by Mads Hilligsoe on Feb 9, 2021
Latest reply on Feb 19, 2021 by Mads Hilligsoe

I'm trying to import a .step file into my current assembly document using a custom C# addin.

I can successfully open a .step file as a new document using the LoadFile4 method (http://help.solidworks.com/2020/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.isldworks~loadfile4.html), but when using the InsertImportedComponent method (http://help.solidworks.com/2020/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IPartDoc~InsertImportedFeature.html) i get an error code 2:
sw3DInterconnectImportErrors_IncompatibleType 2 = Specified file type is not correct.

This is my code so far:

IModelDoc2 modDoc = iSwApp.ActiveDoc;
IAssemblyDoc assemblyDoc = (IAssemblyDoc)modDoc;
string stepFileName = "C:\\Users\\mlhil\\MH Tech ApS\\MH Tech - Vaerks\\Udvikling\\CAM\\FeatureCAM Vises\\Vice.step";
object CompObj;
int error = assemblyDoc.InsertImportedComponent(stepFileName, 0, 0, 0, out CompObj);
Debug.Print($"{error}");

How do I insert a .step file into my currently active assembly document?

Outcomes