Vb scripting for catia v5 pdf download




















Create a new part In the part design workbench, draw a sketch of a square on any plane Pad the sketch to any length Under Geometrical Set 1, create an offset plane and a datum explicit plane. Run the code again and the message box should appear.

The first goal is to add code that will count the number of sketch-based-features. These feature objects are all different kinds of shapes". Click on the red arrow next to the Shape box to see a more detailed view of Shape objects. We want to count the number of SketchBasedShape objects that are in the part. Item 1 grabs the Shapes collection underneath the first part body. If Err. Run the code, you should see End If this message box: Err. Item 1 the For Next loop. Shapes Note the Item 1 in the code.

Item i If Err. Return to the part document object diagram of the. Note that the Part object has a collection called HybridBodies. This is a collection of all the geometrical sets of the part, but the programmatic name of a geometrical set is HybridBody.

We want to add code to count the number of datum planes. A datum plane is a hybrid shape, but we dont know for sure what its programmatic name is. Click on the red arrow indicated below to go to the object diagram for the HybridShape object. We are looking for a class that is the equivalent of a datum plane. The class HybridShapePlaneExplicit looks like the right one. Insert the following code below what we already have. You should get the resulting message box.

HybridBodies End If Err. Navigate the structure of a CATIA part document by iterating through the various collections that a part contains. Access the Shapes collection under a part Body object in order to iterate through features of the part. Description In this workshop you will explore the creation of sketch geometry in a part document.

The purpose of this is to illustrate the use of factories to create objects in a part document. Modify the macro to create additional geometry and rerun it on a new part document. Start the sketch. The resulting should similar to what is pictured to the right.

It is important that there are no constraints in the sketch that was created. A good first step after recording a macro is to add comments to clearly call-out the sequence of stages of the code. To start, add the comments seen below to call-out the first step, which is the getting of the part body.

ActiveDocument Add this End command here. Part when it is run. Bodies Open a new part document and run Dim body1 As Body the macro. Item "PartBody" that a new sketch is created. Sketches containing two parts:. Dim originElements1 As OriginElements 1. OriginElements 2.

The calling of the SetAbsoluteAxisData method. Add reference1 positioned in 3D space. Leave this command as-is. GeometricElements only used to get this Axis2D object. Item "AbsoluteAxis" with a more direct approach.

GetItem "HDirection" into one two lines replace the original four. Item "AbsoluteAxis". CreatePoint 60 , point2D2. GetItem "HDirection" line2D1. GetItem "VDirection" next slide for tips on how to line2D2. CreatePoint 20 , point2D1. CreatePoint 60 , and line2D2 were created, point2D2.

CreateLine 20 , , 60 , properties set. If we determine that the setting of these values line2D3. CloseEdition part1. The programming object in question is the class Line2D. Right-click on ReportName and select Help.

On the documentation page that comes up, note that Geometry2D is the class. The description of the ReportName property doesnt tell us much. For one, it only states that this property returns the report name, but we can see in the recorded macro that it sets the report name. For now, although the macro does use this property to set these report name values, assume that this is an unnecessary step, and remove these lines of code.

OpenEdition same coordinates of the points. CreatePoint 20 , were created. CreateLine 20 , , 60 , point2D1 could be named line2D3. CloseEdition These couple lines of code now part1.

Update End Sub removed. How to edit a recorded macro by using comments, by renaming variables, and by deleting unnecessary lines, for the purpose of increasing clarity and simplicity in the code. How to use the object browser and help documentation to investigate unknown API properties and methods.

Note that a code window appears. There are two drop-down menus, one that shows which objects code you are looking at, the other showing the event subroutine you are editing. As a quick experiment, enter the command featured to the right in this Click sub. Run this new macro using the Run button. Click on the form with your mouse and a message box should appear displaying hello.

As you can see, the form recognizes the click event and it runs the code each time you click it. Close the form by using the x button in the top right corner. Click the View Code button to view the code of the form. Note that in the drop-down menu on the left, there are now two objects to select from UserForm and TextBox1. Each of these objects as its own set of events that can be chosen from the drop-down menu on the right.

