简体   繁体   中英

Solidworks C# API create a Linear Pattern

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 last case ("Part-3") I want to create the Linear Pattern .

Solution to the problem:

        swModelDocExt.SelectByID2("", "EDGE", -0.439825991092107, 7.07350481263802E-02, 0.40982045578545, true, 2, null, 0);
        swModelDocExt.SelectByID2("", "EDGE", -0.219003008311574, 0.073085842475507, 0.549481823985616, true, 4, null, 0);
        swModelDocExt.SelectByID2("Part-3@AssemModel", "COMPONENT", 0, 0, 0, true, 1, null, 0);
        swFeature = (Feature)swFeatureManager.FeatureLinearPattern2(3, 40 / 1000, 0, 0, false, true, "NULL", "NULL", false);
        assemblyModel.ClearSelection2(true);

The code needs to write before a loop.

In function FeatureLinearPattern2

3 - this is a quantity

40 / 1000 - this is a spacing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM