NX7 Open Wizard for Visual Studio 2010

最近需要基于UG(现在叫NX)做一些开发。由于用Windows7 +VS2010已经有一段时间了,感觉还不错,于是为了不重新折腾开发环境,下载安装了能够支持Windows7的UG最新版本NX7.5。安装过程与之前版本没有区别,但是在配置NXOpen for C++(详细介绍请看begtostudy的博客)时才发现,如果注定要折腾,那只是迟早的事。

由于NXOpen几乎为UG的所有功能都提供了接口,因此规模可见一斑。为了方便开发,NXOpen提供了Visual Studio中常见的Wizard来帮助开发者快速创建所需的项目类型,免去手动添加头文件、链接库等配置的麻烦。然后,即使最新的NX7.5,所提供的Wizard也只支持到VS2008。如果直接按照文档中的安装说明,将Wizard相关文件拷贝到VS的对应目录下的话,Wizard并不会出现在新建项目的菜单中,玄机在NX7_Open.vsz这个文件中,这个文件保存了Wizard的基本信息,内容如下:

 

1VSWIZARD 7.0
   2Wizard=VsWizard.VsWizardEngine.9.0
   3
   4Param="WIZARD_NAME = NX7_Open"
   5Param="FALLBACK_LCID = 1033"


第2行中,默认的VsWizardEngine版本是9.0(VS2008),因此需要手动改为10.0(VS2010)。修改保存后,启动VS2010,在新建菜单的C++类别下,就可以看到NX7 Open Wizard的选项了,但是问题到此还没有结束(我正是从这里开始折腾的)。选择NX7 Open Wizard,确定后会弹出类似于MFC中的新建项目向导,提供一些配置(不需要修改的话可以直接点Finish)。但是当点击Finish的时候,问题出现了,错误信息为“对象不支持此操作”,项目创建失败。初次看到这样的错误提示,的确无从下手,但是任何错误都一定有原因的。

Visual Studio中的项目模板和向导都是可以自定义的,并且在VS2010中还提供了创建自定义Wizard的项目模板Custom Wizard(详细的资料看这里)。根据MSDN上的相关内容介绍,Wizard其实是一组html页面(每个页面对应一个步骤),通过JScript来调用Visual Studio提供的内建对象(code, project 和wizard)来实现最终项目的生成和配置。每一个Wizard项目都会包含一些固定的文件和文件夹,如下(来自MSDN):

File

Description

Project.vsz

A text file that resembles the old .ini format. It identifies the wizard engine and provides context and optional custom parameters.

Project.vsdir

A text file that enables the Visual Studio shell to find the wizard and display it in the New Project dialog box.

HTML files (optional)

A wizard can contain a user interface (UI), which is an HTML interface. A wizard without a UI contains no HTML files.

If a wizard has a UI, each individual screen in the wizard is known as a page, and each page specifies UI features.

The default.htm file defines the first page in the wizard. Use the Number of pages list box of Application Settings, Custom Wizard to specify additional pages. Each additional page is defined by a Page_page-number.htm file, where page-number ranges from 2 through the number of pages that you specify.

Script files

The Custom Wizard creates a JScript file, default.js, for each wizard created. This file contains JScript functions that access the Visual C++ Wizard, Code, and Environment Object Models to customize a wizard. You can customize and add functions in your wizard's default.js file.

Additionally, your wizard includes the common.js file, which contains commonly used JScript functions and is shared among all wizards, including the wizards used by Visual C++ to create other project types. For more information, see Customizing C++ Wizards with Common JScript Functions.

Templates

A wizard's templates are a collection of text files that contain directives, which are parsed and inserted into the symbol table, depending on the wizard user's selections. The template text files are rendered according to the user input and added to the project created by the wizard. The appropriate information is obtained by directly accessing the wizard control's symbol table.

Templates.inf

A text file that lists all templates associated with the project.

Default.vcxproj

An .xml file that contains the information about the project type.

Sample.txt

A template file that shows how your wizard directives are used.

ReadMe.txt

A template file that contains a summary of each file created by the Custom Wizard.

Images (optional)

You can provide any images, such as icons, GIFs, BMPs, and other HTML-supported image formats, to enhance the UI for your wizard. A wizard that has no UI does not require images.

Styles.css (optional)

A file that defines the styles for the UI. If your wizard does not have a user interface, the Custom Wizard does not create a .css file.


其中提到的Script Files(默认为default.js)完成了项目生成的主要工作,而之前提到的错误也正出在这里。CustomWizard项目中的html files需要调用Visual Studio提供的内建对象(包含在common.js中),因此没有办法想调试网页一样使用浏览器调试JScript脚本,VS2010貌似也没有提供其他的调试JScript的方法(至少我没有找到),因此不得不利用注释测试NX7_Open中default.js的每一行语句(好在文件不是很长),最后终于发现了罪魁祸首,在default.js文件的第200行:

200       CLTool.Detect64BitPortabilityProblems = true;

这句的作用是设置一个编译器开关,指定编译器在编译过程中检查程序的64位可移植性,但是在VS2010,这一特性在VS2010中已经不建议使用,并且这种设置方式已经不适用于VS2010(详见这里),所以才出现错误信息“对象不支持此操作”,解决办法很简单,直接注释掉该行就可以了。至此,就可以愉快的在VS2010中使用NX7 Open Wizard创建你自己的项目了。

尽管问题很简单,解决办法也很简单,但探索的过程是漫长的,好在国庆长假时间充裕。最后再次感谢begtostudy学长(虽然彼此不认识)的博客。

posted on 2010-10-02 13:58 HienChu 阅读(4603) 评论(5)  编辑 收藏 引用

评论

# re: NX7 Open Wizard for Visual Studio 2010 2010-10-19 09:11 Sunye

Hi, I am from korea.
I had a same problem with you and solved problem with your blog.

Thank you very much for the great work.
And i am very happy i found same developer ( or programmer ) who develop the NX API program :D

It was nice meeting you. Thanks.  回复  更多评论   

# re: NX7 Open Wizard for Visual Studio 2010 2011-03-25 09:04

good~~  回复  更多评论   

# re: NX7 Open Wizard for Visual Studio 2010 2011-05-19 16:56 freebird

请问一下对于C#的又怎么改呢,我用的是C#,现在编不了  回复  更多评论   

# re: NX7 Open Wizard for Visual Studio 2010 2012-03-26 09:09 hx0hx

我也找了半天自定义项目模板的方法,有两个地方没搞定,请问 default.js 里面是如何修改“包含目录”和“库目录”的呢?谢谢。  回复  更多评论   

# re: NX7 Open Wizard for Visual Studio 2010 2014-03-02 18:48 游客

谢谢~~  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

文章分类

搜索

最新评论

阅读排行榜

评论排行榜