VS环境下 C++版本:

 1 int GetPreviewImage(const TCHAR* prtFile, const TCHAR* imageFile)
2 {
3 IStorage* pStorage = NULL;
4 HRESULT hResult = StgOpenStorage(prtFile, NULL, STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &pStorage);
5 if (hResult != S_OK)
6 {
7 return -1;
8 }
9
10 IStorage* pSubStorage = NULL;
11 hResult = pStorage->OpenStorage(_T("images"), NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &pSubStorage);
12 if (hResult != S_OK)
13 {
14 return -1;
15 }
16
17 IStream *pStream = NULL;
18 hResult = pSubStorage->OpenStream( L"preview", NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream );
19 if (hResult != S_OK)
20 {
21 return -1;
22 }
23
24 const int nLen = 10*1024*1024;// 准备读入的长度
25 byte* image = new byte[nLen];
26 if (NULL == image)
27 {
28 return -1;
29 }
30
31 ULONG actRead;
32 pStream->Read(
33 image, // 存放放入的数据的缓冲区
34 nLen, // 要读入数据的长度,如不清楚可以设为较大的数
35 &actRead // 实际读入的长度
36 );
37
38 pStream->Release();
39 pStorage->Release();
40 pSubStorage->Release();
41
42 ofstream outfile(imageFile, ios::binary);
43 outfile.write((char*)image, actRead);
44 outfile.close();
45 delete image;
46 return 0;
47 }

业内还盛传一个C#版本,封装好了一个叫“ThumbnailCreator”的类,用法如下:

 1         static void GetPartBmp(string sFileName)
2 {
3 string sOutputFileName = "";
4 if (!File.Exists(sFileName))
5 {
6 return;
7 }
8 sOutputFileName = sFileName.Substring(0, sFileName.LastIndexOf(".")) + ".bmp";
9 ThumbnailCreator thumbnail = new ThumbnailCreator();
10 Image img = thumbnail.GetThumbnail(sFileName);
11 if (img != null)
12 {
13 if (!File.Exists(sOutputFileName))
14 {
15 File.Delete(sOutputFileName);
16 }
17 img.Save(sOutputFileName, ImageFormat.Bmp);
18 }
19 }

ThumbnailCreator类实现:

  1 using System;
