SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
Getting Started with
CATIA V5 Macros
Emmett Ross
January 2015
http://www.scripting4v5.com
Why use macros?
If you perform a task repeatedly, you can take
advantage of a macro to automate it. A macro is a
series of functions, written in a scripting language,
that you group in a single command to perform the
requested task automatically, saving time and
reducing the possibility of human error.
• Standardization
• Improve efficiency
• Expand CATIA capabilities
• Streamline tasks
Macro Examples
3
• The application of automation in the design process is virtually
unlimited.
• Examples of macros that CAD engineers might use:
– Generate Part List in Excel from CATIA
– Automatically place components at specific points
– Compare differences between two parts
– Print annotation data
– Take a screen capture
– Delete deactivated features
– Create a drawing
– Find specific geometry
– Change background color to white
And so on and so on. The possibilities are nearly limitless.
CATIA V5 Macros
• Macros run from CATIA V5
• Written in VBA
4
1/12/2015
Macros are created by two primary methods:
1. Macro recorder
2. Write custom code with the macro editor
How to create a macro
MACRO RECORDER
• One method for creating macros is by recording your mouse actions
by:
• Going to Tools>Macro>Macros>Start Recording
• Choose CATScript, enter a name then click OK.
• CATIA is now recording your actions until you click the stop button
• DON'T: Record more than is absolutely necessary.
• DON'T: Use the UNDO button when recording a macro.
• DO: Check each macro after it's recorded.
• To view the code that was just recorded go to
Tools>Macro>Macros> Select the macro then click Step Into to
launch the macro editor.
CONS OF MACRO RECORDING
• Many times extra lines of code are added which are not
necessary. This is based on the order of steps that you do as
you record the macro. These unnecessary lines can be
removed.
• Recorded macros do not contain any comments or
explanations of what is happening in the code and input
parameters are never recorded.
• Recorded macros are very simple and don’t contain If
statements, Loops, or other commonly used code.
• Record macros can be used for simple tasks but it is better
to write custom code; use the recorder if you get stuck or
to find out the syntax if you don’t know it.
To open and run macros
There are multiple ways to open the macros window:
• Tools>Macro>Macros
• Macros toolbar
• Keyboard shortcut: Alt+F8
• Create your own icon for each macro
Macro Libraries
• CATIA macros are stored in macro libraries in one
of three locations: Folders (vbscript and
CATScript), Project files (catvba), or documents
such as CATParts, CATProducts, and CATDrawings.
• Only one of these macro libraries can be used at
a time.
• When creating a new macro library, the folder or
path location must already exist. If not you will
get an error message.
How to add a macro library
• Use the following steps to setup an existing
macro library
•Go to Tools>Macro>Macros
•Click "Macro libraries…"
Ensure the Library type is set to "Directories"
then click "Create new library…"
Type in the file location where you are planning on saving all of your
CATIA macros then click OK.
Close the macros libraries window.
This is where you can create CATScript
macros.
If you were setting up an existing library
(add existing library versus Create new
library) you would see a list of .CATScript
files here.
You only need to do this once as the library
should load even after restarting CATIA.
PROGRAMMING LANGUAGE
• To write custom macros you need to know CATIA’s
programming language, Visual Basic for Applications.
• VBA provides a complete programming environment with
an editor, debugger, and help object viewer.
• CATIA cannot run a macro program WITHOUT the host
application (CATIA) running (meaning it runs as a DLL in the
same memory space as the host application).
• CATIA macros are run in-process, meaning CATIA essentially
freezes while the macro is running and the allocation
memory is wiped clean after each run of the program so
passing data between subsequent runs is impossible.
What is CATScript?
VBScript is a subset of the Visual Basic Programming
language (VBA).
All elements of VBScript are present in VBA, but some
VBA elements are not implemented in VBScript.
The result of the slimming down process is a very small
language that is easy to use.
Code specific to CATIA is saved as .CATScript.
Can edit code in macro editor or notepad/word pad, etc.
151/12/2015
MACRO SYNTAX
• Syntax is defined as the ordering of and relationship
between the words and other structural elements in
phrases and sentences.
• Each programming language is composed of its own syntax.
• Think of it like this: when you see an email address
(emmett@scripting4v5.com) you immediately identify it as
an email address. Why is this? An email address has a
correct structure in the language of the internet, its syntax.
• Syntax enables the programming language to understand
what it is you are trying to do
SYNTAX
• Case Sensitivity: By default, VBA is not case sensitive and does not
differentiate between upper-case and lower-case spelling of words.
• Comments: Add comments to your statements using an apostrophe
('), either at the beginning of a separate line, or at the end of a
statement. It is recommended that you add comments wherever
possible to make your scripts easier to understand and maintain,
especially if another user has to make changes to it later on down
the road.
• Indentation: Indent or out dent script to reflect the logical structure
and nesting of the statements to make it easier to read.
• Parentheses: It is important to use parentheses correctly in any
statement to achieve the desired result and to avoid errors.
SYNTAX
• Semicolon (:): Inserting a semicolon allows you to write multiple
commands on the same line of code.
• Single Quotation(‘): To return a single quotation mark which does
not indicate a comment (needed in a formula for example), you'll
have to use the Chr function. Chr() is a built-in VBA function that
returns the character that corresponds to the numeric value of its
argument using the ASCII coding scheme. If you provide Chr with an
integer value (such as 39) it will report back the character that
corresponds to that value. The ASCII value of 39 is the single quote
mark. Chr(34) is for the double quote mark
• Spaces: Add extra blank spaces to your script to improve clarity.
These spaces are ignored by VBA.
SYNTAX
• Text Strings: When a value is entered as a text string you
must add quotation marks before and after the string.
• You can concatenate, or combine, multiple strings using a
plus (+) or ampersand (&) sign: txtString = “This value is “+
TestValue. Return the left, middle, or right of a string using:
left(sting, digits), mid(string, digits), or right(string, digits).
Get the complete length of a string with len(string). To
figure out if a string contains another string use Instr().
Convert numeric strings and vice versa using str(num) or
val(string).
• Underscore(_): Carry over to next line (line concatenation
symbol).
SEQUENTIAL PROGRAMMING
• When you run your macro program, the code will be
read by the computer line by line, generally from top to
bottom and from left to right, just like reading a book.
• The program flows down the code until it hits a
decision point where it may have to jump to a different
portion of the program or re-run lines of code that it
already read.
• The program chooses what lines of code to execute
based on the state of the variables you have defined.
EVENT DRIVEN PROGRAMMING
• The execution of the program depends on an
event, such as a user clicking a button with the
mouse, an object being selected, certain text or
characters being typed into a form, etc.
• One common decision point is an If...Else
statement. If the variable equals x then do y, else
do z.
• Another one is the while loop which will execute
the lines of code within the loop over and over
until the condition becomes false.
VARIABLES
• Variables make up the backbone of any programming
language.
• Variables store information that can be accessed later
by referring to a name or “variable.”
• Variables can then be declared as a type to let us know
what we can do with that information.
• The value of a variable will not necessarily be constant
throughout the duration a program is running.
• Naming variables is important; it’s best to be
descriptive i.e. RowNumber, ColumnNumber
VARIABLES
• Variable names, also known as identifiers, must be less
than 255 characters
• They cannot start with a number.
• Special characters such as spaces and periods are
forbidden.
• Avoid naming conflicts; two variables cannot have the same
name.
Example:
• Good Variable Names: dimensionOne, dimension1
• Bad Variable Names: dimension One, 1dimension
VARIABLES NOTATION
• There is a popular naming convention where a letter is placed in
front of the variable name to notate what type of data the variable
is:
• o=object (i.e. oPartDoc)
• s=selection (i.e sSelection1)
• str=string (i.e. strFilename)
• i=integer (i.e iCount)
• rng=Range (i.e. rngField)
• Some programmers use “int” or “n” for integer and “str” for string.
Either or works as long as your notation is consistent and easy for
others to understand.
• By default, Excel doesn’t force you to declare
your variables. However, you should change that
setting immediately. Press Alt+F11 to launch the
Visual Basic Editor (VBE). Go to Tools>Options.
• In the Editor tab of the Options dialog, make sure
that there’s a check mark in front of “Require
Variable Declaration”
DIMMING AND SETTING
• Variables are "dimmed" (declared) as a type, either a "primitive"
type (single, double, integer, string, etc.) or an object type (more
complex).
• The "Dim" command is used to allocate a variable of any type.
Primitive variables are populated with a value. Declaring variables
with a ‘Dim’ statement helps save memory while running the
program .
• After a variable is declared through dimming then it is “Set” or
given a value.
• For object variables, the "Set" command is used to "point" the
variable to the object. Within the program, the variable then
represents that object unless it is "Set" to a different one.
MACRO BASICS
• An CATIA program or "macro" consists of a
"Subroutine“.
• CATIA only recognizes the Sub ___() as the entry
point to any VBA application.
• Every Sub must end with an End Sub.
• You’ll add your code in-between the subs
CREATE A MSGBOX MACRO
• To create your first custom macro:
• Use the shortcut Alt+F8
• Type in a new macro name “Test”
• Click “Create” to launch the macro editor
• Add the following code between the subs:
• Msgbox “Hello world.”
• Click the play button and a message box with the words “Hello world.”
should pop up in front of your spreadsheet.
Option Explicit
Sub Main()
MsgBox “Hello world.”
End Sub
To create an icon for each macro:
• Go to Tools>Customize>Commands tab> scroll
down to Macros>click "Show Properties"
• Under Commands, select the macro then click the …
box. The icon browser pops up. Over 6000 to
choose from. Select one then hit close.
• Finally, drag and drop the .CATScript file from the
command window to whatever toolbar you would
like the icon to appear on
• Now you can click the Icon to run your macro!
• You can also setup a custom keyboard shortcut as
well.
CATIA Version Macro
This macro displays the current CATIA version and service pack number
Sub CATMain()
'---display the current CATIA version, R number and service pack
MsgBox "The current CATIA configuration is: V" & CATIA.SystemConfiguration.Version & _
"R" & CATIA.SystemConfiguration.Release & _
"(SP" & CATIA.SystemConfiguration.ServicePack & ")"
'---check to see if the specified product is authorized
If CATIA.SystemConfiguration.IsProductAuthorized("FPE.prd") THEN
MsgBox "FPE authorized."
Else
MsgBox "FPE Not Authorized"
End If
End Sub
Want to learn EVEN MORE about
programming macros in CATIA V5?
Join the newsletter VB Scripting for CATIA V5
email newsletter for more macros tips
delivered to your inbox.
CLICK HERE TO SIGNUP FOR FREE!
As a bonus you’ll receive the 7 Tools I Use
When Programming CATIA Macros

Mais conteúdo relacionado

Mais procurados

Catia v5 presentation report
Catia v5 presentation reportCatia v5 presentation report
Catia v5 presentation reportMunna Kumar
 
Computer integrated production planning
Computer integrated production planningComputer integrated production planning
Computer integrated production planningVenu Yadav
 
Creo parametric tips and tricks
Creo parametric tips and tricksCreo parametric tips and tricks
Creo parametric tips and tricksEvan Winter
 
Creo 3.0 tips and tricks r4
Creo 3.0 tips and tricks r4Creo 3.0 tips and tricks r4
Creo 3.0 tips and tricks r4Evan Winter
 
MECH CREO
MECH CREOMECH CREO
MECH CREONaren R
 
tolerance stack up analysis
tolerance stack up analysistolerance stack up analysis
tolerance stack up analysisbaggiojoset
 
Design for Manufacturing Guidelines, issue IV, Milling Design Guidelines
Design for Manufacturing Guidelines, issue IV, Milling Design GuidelinesDesign for Manufacturing Guidelines, issue IV, Milling Design Guidelines
Design for Manufacturing Guidelines, issue IV, Milling Design GuidelinesDFMPro
 
C Programming: Structure and Union
C Programming: Structure and UnionC Programming: Structure and Union
C Programming: Structure and UnionSelvaraj Seerangan
 
Machining fundamentals
Machining fundamentalsMachining fundamentals
Machining fundamentalsendika55
 

Mais procurados (20)

CATIA LESSON 1
CATIA LESSON 1CATIA LESSON 1
CATIA LESSON 1
 
Catia5v
Catia5vCatia5v
Catia5v
 
Catia v5 NOTES
Catia v5  NOTESCatia v5  NOTES
Catia v5 NOTES
 
Learn Excel Macro
Learn Excel Macro  Learn Excel Macro
Learn Excel Macro
 
Catia v5 presentation report
Catia v5 presentation reportCatia v5 presentation report
Catia v5 presentation report
 
Catia
Catia Catia
Catia
 
Jigs and fixtures imp
Jigs and fixtures impJigs and fixtures imp
Jigs and fixtures imp
 
Computer integrated production planning
Computer integrated production planningComputer integrated production planning
Computer integrated production planning
 
Creo parametric tips and tricks
Creo parametric tips and tricksCreo parametric tips and tricks
Creo parametric tips and tricks
 
Creo 3.0 tips and tricks r4
Creo 3.0 tips and tricks r4Creo 3.0 tips and tricks r4
Creo 3.0 tips and tricks r4
 
Centrifugal casting 1
Centrifugal casting 1Centrifugal casting 1
Centrifugal casting 1
 
MECH CREO
MECH CREOMECH CREO
MECH CREO
 
tolerance stack up analysis
tolerance stack up analysistolerance stack up analysis
tolerance stack up analysis
 
Design for Manufacturing Guidelines, issue IV, Milling Design Guidelines
Design for Manufacturing Guidelines, issue IV, Milling Design GuidelinesDesign for Manufacturing Guidelines, issue IV, Milling Design Guidelines
Design for Manufacturing Guidelines, issue IV, Milling Design Guidelines
 
Ppt on catia
Ppt on  catiaPpt on  catia
Ppt on catia
 
Auto cad
Auto cadAuto cad
Auto cad
 
Dfma ppt
Dfma pptDfma ppt
Dfma ppt
 
C Programming: Structure and Union
C Programming: Structure and UnionC Programming: Structure and Union
C Programming: Structure and Union
 
Machining fundamentals
Machining fundamentalsMachining fundamentals
Machining fundamentals
 
Vba
Vba Vba
Vba
 

Semelhante a Getting started with CATIA V5 Macros

Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosNick Weisenberger
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesInductive Automation
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesInductive Automation
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming WebStackAcademy
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
 
What's a macro?: Learning by Examples
What's a macro?: Learning by ExamplesWhat's a macro?: Learning by Examples
What's a macro?: Learning by Exampleschibochibo
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3Vijay Perepa
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...AboutYouGmbH
 
Intermediate Representation in Compiler Construction
Intermediate Representation in Compiler ConstructionIntermediate Representation in Compiler Construction
Intermediate Representation in Compiler Constructiontheizm1
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageAzilen Technologies Pvt. Ltd.
 

Semelhante a Getting started with CATIA V5 Macros (20)

Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel Macros
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
What's a macro?: Learning by Examples
What's a macro?: Learning by ExamplesWhat's a macro?: Learning by Examples
What's a macro?: Learning by Examples
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
C question
C questionC question
C question
 
Intermediate Representation in Compiler Construction
Intermediate Representation in Compiler ConstructionIntermediate Representation in Compiler Construction
Intermediate Representation in Compiler Construction
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Macro-processor
Macro-processorMacro-processor
Macro-processor
 

Último

VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 

Último (20)

VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 

Getting started with CATIA V5 Macros

  • 1. Getting Started with CATIA V5 Macros Emmett Ross January 2015 http://www.scripting4v5.com
  • 2. Why use macros? If you perform a task repeatedly, you can take advantage of a macro to automate it. A macro is a series of functions, written in a scripting language, that you group in a single command to perform the requested task automatically, saving time and reducing the possibility of human error. • Standardization • Improve efficiency • Expand CATIA capabilities • Streamline tasks
  • 3. Macro Examples 3 • The application of automation in the design process is virtually unlimited. • Examples of macros that CAD engineers might use: – Generate Part List in Excel from CATIA – Automatically place components at specific points – Compare differences between two parts – Print annotation data – Take a screen capture – Delete deactivated features – Create a drawing – Find specific geometry – Change background color to white And so on and so on. The possibilities are nearly limitless.
  • 4. CATIA V5 Macros • Macros run from CATIA V5 • Written in VBA 4 1/12/2015 Macros are created by two primary methods: 1. Macro recorder 2. Write custom code with the macro editor How to create a macro
  • 5. MACRO RECORDER • One method for creating macros is by recording your mouse actions by: • Going to Tools>Macro>Macros>Start Recording • Choose CATScript, enter a name then click OK. • CATIA is now recording your actions until you click the stop button • DON'T: Record more than is absolutely necessary. • DON'T: Use the UNDO button when recording a macro. • DO: Check each macro after it's recorded. • To view the code that was just recorded go to Tools>Macro>Macros> Select the macro then click Step Into to launch the macro editor.
  • 6. CONS OF MACRO RECORDING • Many times extra lines of code are added which are not necessary. This is based on the order of steps that you do as you record the macro. These unnecessary lines can be removed. • Recorded macros do not contain any comments or explanations of what is happening in the code and input parameters are never recorded. • Recorded macros are very simple and don’t contain If statements, Loops, or other commonly used code. • Record macros can be used for simple tasks but it is better to write custom code; use the recorder if you get stuck or to find out the syntax if you don’t know it.
  • 7. To open and run macros There are multiple ways to open the macros window: • Tools>Macro>Macros • Macros toolbar • Keyboard shortcut: Alt+F8 • Create your own icon for each macro
  • 8. Macro Libraries • CATIA macros are stored in macro libraries in one of three locations: Folders (vbscript and CATScript), Project files (catvba), or documents such as CATParts, CATProducts, and CATDrawings. • Only one of these macro libraries can be used at a time. • When creating a new macro library, the folder or path location must already exist. If not you will get an error message.
  • 9. How to add a macro library • Use the following steps to setup an existing macro library
  • 10. •Go to Tools>Macro>Macros •Click "Macro libraries…"
  • 11. Ensure the Library type is set to "Directories" then click "Create new library…"
  • 12. Type in the file location where you are planning on saving all of your CATIA macros then click OK.
  • 13. Close the macros libraries window. This is where you can create CATScript macros. If you were setting up an existing library (add existing library versus Create new library) you would see a list of .CATScript files here. You only need to do this once as the library should load even after restarting CATIA.
  • 14. PROGRAMMING LANGUAGE • To write custom macros you need to know CATIA’s programming language, Visual Basic for Applications. • VBA provides a complete programming environment with an editor, debugger, and help object viewer. • CATIA cannot run a macro program WITHOUT the host application (CATIA) running (meaning it runs as a DLL in the same memory space as the host application). • CATIA macros are run in-process, meaning CATIA essentially freezes while the macro is running and the allocation memory is wiped clean after each run of the program so passing data between subsequent runs is impossible.
  • 15. What is CATScript? VBScript is a subset of the Visual Basic Programming language (VBA). All elements of VBScript are present in VBA, but some VBA elements are not implemented in VBScript. The result of the slimming down process is a very small language that is easy to use. Code specific to CATIA is saved as .CATScript. Can edit code in macro editor or notepad/word pad, etc. 151/12/2015
  • 16. MACRO SYNTAX • Syntax is defined as the ordering of and relationship between the words and other structural elements in phrases and sentences. • Each programming language is composed of its own syntax. • Think of it like this: when you see an email address (emmett@scripting4v5.com) you immediately identify it as an email address. Why is this? An email address has a correct structure in the language of the internet, its syntax. • Syntax enables the programming language to understand what it is you are trying to do
  • 17. SYNTAX • Case Sensitivity: By default, VBA is not case sensitive and does not differentiate between upper-case and lower-case spelling of words. • Comments: Add comments to your statements using an apostrophe ('), either at the beginning of a separate line, or at the end of a statement. It is recommended that you add comments wherever possible to make your scripts easier to understand and maintain, especially if another user has to make changes to it later on down the road. • Indentation: Indent or out dent script to reflect the logical structure and nesting of the statements to make it easier to read. • Parentheses: It is important to use parentheses correctly in any statement to achieve the desired result and to avoid errors.
  • 18. SYNTAX • Semicolon (:): Inserting a semicolon allows you to write multiple commands on the same line of code. • Single Quotation(‘): To return a single quotation mark which does not indicate a comment (needed in a formula for example), you'll have to use the Chr function. Chr() is a built-in VBA function that returns the character that corresponds to the numeric value of its argument using the ASCII coding scheme. If you provide Chr with an integer value (such as 39) it will report back the character that corresponds to that value. The ASCII value of 39 is the single quote mark. Chr(34) is for the double quote mark • Spaces: Add extra blank spaces to your script to improve clarity. These spaces are ignored by VBA.
  • 19. SYNTAX • Text Strings: When a value is entered as a text string you must add quotation marks before and after the string. • You can concatenate, or combine, multiple strings using a plus (+) or ampersand (&) sign: txtString = “This value is “+ TestValue. Return the left, middle, or right of a string using: left(sting, digits), mid(string, digits), or right(string, digits). Get the complete length of a string with len(string). To figure out if a string contains another string use Instr(). Convert numeric strings and vice versa using str(num) or val(string). • Underscore(_): Carry over to next line (line concatenation symbol).
  • 20. SEQUENTIAL PROGRAMMING • When you run your macro program, the code will be read by the computer line by line, generally from top to bottom and from left to right, just like reading a book. • The program flows down the code until it hits a decision point where it may have to jump to a different portion of the program or re-run lines of code that it already read. • The program chooses what lines of code to execute based on the state of the variables you have defined.
  • 21. EVENT DRIVEN PROGRAMMING • The execution of the program depends on an event, such as a user clicking a button with the mouse, an object being selected, certain text or characters being typed into a form, etc. • One common decision point is an If...Else statement. If the variable equals x then do y, else do z. • Another one is the while loop which will execute the lines of code within the loop over and over until the condition becomes false.
  • 22. VARIABLES • Variables make up the backbone of any programming language. • Variables store information that can be accessed later by referring to a name or “variable.” • Variables can then be declared as a type to let us know what we can do with that information. • The value of a variable will not necessarily be constant throughout the duration a program is running. • Naming variables is important; it’s best to be descriptive i.e. RowNumber, ColumnNumber
  • 23. VARIABLES • Variable names, also known as identifiers, must be less than 255 characters • They cannot start with a number. • Special characters such as spaces and periods are forbidden. • Avoid naming conflicts; two variables cannot have the same name. Example: • Good Variable Names: dimensionOne, dimension1 • Bad Variable Names: dimension One, 1dimension
  • 24. VARIABLES NOTATION • There is a popular naming convention where a letter is placed in front of the variable name to notate what type of data the variable is: • o=object (i.e. oPartDoc) • s=selection (i.e sSelection1) • str=string (i.e. strFilename) • i=integer (i.e iCount) • rng=Range (i.e. rngField) • Some programmers use “int” or “n” for integer and “str” for string. Either or works as long as your notation is consistent and easy for others to understand.
  • 25. • By default, Excel doesn’t force you to declare your variables. However, you should change that setting immediately. Press Alt+F11 to launch the Visual Basic Editor (VBE). Go to Tools>Options. • In the Editor tab of the Options dialog, make sure that there’s a check mark in front of “Require Variable Declaration”
  • 26. DIMMING AND SETTING • Variables are "dimmed" (declared) as a type, either a "primitive" type (single, double, integer, string, etc.) or an object type (more complex). • The "Dim" command is used to allocate a variable of any type. Primitive variables are populated with a value. Declaring variables with a ‘Dim’ statement helps save memory while running the program . • After a variable is declared through dimming then it is “Set” or given a value. • For object variables, the "Set" command is used to "point" the variable to the object. Within the program, the variable then represents that object unless it is "Set" to a different one.
  • 27. MACRO BASICS • An CATIA program or "macro" consists of a "Subroutine“. • CATIA only recognizes the Sub ___() as the entry point to any VBA application. • Every Sub must end with an End Sub. • You’ll add your code in-between the subs
  • 28. CREATE A MSGBOX MACRO • To create your first custom macro: • Use the shortcut Alt+F8 • Type in a new macro name “Test” • Click “Create” to launch the macro editor • Add the following code between the subs: • Msgbox “Hello world.” • Click the play button and a message box with the words “Hello world.” should pop up in front of your spreadsheet. Option Explicit Sub Main() MsgBox “Hello world.” End Sub
  • 29. To create an icon for each macro: • Go to Tools>Customize>Commands tab> scroll down to Macros>click "Show Properties"
  • 30. • Under Commands, select the macro then click the … box. The icon browser pops up. Over 6000 to choose from. Select one then hit close.
  • 31. • Finally, drag and drop the .CATScript file from the command window to whatever toolbar you would like the icon to appear on • Now you can click the Icon to run your macro! • You can also setup a custom keyboard shortcut as well.
  • 32. CATIA Version Macro This macro displays the current CATIA version and service pack number Sub CATMain() '---display the current CATIA version, R number and service pack MsgBox "The current CATIA configuration is: V" & CATIA.SystemConfiguration.Version & _ "R" & CATIA.SystemConfiguration.Release & _ "(SP" & CATIA.SystemConfiguration.ServicePack & ")" '---check to see if the specified product is authorized If CATIA.SystemConfiguration.IsProductAuthorized("FPE.prd") THEN MsgBox "FPE authorized." Else MsgBox "FPE Not Authorized" End If End Sub
  • 33. Want to learn EVEN MORE about programming macros in CATIA V5?
  • 34. Join the newsletter VB Scripting for CATIA V5 email newsletter for more macros tips delivered to your inbox. CLICK HERE TO SIGNUP FOR FREE! As a bonus you’ll receive the 7 Tools I Use When Programming CATIA Macros