首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Solidworks C# API创建线性模式

Solidworks C# API创建线性模式
EN

Stack Overflow用户
提问于 2019-02-17 08:12:21
回答 1查看 492关注 0票数 2

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

我使用API C#进行Solidworks自动创建模型。

我不明白我要写什么才能在一个部件上创建线性模式

这是我的密码:

代码语言:javascript
复制
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”)中,我想创建线性模式

EN

回答 1

Stack Overflow用户

发布于 2019-02-27 06:12:51

解决问题的办法:

代码语言:javascript
复制
        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-这是quantity

40 / 1000 -这是一个间距

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54731336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档