[022] Export CGA Rules to SketchUp Using RPK Packages

Integrate procedural CityEngine logic directly into SketchUp by packaging CGA files as Rule Packages (RPK).

This tutorial demonstrates the process of converting CityEngine CGA rules into RPK files and utilizing them within SketchUp via a dedicated extension. While custom rules may currently face stability limitations in some versions, we will cover the essential workflow from rule creation to package installation and testing.

    Workflow Overview: CityEngine CGA to SketchUp RPK Pipeline

    It is said that CityEngine CGA files can be used in SketchUp, but in conclusion, it does not work well. The items included during installation work fine, but when trying to use custom-made ones, SketchUp ends up force-closing. Since I haven't used SketchUp much, even looking at GitHub, there are no bug reports at all, so I don't know what the problem is. Nevertheless, I will proceed with calling the CGA extension in SketchUp for now.

    Even though it failed, it's better to leave the process recorded.

    First, the way it works is as follows:

    • Complete the CGA code in CityEngine.
    • Convert it to an RPK (Rule Package) file using "Share As."
    • Install the CityEngine-Sketchup-Extension.
    • Use it in SketchUp.

    Preparing CGA Rules in CityEngine

    
    @Range(min=6, max=30, stepsize=1)
    attr BD_Height = 10
    # This is the building height attribute.
    
    @Range(min=3, max=5, stepsize=0.5)
    attr Floor_Height = 3
    # This is the floor height attribute.
    
    @Color
    attr Floor_Color = "#FF0000"
    # This is the color attribute.
    
    @StartRule
    Lot --> extrude(BD_Height) BD
    # Assigns height based on the BD_Height attribute value.
    
    BD --> split(y) { ~Floor_Height: Floor }*
    # Splits the floors by the Floor_Height.
    
    Floor -->
        case (split.index % 2 == 1):
            color(Floor_Color) X.
        # Colors odd floors with the Floor_Color attribute.
        else:
            color("#00ff00") X.
        # Colors the rest in green.
    

    Exporting CGA as RPK Package

    As a result, this is the CGA code that causes an error in the SketchUp extension, but it is a file that raises a building by setting the building height, floor height, and color as attribute values. Even floors are colored red, and odd floors are colored green.


    img 1 : View of the applied CGA rule in CityEngine
    img 1 : View of the applied CGA rule in CityEngine

    This is the screen showing the applied Rule. Now, let's create the RPK file.

    Select File - Share As.

    img 2 : Selecting the Share As menu
    img 2 : Selecting the Share As menu

    A screen appears to select which CGA file to convert into an RPK.

    img 3 : Selecting the source CGA file
    img 3 : Selecting the source CGA file

    When you select the CGA file you just created and click Open, a window asking for the save path appears.

    img 4 : Configuring the Rule Package settings
    img 4 : Configuring the Rule Package settings

    You can add a description for the RPK, and if 3D files or images were used in the CGA, you should include those folders as well to package them into the RPK.

    img 5 : Adding additional assets and descriptions
    img 5 : Adding additional assets and descriptions

    Once settings are complete, click Analyze to verify there are no errors in the CGA code, and if there are no issues, click Share to save it.

    img 6 : Analyze completion and successful package verification
    img 6 : Analyze completion and successful package verification

    Now it's time to install the CityEngine-Sketchup-extension. Note that the SketchUp version must be between 2017 and 2022.

    After downloading and installing the extension from the path below:

    https://github.com/highered-esricanada/CityEngine-Sketchup-Extension

    Installing CityEngine SketchUp Extension

    Copy the RPK file you just created into the C:\ProgramData\SketchUp\RPK folder.

    img 7 : Copying the RPK file to the SketchUp installation directory
    img 7 : Copying the RPK file to the SketchUp installation directory

    Running RPK in SketchUp

    Now launch SketchUp. For reference, I have installed the 2022 version. When you select "Show CityEngine Window" in the Extensions menu, a window will pop up.

    img 8 : SketchUp extension execution
    img 8 : SketchUp extension execution

    Since the custom-made one keeps failing, let's test the default RPK file that was installed initially.

    Video demonstration showing the successful operation of default RPK files in SketchUp.

    Troubleshooting Custom RPK Failures

    Why does the default RPK work well while the custom-made one causes errors? I thought about trying Bridge, but we will explore that when we cover the CompleteStreetRule package during CGA coding sessions. From the next lecture, the full-scale CGA coding begins.

    "The application of GIS is limited only by the imagination of those who use it."
    — Jack Dangermond, Founder and President of Esri
    Continue Learning
    Explore complete tutorial collections for CityEngine and Global Mapper.

    Comments

    Popular posts from this blog

    029] How to Split Polygon Areas with Intersecting Lines in Global Mapper

    [008] How to Understand CGA Rule Structure in CityEngine (Beginner Guide)

    046] How to Create Parallel Offset Lines in Global Mapper