Esempio n. 1
0
        /// <summary>
        /// 新建部件
        /// </summary>
        /// <param name="partName">部件全路径名</param>
        /// <returns>NXObject</returns>
        public static NXObject NewFile(string partName)
        {
            FileNew fileNew1 = theSession.Parts.FileNew();

            fileNew1.TemplateFileName         = "molex-plain-1-mm-template.prt";
            fileNew1.UseBlankTemplate         = false;
            fileNew1.ApplicationName          = "ModelTemplate";
            fileNew1.Units                    = Part.Units.Millimeters;
            fileNew1.RelationType             = "";
            fileNew1.UsesMasterModel          = "No";
            fileNew1.TemplateType             = FileNewTemplateType.Item;
            fileNew1.TemplatePresentationName = "Molex";
            fileNew1.ItemType                 = "";
            fileNew1.Specialization           = "";
            fileNew1.SetCanCreateAltrep(false);
            fileNew1.NewFileName       = partName;
            fileNew1.MasterFileName    = "";
            fileNew1.MakeDisplayedPart = true;
            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = fileNew1.Commit();
                return(nXObject1);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("PartUtils.NewFile:" + ex.Message);
                return(null);
            }
            finally
            {
                fileNew1.Destroy();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 新建装配档文件
        /// </summary>
        /// <param name="partName">装配Part名字</param>
        /// <param name="partPath">Part档地址</param>
        /// <returns></returns>
        public static NXObject CreateNew(string partName, string partPath)
        {
            Part    workPart = theSession.Parts.Work;
            FileNew fileNew1 = theSession.Parts.FileNew();

            fileNew1.TemplateFileName         = "molex-plain-1-mm-template.prt";
            fileNew1.UseBlankTemplate         = false;
            fileNew1.ApplicationName          = "ModelTemplate";
            fileNew1.Units                    = NXOpen.Part.Units.Millimeters;
            fileNew1.RelationType             = "";
            fileNew1.UsesMasterModel          = "No";
            fileNew1.TemplateType             = NXOpen.FileNewTemplateType.Item;
            fileNew1.TemplatePresentationName = "Molex";
            fileNew1.ItemType                 = "";
            fileNew1.Specialization           = "";
            fileNew1.SetCanCreateAltrep(false);
            fileNew1.NewFileName       = string.Concat(partPath);
            fileNew1.MasterFileName    = "";
            fileNew1.MakeDisplayedPart = false;
            NXOpen.Assemblies.CreateNewComponentBuilder createNewComponentBuilder1;
            createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder();
            createNewComponentBuilder1.ReferenceSet     = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.EntirePartOnly;
            createNewComponentBuilder1.NewComponentName = partName;
            createNewComponentBuilder1.ComponentOrigin  = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentOriginType.Wcs;
            createNewComponentBuilder1.NewFile          = fileNew1;
            bool validate = createNewComponentBuilder1.Validate();

            try
            {
                NXObject nXObject1 = createNewComponentBuilder1.Commit();
                return(nXObject1);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("AssmbliesUtils:CreateNew:" + ex.Message);
                return(null);
            }
            finally
            {
                createNewComponentBuilder1.Destroy();
                Session.UndoMarkId markId = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible);
                theSession.DeleteUndoMark(markId, "");
            }
        }