Edit the Text property of the TextBox to be 0 zero. This will set the TextBox so that its default text that it contains is 0. Note that in the edited code above, tbPointA is an object whose Text property is being accessed. Text form is clicked. End Sub. Click on the form to trigger its Click event. Note that the message box displays the content of the text box. Edit the content of the TextBox and click on the form again. Note that the value that gets displayed again matches the content of the TextBox.

Drag and drop the objects pictured below onto the form. Edit their properties as indicated. Label Label Label TextBox. The code window will come up with various subroutines visible. Also, note that because the cursor is positioned in this subroutine, the object and event that are shown in the drop-down menus match this.

Rather than redevelop code that creates a line in a sketch, well just cut and paste the code previously developed into the Click event of this form. Edit the Pasted CodeStep The goal is to edit the code that has been pasted so that when the Create Line button is clicked, a line gets created whose start point has the coordinates of Point A and whose end point has the coordinates of Point B.

The arrows below show the correspondence between the fields of the form and the parameters of the methods that are called in the code. CreatePoint 20 , CreatePoint 60 , CreateLine 20 , , 60 , Edit the Pasted CodeStep cont. The following replacements need to be made. Note that previously, numerical values were hard coded in as parameters to the CreatePoint methods.

Now we are replacing them with the properties of form objects, in this case the Text property of the various TextBox objects that are on the form. CreatePoint tbPointAx. Text, tbPointAy. Text part1. CreatePoint tbPointBx. Text, tbPointBy. Text sketch1. CreateLine tbPointAx. CreateLine 20 , , 60 , tbPointBx. Create a sketch using the form. Click the Create Line button and you will see that a sketch appears containing a line whose coordinates match those that are in the form TextBox objects.

However, the form remains open, and if you attempt to interact with CATIA you are unable because the form has been shown in what is called modal mode. It would be nice to change this so that after a sketch is created, you could zoom in or rotate, expand the spec tree, etc.

Note that an argument vbModeless will be passed to the Show subroutine that is called on the form. Change point coordinate values on the form and hit the Create Line button to create another sketch. Add form objects to the form such as TextBox objects, Label objects, and CommandButton objects, edit their properties, and insert code into their events as well.

Reference the properties of form objects for use in code. For instance, you used the Text properties of the TextBox objects that were created on the form. Open navigation menu. Close suggestions Search Search.

User Settings. Skip carousel. Carousel Previous. Carousel Next. What is Scribd? Explore Ebooks. Bestsellers Editors' Picks All Ebooks. Explore Audiobooks. Bestsellers Editors' Picks All audiobooks. Explore Magazines. Editors' Picks All magazines. Explore Podcasts All podcasts. Difficulty Beginner Intermediate Advanced.

Explore Documents. Uploaded by Tomas Lopez. Did you find this document useful? Is this content inappropriate?

Report this Document. Flag for inappropriate content. Download now. Related titles. Carousel Previous Carousel Next. Jump to Page. Search inside document. Cover and book design by Nick Weisenberger. Disclaimer Although the author has attempted to exhaustively research all sources to ensure the accuracy and completeness of information on the subject matter, the author assumes no responsibility for errors, inaccuracies, omissions, or any other inconsistencies herein.

What is a Macro and why do we use them? What is VB script? How to Create Macros Macros are created by two primary methods: 1. Macro recorder 2. Click "Macro libraries" 3. Make sure the Library type is set to "Directories" then click "Add existing library" 4. Use the Macros toolbar 3. Create your own icon for each macro If the macro editor cannot be opened you should talk to your system administrator because it probably has not been installed.

How to Record a Macro One method for creating macros is by recording your mouse actions. A few things to keep in mind when recording a macro: 1. Viewpoint3D Notice how the Set Viewpoint command appears multiple times? VB Script Syntax Syntax is defined as the ordering of and relationship between the words and other structural elements in phrases and sentences. Here are some of the key features of VB Scripts syntax: Indentation: Indent or out dent script to reflect the logical structure and nesting of the statements.

Naming: Avoid naming conflicts. Two variables cannot have the same name. Selection If nothing is selected then the selection is empty. Selection oSel. Clear oSel. Add ObjectToAdd A good practice is to always clear the selection before and after you use it. Count Msgbox oSel. Item i. Name Next i You can search through selections by several different methods, including searching by name, type, color, etc. VisProperties gets the color VisProps.

