예제 #1
0
        /// <summary>
        /// 把body导出为文件流
        /// </summary>
        /// <param name="body"></param>
        /// <param name="filePath"></param>
        public static void SaveBodyToFile(IBody2 body, string filePath)
        {
            IStream stream = null;

            CreateStreamOnHGlobal(IntPtr.Zero, true, ref stream);
            body.Save(stream);

            var comStream = new ComStreamBody(ref stream, false, false);

            using (var fileStream = File.Create(filePath))
            {
                comStream.Seek(0, SeekOrigin.Begin);
                comStream.CopyTo(fileStream);
            }
        }
예제 #2
0
        /// <summary>
        /// 从文件加载实体
        /// </summary>
        /// <param name="app"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static IBody2 LoadBodyFromFile(ISldWorks app, string filePath)
        {
            IStream stream = null;

            CreateStreamOnHGlobal(IntPtr.Zero, true, ref stream);

            var comStream = new ComStreamBody(ref stream, true, true);

            using (var fileStream = File.OpenRead(filePath))
            {
                fileStream.CopyTo(comStream);
                comStream.Seek(0, SeekOrigin.Begin);
            }

            IModeler modeler = app.IGetModeler();

            return((IBody2)modeler.Restore(stream));
        }