機翼結(jié)構(gòu)CATIA軟件二次開發(fā),機翼,結(jié)構(gòu),catia,軟件,二次開發(fā)
畢 業(yè) 設(shè) 計(論 文)外 文 參 考 資 料 及 譯 文
譯文題目: CATIA V5 Automation
CATIA V5 的自動化
學(xué)生姓名:
?! I(yè):
所在學(xué)院:
指導(dǎo)教師:
職 稱:
CATIA V5 Automation
CATIA V5 Automation & Scripting : Presentation
On both NT and UNIX:The scripting allows you to program CATIA in a verysimple way with macros on both NT and UNIX platforms. CATIA Use the common paton MS- VBScript ( v5.x on NT and v3.0 on Unix) to have the same macros running on both plat forms.
On NT platforms:Automation allows CATIA to share objects with other external applications such as Word/Excel or Visual Basic programs. CATIA can use the Word/ Excel objects as well as Word/ Excel can use the CATIA Objects.
On UNIX platforms:A future version of CATIA will allow t o share its objects from Java. This will provide a f ull compatibility between UNIX and NT.
CATIA V5 Automation: Present ation ( NT only)
Automation allows communication between several process.
CATIAV5 On NT:Interfaces COM:Visual Basic Script ( for Macros),Visual Basic For Applications ( forex: Word/ Excel ),Visual Basic.
COM ( Component Object Model ) is t he “ Microsof t ” standard to share objects bet ween several applications.
Automation is a “ Microsoft ” technology to use COM obj ect s i n an interpreted envi ronment .
Activex component is a “ Microsof t ” standard to share objects between several appli cations even in an i nter preted environment .
OLE ( Object Linking and Embedding) means that the document can be linked in the document of an other application OLE and can be edited in that other application ( I n place editing) .
Differences between VBScript , VBA and Visual Basic
Visual Basic( VB) is the full version:It can generate independent programs,It can al so create Activex and Servers. It can be compi l ed. VB provides an added document ation called “ Books online” ( VB 5. 0). VBA ( Visual Basic for Applicat ions) is a subset of Visual Basic,VBA is hosted in applications such as Word, Excel or CATI A. I t provides a complete environment with an Editor , a debugger , a Help Object Vi ewer and Completion.
The + menu allows to declare the object library used. Thi s gives access to the completion and the object browser . VBScript ( Vi sual Basic Scr ipt ) is a subset of VBA. Simple interpreted Basic language Can call CATIA Objects. No type is used. The system tries dynamically to call methods and properties of obj ects. ( Late binding calling objects through t heir IDi spatch i nterface) .
Suppor t ed Languages
The languages supported by CATIA ar e:
CATScript : It is the language of the script ing in V5 until the inclusive V5R7. From t he V5R8, it becomes deprecated and it is advised to use rather MS VBScript or MS VBA.
MS- VBScript : It is the language to use f irst and foremost from the V5R8, and the only solution allowing to have a portability of the scripts in NT and UNIX. MS- VBScript differs from CATScript by the fact that the notion to declare a variable by Dim X As Y does not exist .
MS- VBA : VBA is an environment of development integrated into CATI A and dedi cated to VB but only on NT. MS- VBA differ s from MS- VBScript by the comfort of programming and the possibility of realizing simple application with a graphic interf ace.
Activex with panels can be added in a macro but only on NT.
Ot her services such as “ Scripting. FileSystemObj ect ” are called with“ Create Object ” and are available only on NT.
The declaration of object types is recorded in the macro ( even if it is not used in VBScript ) but it can help you ( with the completion in VB on NT) to program your f uture application.
CATI A V5 Associat ion with file extension
A doubl e- click in Windows Explorer on a ” . CATPart ” file opens it i n CATIA V5. On NT, If CATIA V5 is not running, it is launched aut omat i cally.
In the Windows Explorer , with “ As Web page” mode, a thumbnail shows a preview f or all CATIA Documents.
CATIA V5 Scripting capabilities
In process application: This is done from the Tool s + Macro in CATIA menu. When the Macro is running, CATIA is deactivated. You cannot store variables in a macro bet ween two calls. Access with VBScript ( Microsof t ) and VBA on Windows NT, and with VBScript ( Winsof t ) on Unix.
This is based on AUTOMATION. A foreign process can call CATIA, creat e or modif y geometry, decode, measure or pilot CATIA. CATIA is still running. For each action of the application, we have to check if CATIA is in the good state to synchronize the t wo processes. This kind of applications can be developed in: Visual Basic,Windows Scripting Host ( VBScript , JScript ), Windows Explorer HTML ( VBScript , JScri pt ) or Any other COM applications.
In the future, a Java encapsulation of t he V5 Automation objects will also be provi ded. This will enable the development of applications on NT and Unix based on Java, both i n- process and out - process.
I n- Pr ocess Macros
We call In- process because the script interpretation is performed in the same process as CATI A. A list shows the Macro available. We can run, edit , rename or delete exist ing script , or create a new one. The list of libr aries of script proposed into the panel above is modifiable through the window of libraries.
CATI A V5 Visual Basic Editor
With CATIA Visual Basic Editor , We can editexi sting macro or create a new one, i nser t graphic form, debug and r un VBA project .
Macro libraries
The inter face of the dialog “ Tool s + Macro + Macros…” allows to choose a librar y of macro ( a director y of macro or a VBA project ) or a document on which we wish t o work.
From this window, we can close an already opened librar y, open a librar y, or create a library. Libraries are shown by type ( directory, VBA project . . . ) . Every type of libr ary supports different languages. VBA supports only the language MS- VBA, while in a director y we can write in MS- VBScript or in CATScript .
Recording a Macro
The panel of recording VBA allows t o choose the container in which we are going to record, the used language and t he name of the macro to be recorded. The syntax of t he recorded script is going to differ according to the menu chosen. Recording a Macr o gener at es a script corresponding to the creation or modification of the objects in t he recorded sequence. After stopping the recording, we can store, editor replay this scr ipt ( called macro) . As arule, recording a macro helps you to learn how to program something.
Running a Macro
You can execute a macro as soon as CATIA is started : CNEXT - macro
E: \ Users\ Macros\ MacroToRun. CATScript
You can start CATIA in batch mode t o execute a macro:CNEXT - batch - macro
E: \ Users\ Macros\ MacroToRun. CATScr i pt
You can run a macro inter actively from the “ Macro” menu.
You can run a macro inter actively from an icon in a toolbar.
Execution of a Macro from another Macro
CATIA V5R9 offers the capability through an Automation function to execute a Macr o from another Macro. The f unction lets the user invoke another scripted function, contained in another macro library, potentially written in another scripting language. A support enum CATSysLibraryType is used to let the developer describe the kind of l ibr ary the function to call is contai ned in. ( Example from VBScript ).
To call an Add function that is defined in a “ E: \ Macros\ Math” directory library, in a file “ Integer Math. catvbs” , one would writ e:
Dim args2( 1)
args2( 0) = 3
args2( 1) = 2
Dim addResult
addResult = CATIA. Syst emServi ce. ExecuteScript ( "E: \ Macros\ Math", catScript LibraryTypeDirectory, "Integer Math. catvbs", "Add", args2 ) MsgBox addResult
To call an Print Repor t ( ) sub that is defined in a
“ E: \ Parts\ Part1. CATPar t ” V5 document library, in a file
“ Statistics. catvbs” , one would write:
Dim args( )
CATIA. SystemService. Execut eScript "E: \ Part s\ Part1. CATPar t ",
cat Script Library TypeDocument , "Statistics. catvbs", "PrintReport ", args
Adding a Macro as a command in a Toolbar
Select the macro you want to add in Tools + Customi ze + Commands Tab
page + Macros: Drag and Drop the macro name to the tool bar you wish :
To select another icon than the default one, click on ShowPr oper t i es. . .
Macros Options Inter face
The panel of the dialog “ Tool s + Options + Macros” allows to choose according to t he language, the Editor who will be launched to edit a macro, and to specify external t ypelibs to take into account in the replay of scripts. Whith the new inter face, all the t ypelibs V5 of the run time view are automatically taken into account . This option ser ves only fordeclaring typelibs except runtime view ( Excel for example) .
Running Out - Process programs ( On NT only)
The script is running in another application running in another process, such as: Vi sual Basi c, VBA ( in Excel or Word) , Using WSH ( Wi ndows Scripting Host ) with VBScript or JavaScript , Using HTML with VBScript or JavaScript.
CATIA can be scripted from any other COMApplication.
Running Out - Process from VBA or Visual Basic
VBA and Visual Basic provide useful tools: For this, you can declare all the typelib fi es ( *. t l b) provided by Dassault Systemes. The typelib files contain the declarations of all the object s, methods and proper ties of the exposed objects.
Running Out - Process from VBA or Visual Basic
Type definition allows type checking and “ early binding” . Helpful completion gives you all the properties and methods of an object and gives you the argument types of a met hod. Browser Object describes all the expor ted objects
Running Out - Process from VBA or Visual Basic
Her e are the statements to launch CATIA V5 from VBA or Visual Basic.
If CATIA is already running :
[ . . . ]
Dim CATIA as Object
Set CATIA = Get Object ( , “ CATIA. Application” )
[ . . . ]
If CATIA is not already running :
[ . . . ]
Dim CATIA as Object
Set CATIA = Create Object ( “ CATIA. Application” )
CATI A. Visible = True
[ . . . ]
If the typelib INFITF. tbl is referenced, we can declar e CATIA as INFI TF. Application.
Bolt from Excel Exampl e
The purpose of this example is to launch CATIA and to create a bolt part
from Excel .
In this Example, we will learn : the Visual Basic for Application environment in Excel . how to create a Butt on in Excel . how to associate a macro to this button. the macro will launch CATIA and create a Bolt .
Bolt from Excel
Have a look on the code: This tries to retrieve CATIA and if not successful starts it .
Dim CATIA As Object
' Get CATIA or start it if necessar y.
On Error Resume Next
Set CATIA = Get Object ( , "CATIA. Application")
If Err . Number <> 0 Then
Set CATIA = Create Object ( "CATIA. Application")
CATIA. Visible = True
End If
On Err or GoTo 0
Both functions Get Object and Create Object are provided by VBA ( as well as Visual Basic) .
Running Out - Process using the Windows Scripting Host ( WSH)
WSH enabl es scripts written in different languages such as VBScr i pt and JavaScr ipt . You can use a standard Editor to write your application. If your programfails, you will be able to use the Windows Devel opment environment .
It is possible to develop an application in Visual Basic, then put the types in comment and run it with WSH. To run a VBScript ( *. vbs) or JavaScript ( *. j s) f i l e, you can use cscript or wscript commands. Usually, wscript . exeis already associated with those extensions.
VBScript under Windows Scripting Host .
You can write a VBScript program in a simple ASCII text file with the extension “ . vbs” for Visual Basic Script . Under WSH, Get Object and Create Object are provi ded by the object Wscript . The fol lowing code launches
CATI A V5.
On Error Resume Next
Set CATIA = Wscript . Get Object ( , "CATIA. Application")
If Err . Number <> 0 Then
Set CATIA = Wscript . Create Object ( "CATI A. Application")
CATI A. Visibl e = True
End If
Bolt VBSript . vbs exampl e
Have a look on the source code.
To run the “ Bolt VBScr i pt . vbs” exampl e , you can double– click on i t .
To run the example on a Command prompt Window you can also use : Cscript
Bolt VBScript . vbs Or wscript Bolt VBScript . vbs
JavaScript under Windows Scripting Host
In the same way as VBScript , you can write a JavaScript program in a simple ASCI I text file with the extension “ . j s” for JavaScript .
Under WSH, Get Object and Create Object are provided by the object Wscript .
The following code launches CATIA V5.
CATI A = WScript . Get Object ( , "CATIA. Application") ;
if ( CATIA == nul l ) {
CATIA = WScript . Create Object ( "CATIA. Application") ;
CATIA. Visible = true; }
Bolt JavaSript . js exampl e
Have a look on the source code.
To run the “ Bolt JavaScript . js” example, you can double– click on it .
To run the example on a Command prompt Window you can also use : Cscript Bolt JavaScript . js Or wscript Bolt JavaScript . js
Out - Process in HTML ( NT & Microsof t Internet Explorer Only)
In HTML, you can include VBScript or JavaScript routines. Microsoft explorer pr ovides ActiveXObject ( in JavaScript ) and Create Object ( in VBScript ) functions to Launch Aut omation Servers. So, it is possi ble to call
CATIA V5 this way. You can access to the Microsof t Devel opment Environment to debug your Application. You can launch the “ Microsof t Development
Environment from Explorer by : “ Script Debugger ” “ Open”
Out - Process in HTML with VBScript
Load the “ Bolt VBScript . html ” example in Microsof t Internet Explorer . You will be able to Click on the “ Bol t ” button to create a Boltin CATIA V5. You can view t he source code by + menus. Due to security reasons, some warni ng messages for running the script , may appear depending on the configuration and i f the server is local or not .
Out - Process in HTML with JavaScript
Load the “ Bolt JavaScript . html ” example in Microsoft Internet Explorer . You wi ll be able to Click on the “ Bolt ” butt on to create a Bolt in CATIA V5. You can view the source code by +
鏈接地址:http://m.italysoccerbets.com/p-1707851.html