機(jī)翼結(jié)構(gòu)CATIA軟件二次開發(fā)
機(jī)翼結(jié)構(gòu)CATIA軟件二次開發(fā),機(jī)翼,結(jié)構(gòu),catia,軟件,二次開發(fā)
畢 業(yè) 設(shè) 計(論 文)外 文 參 考 資 料 及 譯 文譯文題目: CATIA V5 Automation CATIA V5 的自動化學(xué)生姓名:專業(yè):所在學(xué)院:指導(dǎo)教師:職稱:CATIA V5 AutomationCATIA V5 Automation & Scripting : PresentationOn 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 BasicVisual 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 LanguagesThe 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 extensionA 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 capabilitiesIn 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 MacrosWe 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 EditorWith 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 librariesThe 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 MacroThe 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 MacroYou can execute a macro as soon as CATIA is started : CNEXT - macroE: Users Macros MacroToRun. CATScriptYou can start CATIA in batch mode t o execute a macro:CNEXT - batch - macroE: Users Macros MacroToRun. CATScr i ptYou 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 MacroCATIA 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) = 3args2( 1) = 2Dim addResultaddResult = CATIA. Syst emServi ce. ExecuteScript ( E: Macros Math, catScript LibraryTypeDirectory, Integer Math. catvbs, Add, args2 ) MsgBox addResultTo 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 , argsAdding a Macro as a command in a ToolbarSelect the macro you want to add in Tools + Customi ze + Commands Tabpage + 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 faceThe 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 BasicVBA 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 BasicType 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 objectsRunning Out - Process from VBA or Visual BasicHer e are the statements to launch CATIA V5 from VBA or Visual Basic.If CATIA is already running : . . . Dim CATIA as ObjectSet CATIA = Get Object ( , “ CATIA. Application” ) . . . If CATIA is not already running : . . . Dim CATIA as ObjectSet 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 eThe purpose of this example is to launch CATIA and to create a bolt partfrom 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 ExcelHave 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 NextSet CATIA = Get Object ( , CATIA. Application)If Err . Number 0 ThenSet CATIA = Create Object ( CATIA. Application)CATIA. Visible = TrueEnd IfOn Err or GoTo 0Both 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 launchesCATI A V5. On Error Resume NextSet CATIA = Wscript . Get Object ( , CATIA. Application)If Err . Number 0 ThenSet CATIA = Wscript . Create Object ( CATI A. Application)CATI A. Visibl e = TrueEnd IfBolt VBSript . vbs exampl eHave 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 : CscriptBolt VBScript . vbs Or wscript Bolt VBScript . vbsJavaScript under Windows Scripting HostIn 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 eHave 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 . jsOut - 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 callCATIA V5 this way. You can access to the Microsof t Devel opment Environment to debug your Application. You can launch the “ Microsof t DevelopmentEnvironment from Explorer by : “ Script Debugger ” “ Open”O(jiān)ut - Process in HTML with VBScriptLoad 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 JavaScriptLoad 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 + menus.About Object s, Collections, Properties and MethodsScripting languages such as Visual Basic rely on objects. With CATIA, documents, windows, viewers, parts, sketches, pads, even lines and curves are represented as objects in Visual Basic.Object : an entity.Ex: Document , Pad, Line, Property: a characteristic of an object .DocName = CATIA. ActiveDocument . FullNameMethod: an action on an objectCATIA. ActiveDocument . SaveAs “ MyNewName”Collection: a list of objects.The CATIA collections index begins at 1, and not 0 :For i =1 t o CATIA. Documents. Countmsgbox CATIA. Documents. It em( i ) . NameNextWe can also access a collection with the name of the object :Example: msgbox CATIA. Document s. Item( Pr oduct 1. CATPr oduct ) . NameWe add objects to the collections with the method add : set myPartDoc = CATIA. Documents. add( Par t )About Inheritance and AggregationThere are two kinds of relations between objects : Inheritance helps you to specialize objects while gathering common properties and methods. Aggregation is the ability of an object to contain another one.In the following diagram, the Application aggregat es the Documents collection. The Part Document object is a specialized document that is dedicated to parts and whi chinher its the properties and the methods of t he Document object .Scripting Infrastructure featur es overviewDocuments and WindowsThe CATIA Application object aggregates two main collection objects :Documents and Windows. The Documents collection aggregates any number of Document ( s) since the multiplicity is set to *. The Document object is an abstract object , and only its derived type can actually be created, that is the Part Document , Product Document and Drawing Document . The Windows collection aggregates number of Window( s) , which themselves aggregate one Viewers collection which aggregates any number of Viewer ( s) . The binary association between the Window and the Document objects means that the Document object is the parent of the Wi ndow object .I nfrastructur e Object Architectur eThese objects are shared by all CATIA products. The root object is the Application, which aggregates or i ncludes Documents and Windows.Application and DocumentApplication is the Root object for all CATIA macros. This correspond to the CATIA frame window. The CATIA application is always named CATIA for in- process macr o. The Document s collection provide a method to Add a new document and another to Open an existing document . A Document can be a PartDocument , Product Document or a DrawingDocument . Each Document provide Its own methods to Save or Save As Itsel f .Creating and Opening a DocumentCreating a new Document :Di m Doc as DocumentSet Doc = CATIA. Document s. Add( “ Par t ” ) creat e a Part Document Instead of “ Par t ” , Use “ Product ” for a Product Document or “ Drawing”for a Drawing DocumentOpening a new Document :Dim Doc as DocumentSet Doc= CATIA. Documents. Open( “ E: Parts Document ToOpen. CATPar t ” ) Both Add and Open functions add the Document in the Documents Collection.CATIA V5 的自動化CATIA V5的自動化和腳本:在NT和Unix上:腳本允許你用宏指令以非常簡單的方式計劃CATIA。CATIA使用在MS VBScript中( V5. x 中在 NT和 UNIX3. 0 )的共用部分來使得在兩個平臺上運行相同的宏。在NT平臺上:自動化允許CATIA像Word/ Excel 或者Visual Basic程序那樣與其他外用分享目標(biāo)。ATIA 能使用 Word/ Excel 對象就像 Word/ Excel 能使用 CATIA對象。在Unix平臺上:CATIA將來的版本將允許從Java 分享它的對象。這將提供在Unix 和NT 之間的一個完美兼容。CATIA V5自動化:介紹(僅限NT)自動化允許在幾個進(jìn)程之間的聯(lián)系:CATIAV5在NT上 :接口COM:Visual Basic 腳本(對宏來說),Visual Basic為應(yīng)用(適合前:Word/ Excel ),Vi sual Basic。COM(零部件目標(biāo)模型)是“ 微軟“ 標(biāo)準(zhǔn)于幾個應(yīng)用程序之間的共享對象。Automation 是一種“ 微軟“ 技術(shù),它使用一種解釋環(huán)境中的COM對象。Activex組成部分是“ 微軟“ 標(biāo)準(zhǔn)于幾個應(yīng)用程序之間的共享對象,即使在解釋環(huán)境里。OLE(對象的鏈接與嵌入) 意思是資料可以在一個其他應(yīng)用OLE的資料里連結(jié)并且可以被編輯的方法(在適當(dāng)?shù)奈恢镁庉?。在VBScript,VBA和Visual Basic之間的差別:Visual Basic (VB) 是全部的版本。它能產(chǎn)生獨立的計劃,它也能建立Activex和服務(wù)器。它可以被編輯。VB中提供了一個補充文件名為“ 在線叢書“(VB的5.0)VBA(應(yīng)用的 Visual Basic)是一個 Visual Basic 的子集。VBA是在諸如 Word,Excel 或 CATIA的應(yīng)用托管。它提供了一個用編輯器,調(diào)試器,一個幫助對象查看器和完整的環(huán)境。該+菜單允許申報使用的對象庫。這使得可以訪問結(jié)果和對象瀏覽器。VBScript ( Visual Basic 腳本)是一個 VBA的子集。簡單的語言解釋基本法可以調(diào)用CATIA對象。沒有類型被使用。系統(tǒng)動態(tài)地嘗試調(diào)用方法和對象的屬性。(后期綁定通過他們的I Dispatch接口調(diào)用對象)。支持的語言CATI A 支持的語言是:CATScript :它是在V5的腳本語言,直到包容V5R7。從V5R8,它變得過時,并建議使用MS VBScript 或MS VBA 。MS VBScript:它是從V5R8首先使用的語言,唯一的解決方案是允許有一個在NT和 UNIX可移植的腳本。MS - VBScript 不同于 CATScript 的是,這個概念在模糊地聲明一個X變量為Y不存在。MS - VBA:VBA是一個集成到CATIA和專用于VB的開發(fā)環(huán)境,但只在NT上。 MS- VBA不同于 MS- VBScript 的是編程的舒適性和實現(xiàn)簡單圖形界面的應(yīng)用可能性。面板Activex可以加入一個宏,但是只在NT 上。如“ Scripting. FileSystemObject “ 的其他服務(wù)被稱為“ CreateObject “ ,并只在NT中可用。對象類型的聲明記錄在宏里(即使它不是在 VBScr i pt 中使用),但它可以幫助你(在VB中與在NT上填寫)計劃你未來的應(yīng)用。CATIA V5的文件擴(kuò)展名鏈接在 CATIA V5 中雙擊打開 Windows 資源管理器的“ CATPar t “ 文件。在 NT 上,如果沒有運行CATIA V5,它會自動啟動。CATIA V5的腳本功能在過程中的應(yīng)用:這是在CATIA菜單的工具+宏中進(jìn)行。當(dāng)宏運行時,CATIA停用。你不能在兩個調(diào)用間存儲一個宏變量。使用 VBScript(微軟)和 VBA訪問 Windows NT 和使用VBScript(Wi nsoft)訪問Unix。輸出過程中的應(yīng)用(僅限NT)這基于自動化。一個外部過程可以調(diào)用 CATIA,創(chuàng)建或修改幾何,解碼,測量或試驗CATIA。CATI A仍然運行。對于應(yīng)用程序的每個動作,我們要檢查是否 CATIA在良好的狀態(tài)同步兩個進(jìn)程。這種應(yīng)用可以被發(fā)展在:Visual Basic Windows Scripting Host ( VBScript , JScript ) , Windows ExplorerHTML( VBScript,JScript )或者任何其他COM應(yīng)用。在將來,V5自動化對象的Java封裝也將被提供。這將促使在 NT和基于 Java 的 Unix上應(yīng)用軟件的開發(fā),無論是在輸入進(jìn)程和輸出進(jìn)程。宏進(jìn)程我們在加工過程中調(diào)用它,因為該腳本的解釋在與 CATIA相同的過程里行。一個列表顯示了可用的宏。我們可以運行,編輯,重命名或刪除現(xiàn)有的腳本,或創(chuàng)建一個新的。上述小組建議的腳本庫的列表是可以通過對庫的一個窗口進(jìn)行修改的。利用CATIA的Visual Basic 編輯器,我們可以編輯現(xiàn)有的宏或創(chuàng)建一個新的,插入圖形形式,調(diào)試和運行VBA項目。對話框的界面“ 工具+宏+宏. . . “ 允許選擇一個宏(一個宏目錄或一個 VBA項目)或一個我們希望工作的文檔庫上。從這個窗口,我們可以關(guān)閉已打開的庫,開放一個庫,或建立一個庫。庫是按類型顯示(目錄,VBA項目)。每庫類型支持不同的語言。VBA 只支持語言 MS - VBA,當(dāng)在一個目錄里時,而在目錄中,我們可以寫在MS- VBScr i pt 或在CATScr i pt。錄制宏該記錄的VBA面板允許我們選擇將記錄的容器,使用的語言和宏的名字被記錄。 所錄制的腳本的語法是要根據(jù)不同的菜單中選擇。錄制宏生成一個對應(yīng)創(chuàng)建或修改對象的腳本再記錄序列里。停止錄音后,我們可以存儲,編輯重放這個腳本(稱為宏)。作為一項規(guī)則,記錄一個宏可以幫助你學(xué)習(xí)如何編程的東西。運行宏CATIA 一啟動 , 你就能執(zhí)行宏 : CNEXT - macroE: Users Macros MacroToRun. CATScript。你可以在批處理模式下啟動宏來執(zhí)行 CATIA:CNEXT - batch - macro E: User s Macr os Macr oToRu
收藏