v1.1
 
Example of Style Template Creation

In the Renga STDL SDK, you can access several style template samples. Let's examine a Gas Stove category as an example to demonstrate how you can create a style template.

Technical Task

Before creating a style template, we will take a look at the technical task, according to which we will create a file of parameters and ports in JSON format and write a script in Lua.

The technical task can be shown through a drawing that illustrates the parameters and a table with their corresponding values.

Gas stove drawing
Group/Parameter Parameter type Default value Min Max
General
Material Id
Dimensions
Width Length 600 480 600
Depth Length 600 480 600
Height Length 850 800 1000
Gas
NominalDiameter 1/2″
ConnectionType CoreEnum Thread

Category Gas Stove is an Equipment category.

Description of parameters and ports

According to the technical task, we create a parameters and ports file using the structure detailed in the Style Template Structure topic.

See the resulting file in the Gas Stove Parameters and Ports file.

Please note that if the port is associated with a pipeline system, then the description of the ports must include parameters for the Thread connection type, so the ThreadSize parameter has been added in the Gas group in the following form:

{
"name": "ThreadSize",
"text": "Nominal Diameter",
"type": "CoreEnum",
"coreEnumType": "PipeThreadSize",
"default": "D0_50"
}

For other types of pipeline connections, the Nominal Diameter parameter is necessary:

{
"name": "NominalDiameter",
"text": "Nominal diameter",
"type": "Length",
"default": 7,
"min": 1,
"max": 20
}

Script

Getting parameters and declaring variables

First, we get the parameter values the user sets in the object style editor, in this case the Equipment styles editor. Then we declare the variables.

local parameters = Style.GetParameterValues()
local width = parameters.Dimensions.Width
local depth = parameters.Dimensions.Depth
local height = parameters.Dimensions.Height
Style namespace.
Definition GeometryStyleMethodRegistrator.h:13

Creating a gas stove model

According to the technical task, the oven is a rectangular parallelepiped with graphic primitives representing rings and oven door.

To create the rectangular parallelepiped, we use CreateBlock(width, depth, height). The symbols for the door and the cooking surface will be created using the new functions.

Creating a door symbol and setting its position

Using the new function, we will create a door symbol:

  • Define the dimensions of the symbol. According to the technical task, the dimensions of the door depend on the width and height of the gas stove.
  • Create a rectangle.
  • Create a set of two-dimensional primitives from the rectangle.
  • Return the symbol.
function MakeOvenDoorSymbol()
local doorWidth = width - 100
local doorHeight = height / 2
-- Create a rectangle.
local rectangle = CreateRectangle2D(Point2D(0, doorHeight / 2), 0, doorWidth,
doorHeight)
local geometrySet = GeometrySet2D()
geometrySet:AddCurve(rectangle)
return geometrySet
end
A set of geometric primitives that can include 2D curves and fills.
Two-dimensional point.
Curve2D CreateRectangle2D(Point2D center, double angle, number width, number height)
Creates a rectangle as composite curve of four line segments.

Set the symbol position so that the center of the rectangle is aligned with the center of the front face of the rectangular parallelepiped:

local doorSymbolPlace = Placement3D(Point3D(0, -depth / 2, height / 4),
Vector3D(0, -1, 0), Vector3D(1, 0, 0))
Local coordinate system in three dimensional space.
Three-dimensional point.
Three-dimensional vector.

Creating a cooking surface symbol and setting its position

We will use the cooking surface symbol not only for display in the model, but also as a symbolic representation of a gas stove for drawings.

Using the new function, we will create a cooking surface symbol consisting of 4 circles and a rectangle:

  • Define the dimension of the circle. According to the technical task, the diameter of the circle is 120 mm.
  • Create circles.
  • Create a rectangle.
  • Create a set of two-dimensional primitives from the circles and the rectangle.
  • Return the symbol.
