UG二次开发 实体转装配零件并将实体属性填写到装配零件中(C#)

2021/11/29 14:07:24

本文主要是介绍UG二次开发 实体转装配零件并将实体属性填写到装配零件中(C#),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 1      /// <summary> 
 2         /// 实体转化为装配
 3         /// </summary>
 4         /// <param name="prtfull">全路径</param>
 5         /// <param name="bodys">实体</param>
 6         /// <param name="SaveBool">是否保存零件</param>
 7         /// <returns>返回prtTag </returns>
 8         public void CreatObjPartToAssembly(string prtfull, Body bodys, bool SaveBool, ref Tag prtTag)
 9         {
10             NXOpen.FileNew fileNew1;
11             fileNew1 = base.theSession.Parts.FileNew();
12             fileNew1.TemplateFileName = "model-plain-1-mm-template.prt";
13             fileNew1.UseBlankTemplate = false;
14             fileNew1.ApplicationName = "ModelTemplate";
15             fileNew1.Units = NXOpen.Part.Units.Millimeters;
16             fileNew1.RelationType = "";
17             fileNew1.UsesMasterModel = "No";
18             fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item;
19             fileNew1.ItemType = "";
20             fileNew1.Specialization = "";
21             fileNew1.SetCanCreateAltrep(false);
22             fileNew1.NewFileName = prtfull;
23             fileNew1.MasterFileName = "";
24             fileNew1.MakeDisplayedPart = false;
25             NXOpen.Assemblies.CreateNewComponentBuilder createNewComponentBuilder1;
26             createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder();
27             createNewComponentBuilder1.ReferenceSet = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.Other;
28             createNewComponentBuilder1.ReferenceSetName = "PART";
29             createNewComponentBuilder1.OriginalObjectsDeleted = false;
30             string name = Path.GetFileNameWithoutExtension(prtfull);
31             createNewComponentBuilder1.NewComponentName = name.ToUpper();
32             bool added1;
33             added1 = createNewComponentBuilder1.ObjectForNewComponent.Add(bodys);
34             createNewComponentBuilder1.NewFile = fileNew1;
35             NXOpen.NXObject nXObject1;
36             nXObject1 = createNewComponentBuilder1.Commit();
37             Tag occTag = nXObject1.Tag;
38             Tag InstanceTag = theUfSession.Assem.AskInstOfPartOcc(occTag);
39             prtTag = theUfSession.Assem.AskChildOfInstance(InstanceTag);
40             NXOpen.BasePart bpart = (NXOpen.BasePart)NXObjectManager.Get(prtTag);
41             if (SaveBool)
42             {
43                 bpart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False);
44             }
45             NXObject.AttributeInformation[] allAttrs = bodys.GetUserAttributes();
46             foreach (NXObject.AttributeInformation attrinfo in allAttrs)
47             {
48                 bpart.SetUserAttribute(attrinfo, Update.Option.Now);
49             }
50             createNewComponentBuilder1.Destroy();
51         }

 



这篇关于UG二次开发 实体转装配零件并将实体属性填写到装配零件中(C#)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程