SolidWorks C#API创建线性图案

时间:2019-02-17 08:12:21

标签: c# api design-patterns linear solidworks

我在Solidworks中有一个装配模型。

我在Solidworks中使用API​​ C#自动创建模型。

而且我不明白在零件上创建线性图案时需要写些什么。

这是我的代码:

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
}

在最后一个案例(“ Part-3”)中,我想创建线性图案

请帮助谁。

2 个答案:

答案 0 :(得分:0)

我建议从API帮助中遵循以下示例:

Create Linear Pattern of Subassembly Example (C#)

答案 1 :(得分:0)

问题的解决方案:

        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);

代码需要在循环之前编写。

在功能FeatureLinearPattern2

3-这是数量

40/1000-这是间距