Select to view content in your preferred language

Using comp and listAdd to gather shape geometry

01-23-2019 10:01 AM
New Contributor

I'd like to use listAdd to create a string that contains geometry information about shapes generated through the comp operation.

The code below separates the shape into its edge components and, in the Edges rule, tries to gather the edge lengths recursively and store them in the EdgeLengths attribute.

Rather than storing separate edge lengths, it produces a string with the same edge length listed multiple times, i.e., the loop is running multiple times on the same edge shape.

Is using listAdd in this way possible in CGA, or is there another way to accomplish this? Is this something I'd need Python integration for?

I'm new to CGA, so any guidance is helpful!

* File: listfunctions.cga
* Created: 16 Jan 2019 20:40:45 GMT
* Author: chlvws

version "2018.0"

attr EdgeLengths = ""

   comp(e) { all : Edges }

   case listSize(EdgeLengths) < 3:
      set(EdgeLengths, AddItem(str(
   else: print(EdgeLengths)

AddItem(Edge) =
   listAdd(EdgeLengths, Edge)

0 Kudos
1 Reply
Esri Regular Contributor

In 2019.0, the new comp function (the existing comp operation co-exists with the new comp function) allows you to access attributes for each edge by returning an array, with one element per edge.  You can use comp to get an array of edge lengths.

getEdgeLengths = comp(fe) { all: }

Lot -->
	print(size(getEdgeLengths))				// size of array
	print(getEdgeLengths[0])				// element at index 0
	print(index(getEdgeLengths, 10, 0.1))	// index of first occurrence of value=10 with eps=0.1

Here are the help pages to get array info like size, item, index:

For more examples, check out how comp is used to when definining dists in the examples on the help page for the setback operation.

Your above approach doesn't work because shapes created from a comp do not know about each other.  Let's say you have 4 edges.  The comp will create 4 different shapes in the shape tree, one for each edge, and these shapes do not know about each other.  The code in the Edges rule is run 4 times, once for each edge, but these are run independently of each other; they do not build on each other sequentially.

0 Kudos