编程语言
首页 > 编程语言> > UG二次开发 实体转装配零件并将实体属性填写到装配零件中(C#)

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         }

 

标签:装配,BasePart,fileNew1,实体,createNewComponentBuilder1,Tag,NXOpen,零件,prtTag
来源: https://www.cnblogs.com/lpserver1102/p/15619096.html