Peyep CGA 函数参考流程控制 · 2025.1
版本首页查看 demo →
← 返回 2025.1 分类导航

流程控制 Flow Control · 3 个函数

形状栈操作与空后继

NIL native ✓ cpp-fast ✓ 已实现未验证 官方文档 ↗ #
终止当前形状,不产生后继
签名(1 种重载)
NIL
官方说明(英文原文)

The NIL operation deletes the current shape from the shape tree. It can be used, for example, to create holes in split operations or to terminate recursive rules.

官方示例 · 点击展开
Lot-->
   extrude(10) 
   split(x){ { ~1 : X 
             | ~1 : NIL }* 
           | ~1 : X }
attr ErkerFact = 0.8
attr ErkerDepth = 0.8
attr ErkerStop = 2


Lot-->
   extrude(10)
   X
   comp(f) { all : Erker }
	
Erker-->
   case(scope.sx > ErkerStop) :
      s('ErkerFact, 'ErkerFact, 0)
      center(xy)
      alignScopeToGeometry(yUp, 0)
      extrude(ErkerDepth)
      X
      comp(f){top : Erker}
   else:
      NIL
pop native ✓ cpp-fast ✓ 已验证 2 条 · silver 官方文档 ↗ #
从形状栈恢复形状
参数说明
参数类型说明
operations—A sequence of shape operations to execute.
官方说明(英文原文)

The [ operation pushes the current shape onto the top of the shape stack. It must be matched by a succeeding ] operation, which pops the shape on top of the shape stack and deletes the shape.

官方示例(共 5 个,展示前 3 个) · 点击展开
Lot-->
	extrude(15)
    
	r(scopeCenter, 0, 22.5, 0) X 
	r(scopeCenter, 0, 22.5, 0) X
	r(scopeCenter, 0, 22.5, 0) X
Lot-->
	extrude(15)
    
	[ r(scopeCenter, 0, 22.5, 0) X ]
	[ r(scopeCenter, 0, 22.5, 0) X ]
	[ r(scopeCenter, 0, 22.5, 0) X ]
House -->
    extrude(10)
    comp(f) { top : roofHip(45) Roof. | all = House.}
	
House -->
    [ t(0,10,0) roofHip(45) Roof. ]
    extrude(10)
    comp(f) { top : NIL | all = House. }
我方已验证示例:learning case #111(verified_silver)· 点击展开代码 · 在 demo 中运行 →
@Description("CityEngine CGA 内置字符串与数组函数示例 - splitString / substring / find / replace / sort 等")
@Group("内置函数-字符串与数组")
@Order(37)

// ============================================================
// 内置函数 - 字符串与数组操作
// 演示 splitString, substring, strreplace, replace, toupper, tolower,
//       find, findFirst, findAll, findLast, getPrefix, getSuffix, getRange,
//       trim, startsWith, endsWith, includes, format,
//       size, nRows, nColumns, transpose, setElems, sortIndices, sortRowIndices,
//  …
push native ✓ cpp-fast ✓ 已验证 1 条 · silver 官方文档 ↗ #
把当前形状压入形状栈
参数说明
参数类型说明
operations—A sequence of shape operations to execute.
官方说明(英文原文)

The [ operation pushes the current shape onto the top of the shape stack. It must be matched by a succeeding ] operation, which pops the shape on top of the shape stack and deletes the shape.

官方示例(共 5 个,展示前 3 个) · 点击展开
Lot-->
	extrude(15)
    
	r(scopeCenter, 0, 22.5, 0) X 
	r(scopeCenter, 0, 22.5, 0) X
	r(scopeCenter, 0, 22.5, 0) X
Lot-->
	extrude(15)
    
	[ r(scopeCenter, 0, 22.5, 0) X ]
	[ r(scopeCenter, 0, 22.5, 0) X ]
	[ r(scopeCenter, 0, 22.5, 0) X ]
House -->
    extrude(10)
    comp(f) { top : roofHip(45) Roof. | all = House.}
	
House -->
    [ t(0,10,0) roofHip(45) Roof. ]
    extrude(10)
    comp(f) { top : NIL | all = House. }
我方已验证示例:learning case #114(verified_silver)· 点击展开代码 · 在 demo 中运行 →
@Description("CityEngine CGA 流程控制函数示例 - case / else / stop / push / pop / NIL")
@Group("流程控制")
@Order(35)

// ============================================================
// 流程控制 Flow Control
// 演示 case, else, stop, push/pop, NIL, p
// ============================================================

@StartRule
Lot --> FlowControlDemo

FlowControlDemo -->
    split(x) { ~6: CaseDemo
             | ~6: ElseDemo
             | ~6: StopDemo
             | ~6: PushPopDemo
             | ~6: NilDemo
    …