[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.
This is the screen showing the applied Rule. Now, let's create the RPK file.
Select File - Share As.
A screen appears to select which CGA file to convert into an RPK.
When you select the CGA file you just created and click Open, a window asking for the save path appears.
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.
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.
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.
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.
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.
- If you want to organize long CGA code into reusable modules, see [021] Import External CGA Files for Modular Rule Design
- If you want to start learning procedural modeling from the basics, see [023] Let's start Learning CGA in CityEngine
Comments
Post a Comment
Feel free to leave a comment if you have any questions about Global Mapper or CityEngine. I will get back to you with a sincere response as soon as possible. (Please note that all comments are moderated and manually approved to maintain a high-quality community. Promotional or spam content will not be published.)