Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
GenerativeComponents
  • Product Communities
GenerativeComponents
GenerativeComponents Community Wiki Point By Function Example
    • Sign In
    • +An Overview of GenerativeComponents
    • +Addin Content
    • +Bentley BIM Modeler Accreditation – Program Overview
    • +C# Sample Solution and other Add-ins
    • +GenerativeComponents Solutions
    • +Learn GenerativeComponents
    • +Reference Material
    • Support for GenerativeComponents
    • -Tutorials
      • 3D array copy surface
      • Add RFA data as BuildingContent to ABD with GC Extension
      • BSplineSurface.LoftCurve is throwing an error when trying to add get the curves from cell
      • Cell Feature
      • Create a Set of Random Points
      • Creation of Global function from Custom function
      • Creation of Parabolic curve
      • Error while creating GNT
      • Free Form Roof Example
      • GC Excel Feature
      • GenerativeComponents Essentials Course
      • Get Corner points of a Solid
      • How To Create Surface From Lines & Curves
      • How to Export GC elements
      • How to get concrete sections in the cross-section dialog in Generative Components
      • Landscape Bridge Example
      • +LawCurve
      • List Of Points With A Loop Example
      • Mesh feature 3d print
      • Modular Multiplication On Circle
      • +Operation Node
      • +Optimization with the Optimizer node type
      • Palm Tree Modeler
      • Point By Function Example
      • Points On Curve
      • Prime Number Pattern
      • Selection of Points
      • Selection of points based on Query Expressions
      • Selection of points based on range of indices
      • Set a New Property Value to a Set of Selected Nodes
      • Simple Bridge Example
      • Simple Equations To Describe Form Example
      • Simple Free Form Roof Example
      • Sin Tower
      • Skeleton
      • Sunflower Seed Pattern Modelling
      • Surface Division Basic Steps
      • Surface from Rails and Swept Sections
      • The use of Packager in Generative Components
      • +Tools and Techniques
      • Ulam Spiral From A Rectangular Spiral
      • Video Tutorials
      • Video Tutorials - Short Techniques
      • Working with Parametric cells
    • +User Projects
    • +Visualized Parametric Experimentations
    • +zed_Older Content

     
     Questions about this article, topic, or product? Click here. 

    Point By Function Example

    Introduction

    In this example we will build up a very simple function based script to create a Point Feature using the ByCartesianCoordinates method as the creation method.

    For more examples refer to the GenerativeComponents Documentation page.

    Create a new .gct file

    To start we open a new transaction file using the new transaction file as in any other GenerativeComponents file.

    Create a Point with the ByFunction method

    We will create a point Feature as usual from the Feature List, but rather than directly using one of the model based methods we will use a function. To do so choose Point->ByFunction as the method.

    Open up a script editor window to write the function

    Clicking on the script editor  will invoke the script editor window. This is where we will write the function to generate the Point in using the GCScript language introduced before.

    Setting up the function using the Statement Builder

    Clicking on the statement builder  in the script editor console invokes a list of script statement templates that make it easier to create standard scripting expression. We will use it to first create a function wrapper.

    Select function from the drop down list. The statement should look like this. The brackets denote the beginning and the end of the function body. Arguments is the placeholder for any input arguments we may define.

    function (arguments)

    {

     

    }

     

    Specifying the input arguments to the function

    First we define the input arguments by replacing the placeholder argument with our own inputs to this specific function. Since we want to create a Point ByCartesianCoordiantes we will need a reference to a CoordinateSystem so we need to pass a reference to our function to an outside CoordinateSystem. To do so we need to specify the Type of the input argument and a variable name, that will contain the input value within the boundaries of our function. This concept is also referred to as scope. It means the variable we define here is only defined within the scope or range of our function. We can use any variable name, but to make understanding easier let’s choose cs as a short form for CoordinateSystem. As the type we declare it to be of type CoordinateSystem as that is what we expect the user to pass in as an argument.

    function (CoordinateSystem cs)

    {

     

    }

     

    Creating the internal Variable for the new Point Feature

    Next we need to define a variable of Type Point to hold our to-be-created Point Feature inside the function. To do so we declare a new variable and call it pt01. To initialize it we call the new Point(parentFeature) function from the Feature function list in  under the tab Feature Types.

    There are several initialization methods listed here, but in this case we want the Point in the function to become a parent of the Point Feature we are writing the ByFunction method for, therefore we are using the third method new Point(parentFeature) (the {,featureName] indicates an optional input that is not required, we will not use it here).

    The reason to create the Point in the function as a child to the top level Point is to refer to it with the same name as its parent, which is useful if we make a list of points later.

    The function should look like this now:

    function (CoordinateSystem cs)

    {

        Point pt01 = new Point(parentFeature)

    }

     

    In order to complete this step we need to replace the parentFeature placeholder with a reference to the parent. In this case we said we want to parent the point to the Point we are writing the function in. To do so one uses the keyword this. It makes the new Point a child of the Point this is being called in.

    function (CoordinateSystem cs)

    {

        Point pt01 = new Point(this)

    }

     

    The last thing is to add a ";" at the end of the line to let our script editor know that it is the end of the expression. The script should look like this now. 

    function (CoordinateSystem cs)

    {

        Point pt01 = new Point(this);

    }

     

    Instantiating the Point Feature using ByCartesianCoordinates

    Although we initialized the Point pt01 it still is not created yet. To do so we need to choose a method from our method list for Points. We will use ByCartesianCoordinates. But we will use the variable pt01 that refers to our new Point object to call the method using the dot operator. Once we type pt01. The drop down list will display all the available methods.

    Choosing the ByCartesianCoordinates method inserts the template shown below:

    function (CoordinateSystem cs)

    {

        Point pt01 = new Point(this);

        pt01.ByCartesianCoordinates(CoordinateSystem, Xtranslation, Ytranslation, Ztranslation [, Origin] )

    }

     

    We need to replace the placeholder input arguments with values or variables that are valid in our function. The CoordinateSystem will be replaced with a reference to our input argument CoordinateSystem, which we called cs in this function. The X ,Y, Z value we can replace with fixed values for now – the [, Origin} again shows an optional value, which we will not use for now so we can delete it. Then the function looks like this.

    function (CoordinateSystem cs)

    {

        Point pt01 = new Point(this);

        pt01.ByCartesianCoordinates(cs, 3, 2, 0 );

    }

     

    Using the ByFunction method with input arguments

    Now that our simple function is completed we can close the script editor and use it. To do so we need to pass it one input argument, since we defined an input argument of type CoordinateSystem. This is specified in the ByFunction method in the input field below the Function and it is a list of input arguments, in our case with one element in it, the baseCS. So it will read {baseCS}. Pressing Apply will pass the argument to our function and through the cs variable we defined to the ByCartesianCoordinates method that creates the Point. The Point appears in red as a child Feature of the top level Point point01 that hosts our function. It will look like this.

    This example continues with the GC - List Of Points With A Loop Example.

    • Share
    • History
    • More
    • Cancel
    • Jonathan Asher Created by Jonathan Asher
    • When: Wed, Oct 15 2008 12:17 PM
    • CWiacek Last revision by CWiacek
    • When: Thu, Feb 17 2011 9:37 AM
    • Revisions: 15
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies