Author Topic: To use macro processing large amounts of data in CATIA  (Read 655 times)

nowcad

  • Administrator
  • Hero Member
  • *****
  • Posts: 1864
    • View Profile
    • NowCAD
To use macro processing large amounts of data in CATIA
« on: August 23, 2012, 01:40:26 pm »
From: http://www.opoqo.net/bbs/read.php?tid-41422-fpage-2.html
I. Introduction
With the continuous development of mechanical design. 3D-aided design software to become an important and indispensable tool in product design and processing. Worldwide CATIA has a super free-form surface features. Reverse engineering functions and comprehensive portfolio analysis function. a wide range of applications within the aerospace and automobile industries in the aircraft design process. aircraft shape modeling process often start with the external read into the shape data and the processing of these data in CATIA aircraft shape data usually by many point coordinates. appearance is the more accurate data requirements more the input point usually Point in Shape Generative Shape Design interface command bar manually input data in CATIA. aircraft shape successful 1000 tens of thousands of data points. manually enter not only time-consuming and error-prone. This article describes the method of using macro commands to automatically read data, and these data is automatically related to graphics processing.
Macro definition II.
A macro is a series of commands and instructions grouped together to achieve the implementation of the automation of multi-tasking.
The macro can be written in the following several scripting languages. Depending on the operating system:
☆ Basicscript 2.2 sdk. Unix;
☆ Vbscript.Visual Basic scripting language for Windows NT system;
☆ Jscript.Javascript an application for Windows NT system.
Create macros and run the macro
1 Create a macro
The macro can be used for a variety of software in various software to create and run basic similarity. Highlights macro create and run the process in CATIA.
The creation process is: First open CATIA to create a new file and then enter the menu Tools open the submenu Macro Macros (or Alt F8 command). Opens a window as shown in Figure 1.
Figure 1 macro command to open the window
Named after the name of a macro in the Macro Name input box. Macro1 in then press Creat button opens the Macro Editor window. Text box, enter the macro code in this window to save the macro created shown in Figure 2.
Figure 2 create macros
2. Run a macro
First select the macro. Because macros can be stored in internal documents can be saved to an external file. So, the first in the macro window in the lower left corner of the drop-down box, select the internal file or an external file. Internal documents. Macro window text box displays has created a series of macros to select the desired macro. pressing the Run button. macros results can be displayed in the window if the external file. choose the Select button on the left side of the macro window Select the macro where file directory, press the Run button. equally. macros results displayed in the window.
Macro in CATIA
1. With macro input data
Macro in CATIA. Well integrated with CATIA kernel function calls within a part to play a series of holes. Extracted from the assembly bill of materials, and so on. Practical work aircraft shape data stored in Excel files. use macros to read the data in the Excel file. If the data is saved in other file formats, such as the dat file format can be converted to an Excel file format., or change the code directly from other files directly read the code as follows:
Language = "VBscript" because of the operating systems is windows2000 this macro is written in vbscript the
Sub CATMain ()
Dim partDocument1 As Document to create a file
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part create components
Set part1 = partDocument1.Part
dim excel as object call the excel object
set Excel = getobject, ("d: shape data xls) aircraft shape data stored in d: profile data. xls files
By cyclic reads excel data this data for aircraft shape on the coordinates of the point value and these values ​​are stored in BCD in excel form. These values ​​were assigned to the variable xyz
i = 1
do while x <> ""
x = excel.worksheets (1). cells.range ("B" & trim (cstr (i))). value
y = excel.worksheets (1). cells.range ("C" & trim (cstr (i))). value
z = excel.worksheets (1). cells.range ("D" & trim (cstr (i))). value
·
·
·
Defining point coordinates
Dim hybridShapePointCoord1 As HybridShapePointCoord
Set hybridShapePointCoord1 = hybridShapeFactory1.AddNewPointCoord (x, y, z)
·
·
·
Input points
hybridBody1.AppendHybridShape hybridShapePointCoord1
part1.InWorkObject = hybridShapePointCoord1
i = i 1
loop
part1.Update
End sub
In accordance with the steps to create and run macros. Enter the above code to a custom macro code area. Saved and run, so the profile data. Xls file all aircraft shape data are read out. CATIA system for automatic numbering of these points. designers from the left side of the interface is the most under to see all the points in an Open the Body.1 tree extensions directory.
Figure 3 is a point on the wing with this macro input save the CATIA file is jiyi.CATpart.

Figure 3 macro input data
2. Use of macros processing data
In order to get the shape of the aircraft. Need for processing the input point that these points together into certain spline curves Spline command processing these spline curve in this task. Connected into the point The line is an onerous repetitive tasks with macros can be done automatically. macro code is as follows:
Language = "VBscript"
Sub CATMain ()
Macro initialization
Dim documents1 As Documents
Set documents1 = CATIA.Documents
Dim partDocument1 As Document
Set partDocument1 = documents1.Item ("Part1.CATPart")
·
·
·
According to the requirements of aircraft shape. Settings of two nested loops. Inner loop to complete a spline point to point connection. Complete multiple spline curve connecting the outer loop.
dim j as integer
for j = 1 to const1
Spline curve defined and set
Dim hybridShapeSpline1 As HybridShapeSpline
Set hybridShapeSpline1 = hybridShapeFactory1.AddNewSpline ()
hybridShapeSpline1.SetSplineType 0
hybridShapeSpline1.SetClosing 1
·
·
·
dim i as integer
for i = 1 to const2
Dim hybridShapePointCoord1 As HybridShape
Set hybridShapePointCoord1 = hybridShapes1.Item (i const2 * (j-1))
·
·
·
hybridShapeSpline1.AddControlPoint hybridShapeControlPoint1
next
hybridBody1.AppendHybridShape hybridShapeSpline1
part1.InWorkObject = hybridShapeSpline1
part1.Update
next
part1.Update
End Sub
Same. According to create and run macros steps. Above code is input to another macro code custom save and run the results shown in Figure 4.

Figure 4 macro data processing
V. Conclusion
CATIA macros in aviation design introduced above. CATIA can be used to interact with the outside world data larger than in other areas such as the automotive sector. Macros can be used to accelerate the product development cycle. Improve work efficiency. With CATIA function continuously enhanced, and a constantly expanding range of applications in CATIA. macros as an essential auxiliary function will continue to expand the functionality of CATIA experience on a new blog: Body Cla A surface model constructed: Catia Some tips