CATIA macro syntax is defined as the ordering of and relationship between the words and other structural elements in phrases and sentences. You can think of it as a particular layout of words and symbols. Each scripting language is composed of its own syntax. Learning the syntax of each programming language is crucial to creating successful macros. 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. Listed below are some of the key syntax features of CATIA macro programming:
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: To achieve the desired result and to avoid errors, it is important to use parentheses correctly in any statement.
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. This is shown in an example later on in this text.
Spaces: Add extra blank spaces to your script to improve clarity. These spaces are ignored by VBA.
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)
Syntax is often the biggest cause of a macro program giving an error and not working. There is a correct way to write your code. It takes practice, patience, and persistence to understand but over time it will become second nature to you. If you follow the rules the programming languages will understand you otherwise you will get errors.
Dealing with syntax can be tough which is why programmers have developed tools to help create programs correctly. These are called IDE, or integrated development environments (remember that definition I defined earlier?). The Visual Basic editor in CATIA is the perfect example (Alt+F11). It contains a built-in syntax checker and works much like a grammar checker found in software like Microsoft Word and will even give you hints about what it thinks you meant.
Go back to CATIA macro languagues.
Hi, your site is excellent. I truly do appreciate you sharing helpful posts.
is it possible to edit text (only portion of sentence) using catia macros
How to turn on case sensitive for portion of code?
Regards!
Hi,
As I am working on catia macro development.
I want to instantiate a power copy using command button(Userform).But I am getting problem while if I use same code in catscript and run through macro it works fine..
Any suggestion.
I am not sure about KT1 licence as I am using Catai V5 r28
Hi
May I request you help to correct this issue.
Trying to create a sphere with exiting points. Requirement is to create a sphere with parameter. I followed your youtube video but not able to fix the problem.
Not able to create formula to connect to radius of shpere.
Language=”VBSCRIPT”
‘ * * * * * * * * * * * * *
‘This MACRO is to create a parametric spehere with diametere as input
‘points in GS
‘ * * * * * * * * * * * * * – – – – – – – – – – – * * * * * * *
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set hybridBodies1 = part1.HybridBodies
‘Set hybridShapes1 = hybridBody1.HybridShapes
Set axisSystems1 = part1.AxisSystems
msgbox (“Select the geometrical set with I/P points for creating Sphere”)
Dim oSelection ‘as Selection
Dim InputObjectType(0)
Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
InputObjectType(0) = “HybridBody”
Status = oSelection.SelectElement2(InputObjectType, “Select Geometrical set.”, True)
Set hybridBody1 = hybridBodies1.Add()
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject
Set parameters1 = part1.Parameters
Dim length1 ‘As Dimension
Set length1 = parameters1.CreateDimension(“”, “LENGTH”, 0.000000)
length1.Rename “SPDia”
length1.Value = 25.000000
‘Spheredia=Inputbox(“Enter Diameter of sphere to be created”)
Dim iCount
Dim i ‘As Integer
oSelection.Search “CATGmoSearch.Point,sel”
iCount = oSelection.Count
For i = 1 to iCount
Set hybridShapePointOnSurface1 = oSelection.Item(i).Value
Dim reference1 ‘As reference
Set reference1 = part1.CreateReferenceFromObject(hybridShapePointOnSurface1)
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim relations1 ‘As Relations
Set relations1 = part1.Relations
Dim formula1 ‘As Formula
Set formula1 = relations1.CreateFormula(“Formula.2”, “”, length1, SPDia)
formula1.Rename “Formula.2”
Set hybridShapeSphere1 = hybridShapeFactory1.AddNewSphere(reference1, Nothing, SPDia, -45.000000, 45.000000, 0.000000, 180.000000)
hybridShapeSphere1.Limitation = 1
hybridBody1.AppendHybridShape hybridShapeSphere1
part1.InWorkObject = hybridShapeSphere1
hybridShapeSphere1.name = “Shpere for-” & oSelection.Item(i).Value.name
‘part1.Update
NEXT
part1.Update
msgbox (“Total number of sphere created -” & iCount)
End Sub