SolidWorks Addin Import STEP file to current document

242 Views Asked by At

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?

1

There are 1 best solutions below

0
On

Turns out the issue was with my path. Not sure why, but I cant load the file at the current location. If i copied the file to C:\ then there was no issue.