gpt4 book ai didi

c# - Solidworks C# API 创建线性阵列

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:21 25 4
gpt4 key购买 nike

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

我将 API C# 用于 Solidworks 以自动创建模型。

而且我不明白我需要如何编写才能在零件上创建线性模式

这是我的代码:

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
}

在最后一个案例(“第 3 部分”)中,我想创建线性模式

最佳答案

问题解决方案:

        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 - 这是一个间距

关于c# - Solidworks C# API 创建线性阵列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54731336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com