GetRealColor ,0,0 sets the color visProps. SetRealColor ,0,0,1 VisProps. It controls items such as: Are the parts shaded, wireframe, etc? Everything in this collection has to do with HOW the data is seen. Subroutines and Functions Subroutines and functions are good for encapsulating code that needs to be called repeatedly. Save The Save As method takes a string as an argument but returns nothing. ActiveDocument doc1. GetWorkbench Structural Work with Collections: Count and Item Collections are special kinds of objects that hold a list of objects of a certain class.

ActiveViewer Next, we need to access one of the Camera objects from the current document. So, to change the view of a document we need to set the 3DViewer viewpoint to the Camera viewpoint: objViewer3D. ActiveViewer Translating the view objViewer. Translate translationVector Rotating the view: objViewer. NewCamera To reframe a window objViewer. Reframe To Zoom In objViewer.

ActiveDocument MsgBox pdoc1. FullName End Sub The program would stop at the third line of the above code. FullName The behavior of the program can be made even more intelligent by using the Err object, which is an object that exists in every VBA program. ActiveDocument If Err. Clear Proceed with the error number cleared Err.

CreateDimension Name,Length, Use this code to change the background color to white: This array holds the original ReDim dblBackArray 2 background color objViewer3D.

ShapeFactory Where Argument 1 is a sketch and I means input. The Pad object must be declared. Path End Sub User Forms A great way to enhance the experience for your end users and one of the most important features of Visual Basic programs is by creating userforms. Products Products1. BMP 2. TIFF 3. CGM 4. EMF 5. Application" If Err. Application" Else Err. Cells 2, First, select a cell in the spreadsheet and then specify if you want to insert a row above it as in these examples: 'insert a row at the top for headers Excel.

Cells 1,1. Select Excel. Insert 'Insert column to the left of the active cell Excel. Insert 'Insert column to the right of the active cell Excel. Cells 1,8.

Offset 0, 1. Range "A:G". Rows 2. Delete 'delete sorter column G Excel. Columns 7. Delete Formatting Excel After all the formulas and sorting on the spreadsheet is complete, then its time to format to get it the way you want it to look.

Some formatting examples: 'Select range to format Excel. Rows "". Select 'change font to bold Excel. With Excel. Autofit End With 'merge cells in selected range Excel. Range "Z1:AA1". Merge 'wrap text within selected range Excel. Range "W3","AA3". Borders xlDiagonalDown. Borders xlDiagonalUp.

Select With Excel. Slide oPPT. Add 1, 1 objSlide. Shapes 1. Shapes 2. AddPicture strName, False, True, 50, 5, , Adding headers and footer automatically to your presentation is very easy. Use this code to lock the aspect ratio for all the pictures as you insert them: Pic. Some examples: Sleep insert a delay into the VB application Killing processes like CNEXT to instantly stop CATIA Checking for processes to see if something is running Complete Macro Examples Its always a good idea to add some notes at the beginning of your code indentifying who wrote or modified the code, when the last revision was made, what the code actually is supposed to do, etc.

Parent If Err. Name Else Msgbox "You must select an object to return the parent name. Viewpoint3D 'reframe objViewer3D. Reframe 'zoom in objViewer3D. ZoomIn 'objViewer3D. Clear 'increase to fullscreen to obtain maximum resolution objViewer3D. ActiveViewer partDocument1. Part If Err. Item i oCapture. James January 20, Reply. It would nice if one of your payment methods was PayPal. Emmett Ross February 3, Reply.

Emmett Ross June 3, Reply. Kevin Barker January 22, Reply. Anarkia November 5, Reply. Emmett Ross November 8, Reply. Add a Comment Cancel reply Your email address will not be published. This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Close Privacy Overview This website uses cookies to improve your experience while you navigate through the website.

Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience. Necessary Necessary.

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. The purpose of this text is to show beginners how they can approach different problems and for users to rewrite code shown in the examples to suite their specific needs. It contains the fundamental knowledge that is required for macro programming. VB scripting of CATIA V5 does not allow the identification and selection of individual faces for a solid body , and as such it is impossible to identify which face is to be projected onto the reduced dimensional element.



0コメント

  • 1000 / 1000