UG NX二次开发(C#)-装配-替换组件

Posted GimiGimmy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UG NX二次开发(C#)-装配-替换组件相关的知识,希望对你有一定的参考价值。

UG NX装配中的替换组件的代码如下:

 public static void Replace(Component olderComponent, string newer)
    
        string name = newer.Split('.')[0].Split('\\\\')[newer.Split('.')[0].Split('\\\\').Length - 1].ToUpper();

        NXOpen.Assemblies.ReplaceComponentBuilder replaceComponentBuilder1;
        replaceComponentBuilder1 = workPart.AssemblyManager.CreateReplaceComponentBuilder();
        replaceComponentBuilder1.MaintainRelationships = false;
        replaceComponentBuilder1.ComponentNameType = NXOpen.Assemblies.ReplaceComponentBuilder.ComponentNameOption.AsSpecified;
        replaceComponentBuilder1.ComponentName = name;

        NXOpen.Assemblies.Component component1 = olderComponent;
        bool added1;
        added1 = replaceComponentBuilder1.ComponentsToReplace.Add(component1);

        replaceComponentBuilder1.ReplacementPart = newer;

        replaceComponentBuilder1.SetComponentReferenceSetType(NXOpen.Assemblies.ReplaceComponentBuilder.ComponentReferenceSet.Maintain, null);

        NXOpen.PartLoadStatus partLoadStatus1;
        partLoadStatus1 = replaceComponentBuilder1.RegisterReplacePartLoadStatus();

        NXOpen.NXObject nXObject1;
        nXObject1 = replaceComponentBuilder1.Commit();

        partLoadStatus1.Dispose();
        replaceComponentBuilder1.Destroy();
    

其中,第一个参数是装配体中已有的组件,第二个参数是替换的组件完整路径。

以上是关于UG NX二次开发(C#)-装配-替换组件的主要内容,如果未能解决你的问题,请参考以下文章

UG NX二次开发(C#)-装配-替换组件

UG NX二次开发(C#)-装配-删除阵列矩阵

UG NX二次开发(C#)-装配-删除阵列矩阵

UG NX二次开发(C#)-装配-添加组件

UG NX二次开发(C#)-模型处理功能

UG NX二次开发(C#)-模型处理功能