Learning EKL Enterprise Knowledge Language Intro

Learning EKL Enterprise Knowledge Language Intro

The Enterprise Knowledge Language formally known as the Engineering Knowledge Language in V5 is extensively used through out the 3DX Platform for both thick and thin clients. This post will focus on the thick client side predominantly on geometry creation and edition from the basics to advanced concepts.

Basic Syntax

Variables and Data Types

All programing languages have the ability to reserve blocks of memory for storing data values, EKL is no different. When reserving blocks of memory there are two pieces of information required the reservation name or variable name which must be unique and the data type.

With EKL there is an additional requirement, which is the variable name can not start with a number or contain spaces unless the variable name is wrapped with grave symbols i.e. `2DProfile`, the same can also be said for the data type.

Multiple variables of the same data type can be defined at once by comma separating the variable names.

The Variable Name can be anything, however it’s best to use a name that’s meaningful. In addition to this a prefix of ‘i’, ‘o’, ‘io’ can be used to define if the variable is used for input, output or internal variables.

The variable name can contain multiple words, as a result CamelCase is suggested, this is where the first letter of each word is capitalized and there are no space between the separate words.

There is a special case for late bound variables, where the data type is not defined but the variable is initialized. It is strongly advised to strongly type your variables at the time of definition and not to use late bound variables, as shown below.

Typically used data types are, however there are thousands;

Comments

Within the EKL programming language we can either comment a single line or comment out blocks of code.

Its often very useful to add comments into your code to help either yourself or others when later editing the code. Also while debugging there are occasions when you will need to comment out a single or multiple lines.

Specification Tree Objects

There are two occasions when we will need to reference objects in the specification tree; when equating a variable to a spec object and equating a spec object to a variable. The difference is which side of the equals sign is the spec object.

To include a specification tree object within the code, double click on the spec object.

Basic Wireframe Constructors

Point by Coordinates
Point Between
Line Pt to Pt

Its important to understand this is the expanded form we can compress the code by a process of substitution. This is referred to as in-lining, where constructors contain other constructors.

Point On Curve Ratio

Set Keyword

Within the CAD application there is an object inheritance hierarchy for example at the top of the geometry hierarchy is an object of type ‘Wireframe‘, since all geometry can be classified as ‘Wireframe‘. The ‘Wireframe‘ object has certain property’s and Methods that will be inherited by all subtypes, for example ‘.Name‘, ‘.Color‘, ‘.Show‘, ‘->Update()‘, etc. Next in the inheritance would be ‘Curve‘, ‘Surface‘, ‘Point‘, ‘AxisSystem‘, below ‘Curve‘, ‘Line‘, ‘Circle‘, ‘Arc‘, ‘Spline‘ etc., and below ‘Surface‘, ‘Plane‘. Since ‘Wireframe‘ has the attribute ‘.Name‘ then all inherited subtypes will have the ‘.Name‘ attribute. Any attributes or methods defined at the ‘Curve‘ object will be inherited down to ‘Line‘, ‘Circle‘, ‘Arc‘, ‘Spline‘ etc.

This is important to understand that there is an inheritance hierarchy and which types are related to each other. When we define an object such as ‘Wireframe‘ in memory we can directly equate that to any object in the specification tree of any type, because ‘Wireframe‘ is the higher type.

However we can’t go in the opposite direction and equate directly a ‘Point‘ to a ‘Wireframe‘ element. This happens with some EKL functions the best example of this is ‘translate‘. When we translate geometry we can select any type ‘Point‘ , ‘Line‘, ‘Plane‘, ‘Curve‘ etc. So the translate function has to be written to accept ‘Wireframe‘ elements, but as a result the output also has to be ‘Wireframe‘, since we never know what object type is being translated.

This can be seen below with the ‘ToTranslate‘ object which is defined as ‘Wireframe‘ and the last part of the method signature is ‘Wireframe‘ shown out side of the last parenthesis.

So if I translate a ‘Point‘ and I get back a ‘Wireframe‘ element how do I convert this back to a ‘Point‘. This is where the ‘Set‘ keyword comes in or the Cast method. Here we can see a point by coordinates is created along with a direction these are then used to define a translation in +Z of 10mm.

The ‘Set‘ Keyword is used to force the ‘ioTranslatedPoint‘ object to be equivalent to the translated ‘Wireframe‘ object.

Where as the ‘: Point‘ Casts (Converts) the resulting translated ‘Wireframe‘ object to a ‘Point‘ object. When Casting we must match the object type to the left-hand side of the equals symbol. The Cast method becomes really useful when in-lining constructors, since we can cast the correct type within a line of code where as the ‘Set‘ keyword can only be used at the start of a line of code.