コード例 #1
0
        /// <summary>
        /// 编辑零部件,自动区分装配体还是零件
        /// </summary>
        /// <param name="comp">组件</param>
        /// <param name="doc">顶级文档</param>
        /// <param name="silent">静默编辑--提高速度</param>
        /// <param name="readOnly">只读</param>
        /// <returns></returns>
        public static swEditPartCommandStatus_e Edit(this Component2 comp, AssemblyDoc doc, bool silent = true, bool readOnly = false)
        {
            var type = comp.GetCompType();
            int info = -1;

            switch (type)
            {
            case swDocTemplateTypes_e.swDocTemplateTypePART:
                if (comp.Select2(false, -1))
                {
                    doc.EditPart2(silent, readOnly, ref info);
                }
                break;

            case swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY:
                if (comp.Select2(false, -1))
                {
                    doc.EditAssembly();
                }
                info = 0;
                break;

            default:
                throw new FileFormatException(string.Format("不能编辑此类型的组件:{0} 的类型", type.ToString()));
            }
            swEditPartCommandStatus_e state = (swEditPartCommandStatus_e)info;

            return(state);
        }