Rhino on large scale project #4- Integrating models by using scripts

The previous article was about the methods to save each part into individual files, and the process to be repeated by batch operation.

The ongoing project used this method to model the facade parts, but in this way, it is troublesome to check the whole shape as an overall model due to the separated files. This is a drawback.

Furthermore, since we need to create a consistent and workable model while exchanging data with other companies, it is necessary to reintegrate all part models into one model when deploying the data to other companies. If the shape is complicated, the confirmation and the accompanying shape correction are repeated each time. Therefore, creating an integrated model is essential (the essential model hereinafter referred to as “integrated model”)

In Rhino, when merging multiple files, it seems you can only import the files all by dragging and dropping them at once. If it is a large-scale project within many parts and laying in different folders, it takes time and suffers the stress of merging files without missing anything every time.

This time, I will write about how to automatically create an integrated model by using a script. Assuming the following project file and folder structure which include the following files: base.3dm + working.3dm + parts_modeling to integrate.

It is also possible to manage the general panel and the base panel with UserText etc. and to manage them with conditional branching. This time I will assume that the folders are separated

Project folder / file structure

prj_name
- 0_base
	- base.3dm // File content unchangable objects such as reference lines. 
                 (which usually is attached to use, but includs the model when integrating)

- 1_working
	- working.3dm // Working files which might includ the skeleton and support parts
                  

- 2_parts_modeling
	- parts  // Files which named separately for each member, general panel
		- 0000.3dm
		- 0001.3dm
		- 0002.3dm
		- ...

	- parts_bottom // Files named for each member, base panel (partially different details due to the building ground level)
                    
		- 9001.3dm
		- 9002.3dm
		- 9003.3dm
		- ...

To create a integrated model automatically:

  1. Specify the project folder
  2. Create a new Rhino canvas
  3. Read the file
  4. Save the file after naming it

These processes are required.

Let’s write a script. The operating environment is Windows10 / Rhino6.

### Copyright (c) 2021 Syntegrate
###
### This software is released under the MIT License.
### https://opensource.org/licenses/MIT

# -*- coding: utf-8 -*-

import datetime
import os
import rhinoscriptsyntax as rs


def get_current_time():
    return str(datetime.datetime.now().strftime("%y%m%d-%H%M%S"))

def get_rhino_file(dir_):
    pathList = []
    for file in os.listdir(dir_):
        if file.endswith(".3dm"):
            path = dir_ + "\\" + file
            pathList.append(path)
            # print (path)
    return (pathList)


### (1) Set Path
prj_path = rs.BrowseForFolder()
# print(prj_path)


### (2) Rhino Initialize
rs.Command("-New \"Large Objects - Millimeters.3dm\"")


### (3) Import
##### Base
base_path = "\"" + prj_path + "\\0_base\\base.3dm\""
rs.Command('_-Import {} _Enter'.format(base_path))

##### Working
working_path = "\"" + prj_path + "\\1_working\\working.3dm\""
rs.Command('_-Import {} _Enter'.format(working_path))

##### Parts
parts_dir = prj_path + "\\2_parts_modeling\\parts"
parts_path = get_rhino_file(parts_dir)
for p in parts_path:
    p = "\"" + p + "\""
    rs.Command('_-Import {} _Enter'.format(p))

##### Parts_Botttom
parts_dir = prj_path + "\\2_parts_modeling\\parts_bottom"
parts_path = get_rhino_file(parts_dir)
for p in parts_path:
    p = "\"" + p + "\""
    rs.Command('_-Import {} _Enter'.format(p))


### (4) Save
timestamp = get_current_time()
result_path = prj_path + "\\result_{}".format(timestamp) + ".3dm"
rs.Command("-Save \"{}\"".format(result_path))

print("SAVE : {}".format(result_path))

It’s not smart to include a large number of file names with serial numbers in your code, so let’s get a list of files in the specified folder and process it in a loop. In this script, it is not quite clever for the hard-coding of the file names under the folder “2_parts_modeling”.

When the above script is executed, an integrated model named with the time of creation will be created directly under the first selected folder.

The creation time is 23:00 but I’m not insisted, don’t worry 😀

If you are about to finish the model modifying, just run the script, and wait on your seat. You can create an integrated model while avoiding human error with only the file summarizing process.

There is still some part I would like to dig more into. I wonder if it’s possible to add functions such as analysis and automatically integrate them while spitting out the analysis results.
It is worth trying to write scripts to automate simple tasks that occur repeatedly, so I want to increase the time I spend facing essential tasks (in order to make “more comfortable 🙂

Translation: Iris Huang

naoki.yoshioka

Mainly in charge of façade projects. He uses Japanese and Python, and is studying C++ (and English).

Share

Leave a Reply

Your email address will not be published.

4 − three =

Post comment