2 using System.IO;
3 using System.Runtime.InteropServices;
4 using System.Text;
5
6 namespace SharedClasses
7 {
8
9 #region ThumbnailCreator
10
11 /// Summary description for ThumbnailCreator.
12
13 public class ThumbnailCreator : IDisposable
14 {
15 #region ShellFolder Enumerations
16 [Flags]
17 private enum ESTRRET : int
18 {
19 STRRET_WSTR = 0x0000, // Use STRRET.pOleStr
20 STRRET_OFFSET = 0x0001, // Use STRRET.uOffset to Ansi
21 STRRET_CSTR = 0x0002 // Use STRRET.cStr
22 }
23 [Flags]
24 private enum ESHCONTF : int
25 {
26 SHCONTF_FOLDERS = 32,
27 SHCONTF_NONFOLDERS = 64,
28 SHCONTF_INCLUDEHIDDEN = 128
29 }
30
31 [Flags]
32 private enum ESHGDN : int
33 {
34 SHGDN_NORMAL = 0,
35 SHGDN_INFOLDER = 1,
36 SHGDN_FORADDRESSBAR = 16384,
37 SHGDN_FORPARSING = 32768
38 }
39 [Flags]
40 private enum ESFGAO : int
41 {
42 SFGAO_CANCOPY = 1,
43 SFGAO_CANMOVE = 2,
44 SFGAO_CANLINK = 4,
45 SFGAO_CANRENAME = 16,
46 SFGAO_CANDELETE = 32,
47 SFGAO_HASPROPSHEET = 64,
48 SFGAO_DROPTARGET = 256,
49 SFGAO_CAPABILITYMASK = 375,
50 SFGAO_LINK = 65536,
51 SFGAO_SHARE = 131072,
52 SFGAO_READONLY = 262144,
53 SFGAO_GHOSTED = 524288,
54 SFGAO_DISPLAYATTRMASK = 983040,
55 SFGAO_FILESYSANCESTOR = 268435456,
56 SFGAO_FOLDER = 536870912,
57 SFGAO_FILESYSTEM = 1073741824,
58 SFGAO_HASSUBFOLDER = -2147483648,
59 SFGAO_CONTENTSMASK = -2147483648,
60 SFGAO_VALIDATE = 16777216,
61 SFGAO_REMOVABLE = 33554432,
62 SFGAO_COMPRESSED = 67108864
63 }
64 #endregion
65
66 #region IExtractImage Enumerations
67 private enum EIEIFLAG
68 {
69 IEIFLAG_ASYNC = 0x0001, // ask the extractor if it supports ASYNC extract (free threaded)
70 IEIFLAG_CACHE = 0x0002, // returned from the extractor if it does NOT cache the thumbnail
71 IEIFLAG_ASPECT = 0x0004, // passed to the extractor to beg it to render to the aspect ratio of the supplied rect
72 IEIFLAG_OFFLINE = 0x0008, // if the extractor shouldn't hit the net to get any content neede for the rendering
73 IEIFLAG_GLEAM = 0x0010, // does the image have a gleam ? this will be returned if it does
74 IEIFLAG_SCREEN = 0x0020, // render as if for the screen (this is exlusive with IEIFLAG_ASPECT )
75 IEIFLAG_ORIGSIZE = 0x0040, // render to the approx size passed, but crop if neccessary
76 IEIFLAG_NOSTAMP = 0x0080, // returned from the extractor if it does NOT want an icon stamp on the thumbnail
77 IEIFLAG_NOBORDER = 0x0100, // returned from the extractor if it does NOT want an a border around the thumbnail
78 IEIFLAG_QUALITY = 0x0200 // passed to the Extract method to indicate that a slower, higher quality image is desired, re-compute the thumbnail
79 }
80 #endregion
81
82 #region ShellFolder Structures
83 [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4, Size = 0, CharSet = CharSet.Auto)]
84 private struct STRRET_CSTR
85 {
86 public ESTRRET uType;
87 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 520)]
88 public byte[] cStr;
89 }
90
91 [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Auto)]
92 private struct STRRET_ANY
93 {
94 [FieldOffset(0)]
95 public ESTRRET uType;
96 [FieldOffset(4)]
97 public IntPtr pOLEString;
98 }
99
100 [StructLayoutAttribute(LayoutKind.Sequential)]
101 private struct SIZE
102 {
103 public int cx;
104 public int cy;
105 }
106 #endregion
107
108 #region Com Interop for IUnknown
109 [ComImport, Guid("00000000-0000-0000-C000-000000000046")]
110 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
111 private interface IUnknown
112 {
113 [PreserveSig]
114 IntPtr QueryInterface(ref Guid riid, out IntPtr pVoid);
115
116 [PreserveSig]
117 IntPtr AddRef();
118
119 [PreserveSig]
120 IntPtr Release();
121 }
122 #endregion
123
124 #region COM Interop for IMalloc
125 [ComImportAttribute()]
126 [GuidAttribute("00000002-0000-0000-C000-000000000046")]
127 [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
128 //helpstring("IMalloc interface")
129 private interface IMalloc
130 {
131 [PreserveSig]
132 IntPtr Alloc(int cb);
133
134 [PreserveSig]
135 IntPtr Realloc(
136 IntPtr pv,
137 int cb);
138
139 [PreserveSig]
140 void Free(IntPtr pv);
141
142 [PreserveSig]
143 int GetSize(IntPtr pv);
144
145 [PreserveSig]
146 int DidAlloc(IntPtr pv);
147
148 [PreserveSig]
149 void HeapMinimize();
150 };
151 #endregion
152
153 #region COM Interop for IEnumIDList
154 [ComImportAttribute()]
155 [GuidAttribute("000214F2-0000-0000-C000-000000000046")]
156 [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
157 //helpstring("IEnumIDList interface")
158 private interface IEnumIDList
159 {
160 [PreserveSig]
161 int Next(
162 int celt,
163 ref IntPtr rgelt,
164 out int pceltFetched);
165
166 void Skip(
167 int celt);
168
169 void Reset();
170
171 void Clone(
172 ref IEnumIDList ppenum);
173 };
174 #endregion
175
176 #region COM Interop for IShellFolder
177 [ComImportAttribute()]
178 [GuidAttribute("000214E6-0000-0000-C000-000000000046")]
179 [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
180 //helpstring("IShellFolder interface")
181 private interface IShellFolder
182 {
183 void ParseDisplayName(
184 IntPtr hwndOwner,
185 IntPtr pbcReserved,
186 [MarshalAs(UnmanagedType.LPWStr)] string lpszDisplayName,
187 out int pchEaten,
188 out IntPtr ppidl,
189 out int pdwAttributes
190 );
191
192 void EnumObjects(
193 IntPtr hwndOwner,
194 [MarshalAs(UnmanagedType.U4)] ESHCONTF grfFlags,
195 ref IEnumIDList ppenumIDList
196 );
197
198 void BindToObject(
199 IntPtr pidl,
200 IntPtr pbcReserved,
201 ref Guid riid,
202 ref IShellFolder ppvOut
203 );
204
205 void BindToStorage(
206 IntPtr pidl,
207 IntPtr pbcReserved,
208 ref Guid riid,
209 IntPtr ppvObj
210 );
211
212 [PreserveSig]
213 int CompareIDs(
214 IntPtr lParam,
215 IntPtr pidl1,
216 IntPtr pidl2
217 );
218
219 void CreateViewObject(
220 IntPtr hwndOwner,
221 ref Guid riid,
222 IntPtr ppvOut
223 );
224
225 void GetAttributesOf(
226 int cidl,
227 IntPtr apidl,
228 [MarshalAs(UnmanagedType.U4)] ref ESFGAO rgfInOut
229 );
230
231 void GetUIObjectOf(
232 IntPtr hwndOwner,
233 int cidl,
234 ref IntPtr apidl,
235 ref Guid riid,
236 out int prgfInOut,
237 ref IUnknown ppvOut
238 );
239
240 void GetDisplayNameOf(
241 IntPtr pidl,
242 [MarshalAs(UnmanagedType.U4)] ESHGDN uFlags,
243 ref STRRET_CSTR lpName
244 );
245
246 void SetNameOf(
247 IntPtr hwndOwner,
248 IntPtr pidl,
249 [MarshalAs(UnmanagedType.LPWStr)] string lpszName,
250 [MarshalAs(UnmanagedType.U4)] ESHCONTF uFlags,
251 ref IntPtr ppidlOut
252 );
253
254 };
255
256 #endregion
257
258 #region COM Interop for IExtractImage
259 [ComImportAttribute()]
260 [GuidAttribute("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1")]
261 [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
262 //helpstring("IExtractImage"),
263 private interface IExtractImage
264 {
265 void GetLocation(
266 [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszPathBuffer,
267 int cch,
268 ref int pdwPriority,
269 ref SIZE prgSize,
270 int dwRecClrDepth,
271 ref int pdwFlags
272 );
273
274 void Extract(
275 out IntPtr phBmpThumbnail
276 );
277 }
278
279 #endregion
280
281 #region UnManagedMethods for IShellFolder
282 private class UnManagedMethods
283 {
284 [DllImport("shell32", CharSet = CharSet.Auto)]
285 internal extern static int SHGetMalloc(out IMalloc ppMalloc);
286
287 [DllImport("shell32", CharSet = CharSet.Auto)]
288 internal extern static int SHGetDesktopFolder(out IShellFolder ppshf);
289
290 [DllImport("shell32", CharSet = CharSet.Auto)]
291 internal extern static int SHGetPathFromIDList(IntPtr pidl, StringBuilder pszPath);
292
293 [DllImport("gdi32", CharSet = CharSet.Auto)]
294 internal extern static int DeleteObject(IntPtr hObject);
295 }
296 #endregion
297
298 #region Member Variables
299 private IMalloc alloc = null;
300 private bool disposed = false;
301 private System.Drawing.Size desiredSize = new System.Drawing.Size(246, 184);
302 private System.Drawing.Bitmap thumbNail = null;
303 #endregion
304
305 #region Implementation
306 public System.Drawing.Bitmap ThumbNail
307 {
308 get
309 {
310 return thumbNail;
311 }
312 }
313
314 public System.Drawing.Size DesiredSize
315 {
316 get
317 {
318 return desiredSize;
319 }
320 set
321 {
322 desiredSize = value;
323 }
324 }
325
326 private IMalloc Allocator
327 {
328 get
329 {
330 if (!disposed)
331 {
332 if (alloc == null)
333 {
334 //Kaushik - fails here at times
335 UnManagedMethods.SHGetMalloc(out alloc);
336 }
337 }
338 else
339 {
340 System.Diagnostics.Debug.Assert(false, "Object has been disposed.");
341 }
342 return alloc;
343 }
344 }
345
346 public System.Drawing.Bitmap GetThumbnail(string file)
347 {
348 if ((!File.Exists(file)) && (!Directory.Exists(file)))
349 {
350 throw new FileNotFoundException(
351 String.Format("The file '{0}' does not exist", file),
352 file);
353 }
354
355 if (thumbNail != null)
356 {
357 thumbNail.Dispose();
358 thumbNail = null;
359 }
360
361 IShellFolder folder = null;
362 try
363 {
364 folder = getDesktopFolder;
365 }
366 catch (Exception ex)
367 {
368 throw ex;
369 }
370
371 if (folder != null)
372 {
373 IntPtr pidlMain = IntPtr.Zero;
374 try
375 {
376 int cParsed = 0;
377 int pdwAttrib = 0;
378 string filePath = Path.GetDirectoryName(file);
379 pidlMain = IntPtr.Zero;
380 folder.ParseDisplayName(
381 IntPtr.Zero,
382 IntPtr.Zero,
383 filePath,
384 out cParsed,
385 out pidlMain,
386 out pdwAttrib);
387 }
388 catch (Exception ex)
389 {
390 Marshal.ReleaseComObject(folder);
391 throw ex;
392 }
393
394 if (pidlMain != IntPtr.Zero)
395 {
396 // IShellFolder:
397 Guid iidShellFolder = new
398 Guid("000214E6-0000-0000-C000-000000000046");
399 IShellFolder item = null;
400
401 try
402 {
403 folder.BindToObject(pidlMain, IntPtr.Zero, ref iidShellFolder, ref item);
404 }
405 catch (Exception ex)
406 {
407 Marshal.ReleaseComObject(folder);
408 Allocator.Free(pidlMain);
409 throw ex;
410 }
411
412 if (item != null)
413 {
414 string sFileName = Path.GetFileName(file);
415 IntPtr pidlFile = IntPtr.Zero;
416 try
417 {
418 int cParsed = 0;
419 int pdwAttrib = 0;
420 item.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, sFileName, out cParsed, out pidlFile, out pdwAttrib);
421 if (pidlFile != IntPtr.Zero)
422 {
423 getThumbnail(file, pidlFile, item);
424 Allocator.Free(pidlFile);
425 }
426 }
427 catch (Exception ex)
428 {
429 Marshal.ReleaseComObject(folder);
430 Allocator.Free(pidlMain);
431 throw ex;
432 }
433 Marshal.ReleaseComObject(item);
434 }
435
436 /*if (item != null)
437 {
438 //
439 IEnumIDList idEnum = null;
440 try
441 {
442 item.EnumObjects(
443 IntPtr.Zero,
444 (ESHCONTF.SHCONTF_FOLDERS |
445 ESHCONTF.SHCONTF_NONFOLDERS),
446 ref idEnum);
447 }
448 catch (Exception ex)
449 {
450 Marshal.ReleaseComObject(folder);
451 Allocator.Free(pidlMain);
452 throw ex;
453 }
454
455 if (idEnum != null)
456 {
457 // start reading the enum:
458 int hRes = 0;
459 IntPtr pidl = IntPtr.Zero;
460 int fetched = 0;
461 bool complete = false;
462 while (!complete)
463 {
464 hRes = idEnum.Next(1, ref pidl, out fetched);
465 if (hRes != 0)
466 {
467 pidl = IntPtr.Zero;
468 complete = true;
469 }
470 else
471 {
472 if (getThumbnail(file, pidl, item))
473 {
474 complete = true;
475 }
476 }
477 if (pidl != IntPtr.Zero)
478 {
479 Allocator.Free(pidl);
480 }
481 }
482
483 Marshal.ReleaseComObject(idEnum);
484 }
485
486
487 Marshal.ReleaseComObject(item);
488 }*/
489
490 Allocator.Free(pidlMain);
491 }
492
493 Marshal.ReleaseComObject(folder);
494 }
495 return thumbNail;
496 }
497
498 private bool getThumbnail(string file, IntPtr pidl, IShellFolder item)
499 {
500 IntPtr hBmp = IntPtr.Zero;
501 IExtractImage extractImage = null;
502
503 try
504 {
505 string pidlPath = PathFromPidl(pidl);
506 if (Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
507 {
508 // we have the item:
509 IUnknown iunk = null;
510 int prgf = 0;
511 Guid iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
512 item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, out prgf, ref iunk);
513 extractImage = (IExtractImage)iunk;
514
515 if (extractImage != null)
516 {
517 //Got an IExtractImage object!
518 SIZE sz = new SIZE();
519 sz.cx = desiredSize.Width;
520 sz.cy = desiredSize.Height;
521 StringBuilder location = new StringBuilder(260, 260);
522 int priority = 0;
523 int requestedColourDepth = 32;
524 EIEIFLAG flags = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
525 int uFlags = (int)flags;
526
527 try
528 {
529 extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref uFlags);
530 } catch {}
531
532 extractImage.Extract(out hBmp);
533 if (hBmp != IntPtr.Zero)
534 {
535 // create the image object:
536 thumbNail = System.Drawing.Bitmap.FromHbitmap(hBmp);
537 // is thumbNail owned by the Bitmap?
538 }
539
540 Marshal.ReleaseComObject(extractImage);
541 extractImage = null;
542 }
543 return true;
544 }
545 else
546 {
547 return false;
548 }
549 }
550 catch (Exception ex)
551 {
552 if (hBmp != IntPtr.Zero)
553 {
554 UnManagedMethods.DeleteObject(hBmp);
555 }
556 if (extractImage != null)
557 {
558 Marshal.ReleaseComObject(extractImage);
559 }
560 throw ex;
561 }
562 }
563
564 private string PathFromPidl(IntPtr pidl)
565 {
566 StringBuilder path = new StringBuilder(260, 260);
567 int result = UnManagedMethods.SHGetPathFromIDList(pidl, path);
568 if (result == 0)
569 {
570 return string.Empty;
571 }
572 else
573 {
574 return path.ToString();
575 }
576 }
577
578 private IShellFolder getDesktopFolder
579 {
580 get
581 {
582 IShellFolder ppshf;
583 int r = UnManagedMethods.SHGetDesktopFolder(out ppshf);
584 return ppshf;
585 }
586 }
587 #endregion
588
589 #region Constructor, Destructor, Dispose
590 public ThumbnailCreator()
591 {
592 }
593
594 public void Dispose()
595 {
596 if (!disposed)
597 {
598 if (alloc != null)
599 {
600 Marshal.ReleaseComObject(alloc);
601 }
602 alloc = null;
603
604 if (thumbNail != null)
605 {
606 thumbNail.Dispose();
607 }
608
609 disposed = true;
610 }
611 }
612
613 ~ThumbnailCreator()
614 {
615 Dispose();
616 }
617 #endregion
618 }
619 #endregion
620 }

另外,在GTAC上看到官方提供的另外一个C#版,https://solutions.industrysoftware.automation.siemens.com/view.php?sort=desc&q=get+part+preview+image+&file_type=text&i=nx_api3944&k=2&o=0

照顾没有账号的同学,摘录如下:

  1 NX API
2 Sample NX Open .NET C# program : create bitmap from selected part preview
3 Note:
4
5 GTAC provides programming examples for illustration only, and assumes that you are familiar
6 with the programming language being demonstrated and the tools used to create and debug procedures.
7 GTAC support professionals can help explain the functionality of a particular procedure, but we
8 will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
9
10
11
12 // Shows existing preview image from work part or selected part
13 // and also works external with 'run_journal'
14 using System;
15 using System.Drawing;
16 using System.Collections.Generic;
17 using System.ComponentModel;
18 using System.Data;
19 using System.Text;
20 using System.Windows.Forms;
21 using NXOpen;
22
23 public class Preview : Form
24 {
25 public static Session theSession;
26 public static Part wp;
27 public static ListingWindow lw;
28
29 private System.Windows.Forms.Button preview_btn;
30 private System.Windows.Forms.PictureBox pictureBox1;
31 private System.Windows.Forms.Button close_btn;
32 private System.Windows.Forms.Button load_btn;
33 private System.Windows.Forms.Button save_btn;
34 private TextBox textRelease;
35
36 public Preview()
37 {
38 InitializeComponent();
39 }
40
41 [STAThread]
42 public static void Main(string[] args)
43 {
44 try
45 {
46 theSession = Session.GetSession();
47
48 wp = theSession.Parts.Work;
49 lw = theSession.ListingWindow;
50
51 Preview preview = new Preview();
52 preview.ShowDialog();
53 }
54 catch (NXException ex)
55 {
56 MessageBox.Show(ex.Message);
57 Console.WriteLine(ex.Message);
58 }
59
60 }
61
62 private void getPreview(Part prt)
63 {
64 BasePart.HistoryEventInformation[] hInfo = prt.GetHistoryInformation();
65 string strInfo = "";
66 for (int i = 0; i < hInfo.Length; i++)
67 {
68 strInfo += hInfo[i] + "\r\n";
69 }
70 textRelease.Text = strInfo;
71
72 int width = 0;
73 int height = 0;
74 int[] pixels = null;
75
76 prt.GetPreviewImage(out width, out height, out pixels);
77 if (width > 0 && height > 0)
78 {
79 Bitmap image1 = createBitmap(width, height, pixels);
80 pictureBox1.Image = image1;
81 save_btn.Enabled = true;
82 }
83 else MessageBox.Show("Part has no valid preview", "Information");
84 }
85
86 private Bitmap createBitmap(int w, int h, int[] px)
87 {
88 //lw.WriteLine("Bitmap Image Size: " + w.ToString() + "x" + h.ToString());
89 Bitmap bm = new Bitmap(w, h);
90
91 for (int y = 0; y < h; y++)
92 {
93 for (int x = 0; x < w; x++)
94 {
95 int pixel = px[y * w + x];
96 Color col1 = Color.FromArgb(pixel);
97 Color col2 = Color.FromArgb(255, col1);
98 //lw.WriteLine(col2.ToString());
99 bm.SetPixel(x, y, col2);
100 }
101 }
102
103 return bm;
104 }
105
106 public static DialogResult select_part_file(ref String filename)
107 {
108 OpenFileDialog ofd = new OpenFileDialog();
109 DialogResult result;
110
111 ofd.Title = "Choose NX part file";
112 ofd.AddExtension = true;
113 ofd.DefaultExt = "prt";
114 ofd.Filter = "NX Part files (*.prt)|*.prt|All files (*.*)|*.*";
115 ofd.FilterIndex = 1;
116 ofd.ShowHelp = true;
117
118 // start browsing at current folder, uncomment for any other default directory
119 // ofd.InitialDirectory = GetEnvironmentVariable("UGII_BASE_DIR");
120 // ofd.InitialDirectory = GetEnvironmentVariable("UGII_BASE_DIR") + "\Moldwizard";
121 // ofd.InitialDirectory = "c:\mypath1\mypath2";
122 result = ofd.ShowDialog();
123 filename = ofd.FileName;
124 ofd.Dispose();
125 return result;
126 }
127
128 private void preview_btn_Click(object sender, EventArgs e)
129 {
130 if (wp == null)
131 {
132 MessageBox.Show("No Part", "Information");
133 return;
134 }
135 else
136 {
137 getPreview(wp);
138 }
139 }
140
141 private void load_btn_Click(object sender, EventArgs e)
142 {
143 String filename = "";
144 if (select_part_file(ref filename) == DialogResult.OK)
145 {
146 PartLoadStatus loadStatus = null;
147 int failCount = 0;
148
149 Part mypart = theSession.Parts.Open(filename, out loadStatus);
150
151 if (loadStatus.NumberUnloadedParts > 0)
152 failCount = reportLoadStatus(loadStatus);
153 else
154 {
155 getPreview(mypart);
156 mypart.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.CloseModified, null);
157 }
158 }
159 }
160
161 public static int reportLoadStatus(PartLoadStatus loadStatus)
162 {
163
164 lw.Open();
165
166 int counter = 0;
167
168 do
169 {
170
171 string file = loadStatus.GetPartName(counter);
172 string failure = loadStatus.GetStatusDescription(counter);
173 int statusCode = loadStatus.GetStatus(counter);
174 MessageBox.Show("File: " + file + "\nCode: " + statusCode + "\nStatus: " + failure, "Unloaded Part");
175
176 counter += 1;
177 }
178 while (!(counter == loadStatus.NumberUnloadedParts));
179
180
181 return counter;
182 }
183
184 private void save_btn_Click(object sender, EventArgs e)
185 {
186 SaveFileDialog save = new SaveFileDialog();
187 save.Filter = "Bitmap File(*.bmp)|*.bmp";
188 if (save.ShowDialog() == DialogResult.OK)
189 {
190 pictureBox1.Image.Save(save.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
191 }
192 }
193
194 private void close_btn_Click(object sender, EventArgs e)
195 {
196 Close();
197 }
198
199 private void InitializeComponent()
200 {
201 this.preview_btn = new System.Windows.Forms.Button();
202 this.pictureBox1 = new System.Windows.Forms.PictureBox();
203 this.close_btn = new System.Windows.Forms.Button();
204 this.load_btn = new System.Windows.Forms.Button();
205 this.save_btn = new System.Windows.Forms.Button();
206 this.textRelease = new System.Windows.Forms.TextBox();
207 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
208 this.SuspendLayout();
209 //
210 // preview_btn
211 //
212 this.preview_btn.Location = new System.Drawing.Point(14, 481);
213 this.preview_btn.Name = "preview_btn";
214 this.preview_btn.Size = new System.Drawing.Size(75, 23);
215 this.preview_btn.TabIndex = 0;
216 this.preview_btn.Text = "Work Part";
217 this.preview_btn.UseVisualStyleBackColor = true;
218 this.preview_btn.Click += new System.EventHandler(this.preview_btn_Click);
219 //
220 // pictureBox1
221 //
222 this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
223 this.pictureBox1.Location = new System.Drawing.Point(14, 12);
224 this.pictureBox1.Name = "pictureBox1";
225 this.pictureBox1.Size = new System.Drawing.Size(534, 400);
226 this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
227 this.pictureBox1.TabIndex = 1;
228 this.pictureBox1.TabStop = false;
229 //
230 // close_btn
231 //
232 this.close_btn.Location = new System.Drawing.Point(473, 481);
233 this.close_btn.Name = "close_btn";
234 this.close_btn.Size = new System.Drawing.Size(75, 23);
235 this.close_btn.TabIndex = 2;
236 this.close_btn.Text = "Close";
237 this.close_btn.UseVisualStyleBackColor = true;
238 this.close_btn.Click += new System.EventHandler(this.close_btn_Click);
239 //
240 // load_btn
241 //
242 this.load_btn.Location = new System.Drawing.Point(95, 481);
243 this.load_btn.Name = "load_btn";
244 this.load_btn.Size = new System.Drawing.Size(75, 23);
245 this.load_btn.TabIndex = 3;
246 this.load_btn.Text = "Load Part";
247 this.load_btn.UseVisualStyleBackColor = true;
248 this.load_btn.Click += new System.EventHandler(this.load_btn_Click);
249 //
250 // save_btn
251 //
252 this.save_btn.Enabled = false;
253 this.save_btn.Location = new System.Drawing.Point(191, 481);
254 this.save_btn.Name = "save_btn";
255 this.save_btn.Size = new System.Drawing.Size(75, 23);
256 this.save_btn.TabIndex = 3;
257 this.save_btn.Text = "Save BMP";
258 this.save_btn.UseVisualStyleBackColor = true;
259 this.save_btn.Click += new System.EventHandler(this.save_btn_Click);
260 //
261 // textRelease
262 //
263 this.textRelease.BackColor = System.Drawing.SystemColors.Control;
264 this.textRelease.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
265 this.textRelease.Location = new System.Drawing.Point(14, 418);
266 this.textRelease.Multiline = true;
267 this.textRelease.Name = "textRelease";
268 this.textRelease.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
269 this.textRelease.Size = new System.Drawing.Size(534, 57);
270 this.textRelease.TabIndex = 4;
271 //
272 // Preview
273 //
274 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
275 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
276 this.ClientSize = new System.Drawing.Size(563, 516);
277 this.Controls.Add(this.load_btn);
278 this.Controls.Add(this.save_btn);
279 this.Controls.Add(this.close_btn);
280 this.Controls.Add(this.pictureBox1);
281 this.Controls.Add(this.preview_btn);
282 this.Controls.Add(this.textRelease);
283 this.Name = "Preview";
284 this.Text = "NX Part Preview";
285 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
286 this.ResumeLayout(false);
287 this.PerformLayout();
288
289 }
290
291 }

C++ (C#)实现获取NX PART预览图的更多相关文章

  1. Android开发 获取视频中的信息(例如预览图或视频时长) MediaMetadataRetriever媒体元数据检索器

    前言 在Android里获取视频的信息主要依靠MediaMetadataRetriever实现 获取最佳视频预览图 所谓的最佳就是MediaMetadataRetriever自己计算的 /** * 获 ...

  2. 为Unity的新版ugui的Prefab生成预览图

    using UnityEngine;using System.Collections;using UnityEditor;using System.IO; [CustomPreview(typeof( ...

  3. 18.libgdx制作预览图,背景移动循环,改变地图颜色

    经过构思,游戏将分为两部分, 1,预览图,只负责展示世界形势 2,根据预览图生成的战役项 现在要记录的是我制作预览图的部分 1.预览图只有实际地图的1/4,首先生成地图(建议不要缩放以前地图,由于误差 ...

  4. HTML5-video标签-实现点击预览图播放或暂停视频

    HTML5-video标签-实现点击预览图播放或暂停视频 刚刚参加工作,开始更多的接触到一些新的知识,促使我开始了解html5和css3的新特性.这时我才真的发现到html5和css3的强大. 之前关 ...

  5. 可拖拽和带预览图的jQuery文件上传插件ssi-uploader

    插件描述:ssi-uploader是一款带预览图并且可以拖拽文件的jQuery ajax文件上传插件.该文件上传插件支持AJAX,支持多文件上传,可控制上的文件格式和文件大小,提供各种回调函数,使用非 ...

  6. Images corrections preview with lensfun 不同型号镜头预览图 828张 合集

    lensfun 目前支持900多种镜头, 但是网上并没有预览图; 闲暇时间做了800多张预览图合集 下载地址 链接: https://pan.baidu.com/s/1crfhoKKZKnxntvNH ...

  7. PHP如何生成文章预览图

    PHP如何生成文章预览图 一.总结 一句话总结:php的wkhtmltox扩展,php官方文档有怎么使用,或者github,或者百度,等等等等 wkhtmltox 1.PHP如何自动生成文章预览图? ...

  8. 资源管理器总是生成 avi,mpeg的预览图

    感觉非常讨厌. 图片可以直接显示,但是视频的预览图感觉很不舒服. 查了一下 , 用ShellExView 禁用一下 MF XXXX Property Handler 就可以了. 官网最下面可以下载: ...

  9. APP图标设计小技巧:在iOS上快速获得APP图标的真实预览图

    严格来说,这并不是一篇关于前端开发的文章,因为涉及到的知识非常浅.这只是一个向设计狮们分享的小经验,只是其中用到了一些前端内容. 最近接了个私活,了解到一个初创公司正在高价悬赏Logo(主要用于APP ...

随机推荐

  1. Redis高级项目实战,都0202年了,还不会Redis?

    导读 大家都听过1万小时定律,可事实真的是这样吗?做了1万小时的CRUD,不还只会CRUD吗,这年头不适当的更新自身下技术栈,出门和别人聊天吹牛的时候,都没拿不出手,(⊙o⊙)…Redis没入门的童鞋 ...

  2. Linux kernel 模块 hello 测试

    原文链接:https://www.cnblogs.com/nerohwang/p/3621316.html hello.c 文件: #include <linux/kernel.h> /* ...

  3. 精讲响应式WebClient第5篇-请求超时设置与异常处理

    本文是精讲响应式WebClient第5篇,前篇的blog访问地址如下: 精讲响应式webclient第1篇-响应式非阻塞IO与基础用法 精讲响应式WebClient第2篇-GET请求阻塞与非阻塞调用方 ...

  4. python数据类型和运算符

    一.python类型判断 type,isinstance type(变量或常量):返回数据类型 a = 23.3print(type(a))b = 2e3print(b, type(b))输出: &l ...

  5. Java线上问题排查神器Arthas快速上手与原理浅谈

    前言 当你兴冲冲地开始运行自己的Java项目时,你是否遇到过如下问题: 程序在稳定运行了,可是实现的功能点了没反应. 为了修复Bug而上线的新版本,上线后发现Bug依然在,却想不通哪里有问题? 想到可 ...

  6. 【java学习笔记】LongAdder

    目录 1.背景 2.LongAdder 3.Striped64内部结构 4.LongAdder的add方法解析 5.Striped64的longAccumulate方法解析 6.总结 LongAdde ...

  7. SQL语句中IF的简单使用 - 关联leetcode 627.交换工资

    MySQL的IF既可以作为表达式用,也可在存储过程中作为流程控制语句使用,如下是做为表达式使用: IF表达式 IF(expr1,expr2,expr3) 如果 expr1 是TRUE (expr1 & ...

  8. 【洛谷日报#26】GCC自带位运算系列函数

    文章转自 洛谷 谈到GCC的黑科技,大家想到的一定是这句: #pragma GCC optimize (3)//吸氧 抑或是这句: #pragma GCC diagnostic error " ...

  9. Python错误,pip安装包或更新时因超时而报错误

    报错原因 想要使用pip,结果出下以下警告: 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知道如何去学习更加高 ...

  10. I - 乓 (BFS+邻接表)

    USTC campus network is a huge network. There is a bi-directional link between every pair of computer ...