ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
AAAlex Alex18/02/2019

I have an assembly model in Solidworks.

I use API C# to Solidworks for automatic create a model.

And I don't understand how what I need to write for creating the Linear Pattern on a part.

This is my code:

public SldWorks swApp;
public AssemblyDoc assemblyDoc;
public ModelDoc2 assemblyModel;
public EquationMgr assemblyMgr;
public IDimension partDimension;
public Feature swFeature;
public IModelDoc2 partModel;

public void createModel()
{
Console.WriteLine("createModel");

Process[] processes = Process.GetProcessesByName("SLDWORKS");
foreach (Process process in processes)
{
Console.WriteLine("kill process ");
process
.CloseMainWindow();
process
.Kill();
}

object processSW = System.Activator.CreateInstance(System.Type.GetTypeFromProgID("SldWorks.Application"));
swApp
= (SldWorks)processSW;
swApp
.Visible = true;
//open file
int fileError = 0, fileWarning = 0;
string pathToFileAssembly = "C:\\Users\\administrator\\Desktop\\SW\\AssemBelt.SLDASM";
assemblyModel
= swApp.OpenDoc6(pathToFileAssembly, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "1", ref fileError, ref fileWarning);

assemblyDoc
= (AssemblyDoc)assemblyModel;
assemblyMgr
= assemblyModel.GetEquationMgr();

object[] comps = assemblyDoc.GetComponents(true);
Console.WriteLine("Solidworks comps size = " + comps.Length);
foreach (Component2 icomp in comps)
{
partModel
= swApp.OpenDoc6(icomp.GetPathName(), (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "1", ref fileError, ref fileWarning);

switch (icomp.Name)
{
case "Part-1": //Part1
Console.WriteLine("--------------------Part-1--------------------");
break;

case "Part-2": //Part2
Console.WriteLine("--------------------Part-2--------------------");
break;

case "Part-3": //Part3
Console.WriteLine("--------------------Part-3--------------------");
if (cleatModel.getCleatVisible())
{
icomp
.SetSuppression(1);
icomp
.ReferencedConfiguration = "type-C";

// swFeature = partModel.FeatureManager.FeatureLinearPattern4(3, 0.0029375, 4, 0.02, true, true, "", "", false, false, true, false, true, false, false, true, false, false, 0.19, 0.01);

//FOR PART-3 I NEED A LINEAR PATTERN

}
else icomp.SetSuppression(0);

break;
}

Console.WriteLine(icomp.Name + " => " + icomp.GetPathName() + " => " + partModel);
}//for end
}

In the last case ("Part-3") I want to create the Linear Pattern.

Help who than can, please.