function MakeCookingSurfaceSymbol()
-- Diameter is equal to 120, see technical task drawing
local radius = 120 / 2
local x = width / 4
local y = depth / 4
-- Create circles
local circle1 = CreateCircle2D(Point2D(x, y), radius)
local circle2 = CreateCircle2D(Point2D(x, -y), radius)
local circle3 = CreateCircle2D(Point2D(-x, -y), radius)
local circle4 = CreateCircle2D(Point2D(-x, y), radius)
-- Create rectangle for symbolic geometry
local rectangle = CreateRectangle2D(Point2D(0, 0), 0, width,
depth)
-- Create geometry set
local geometrySet = GeometrySet2D()
geometrySet:AddCurve(circle1)
geometrySet:AddCurve(circle2)
geometrySet:AddCurve(circle3)
geometrySet:AddCurve(circle4)
geometrySet:AddCurve(rectangle)
-- Return the resulting symbol
return geometrySet
end
Curve2D CreateCircle2D(Point2D center, number radius)
Creates a circle.

Set the symbol position so that the center of the symbol is aligned with the center of the top face of the rectangular parallelepiped:

local cookerSurfaceSymbolPlace = Placement3D(
Point3D(0, 0, height),
Vector3D(0, 0, 1), Vector3D(1, 0, 0))

Creating a detailed geometry

Create a detailed geometry and add all model components to it:

local detailedGeometry = ModelGeometry()
detailedGeometry:AddSolid(CreateBlock(width, depth, height))
detailedGeometry:AddGeometrySet2D(MakeOvenDoorSymbol(), doorSymbolPlace)
detailedGeometry:AddGeometrySet2D(MakeCookingSurfaceSymbol(),
cookerSurfaceSymbolPlace)
Model geometry.
Solid CreateBlock(number xSize, number ySize, number zSize, Placement3D oPlacement)
Creates a rectangular parallelepiped.

Set the detailed geometry for the object style using a function from the Style namespace:

Style.SetDetailedGeometry(detailedGeometry)

‍When the detailed geometry is set, you can check the result. See. Style Template Building and Testing and Debugging.

Creating a symbolic representation of a gas stove

We have already created a cooking surface symbol above. Now create a symbolic representation from it and set it for the style.

local symbolicGeometry = ModelGeometry()
symbolicGeometry:AddGeometrySet2D(MakeCookingSurfaceSymbol(),
cookerSurfaceSymbolPlace)
Style.SetSymbolicGeometry(symbolicGeometry)

Working with a port

The gas stove is connected to the Gas. This system category belongs to the Pipe system group.

In the equipment style editor, the user can select any type of connection for the port of the pipe system. Depending on the connection type, the port can take different diameter values.

If the connection is threaded, the value will be selected from a pre-set list. For all other cases, the diameter value will be set in millimeters. To ensure proper functioning, a function must be written.

function SetPipeParameters(port, portParameters)
local connectionType = portParameters.ConnectionType
if connectionType == PipeConnectorType.Thread then
port:SetPipeParameters(connectionType, portParameters.ThreadSize)
else
port:SetPipeParameters(connectionType, portParameters.NominalDiameter)
end
end
PipeConnectorType
Types of connections in pipeline systems.
Definition DoxygenCoreEnum.h:16

To display only the necessary parameter in the editor, let's create a function to hide the parameters and execute it for the port.

function HideIrrelevantPortParams(portName)
local isThread =
Style.GetParameter(portName, "ConnectionType"):GetValue() ==
Style.GetParameter(portName, "ThreadSize"):SetVisible(isThread)
Style.GetParameter(portName, "NominalDiameter"):SetVisible(not isThread)
end
HideIrrelevantPortParams("Gas")

Set the position of the port according to the technical task:

local gasPortPlace = Placement3D(
Point3D(width / 2 - 50, depth / 2, height - 100),
Vector3D(0, 1, 0), Vector3D(1, 0, 0))

Access the port and set its parameters:

local gasPort = Style.GetPort("Gas")
SetPipeParameters(gasPort, parameters.Gas)
gasPort:SetPlacement(gasPortPlace)

For a full style template sample, see link.