Cityengine uses Python scripts to export models

Source: Internet
Author: User

In the previous article "cityengine uses Python scripts to export roads by feature as a whole", we introduced how to export roads according to objectid of GIS Road Data. Users raised several questions during use, such:

1. The script is used in the whole cityengine scenario. When the data volume is very large, it will become stuck.

2. When processing road data, the name field must be assigned objectid, which is not intuitive enough.

3. It is not intelligent enough to record the number of roads in the road data table to modify the range () parameter of the Python script.

4. The choice of Export Road can only be controlled by the range () parameter, which is inconvenient and silly.

 

In order to solve the above problems, we can get rid of the objectid restrictions (the name field can be assigned a road name, of course, an English character), and you can directly select a box to export models in batches, the current modification script is as follows:

'''Created on 2012-8-14 @ Author: yyx''' from scripting import * # obtain ce instance Ce = Ce () selectedobj = ce. getobjectsfrom (CE. selection (), ce. isgraphsegment) # in CE. select collection to obtain the CE of the road network segments set. setselection (selectedobj) # reset ce. selection is the segments set numofselected = selectedobj. _ Len _ () # obtain the number of objects in the segments set nameofselectedobj = [] # create an empty list ''' to obtain the name of objects in the segment set cyclically, combine the duplicate value ''' for I in range (0, numofselected) with the set function: nameofselectedobj. append (CE. getname (CE. selection () [I]) uniqueselectedobj = set (nameofselectedobj) # Name of the segments set after merging duplicate values, that is, the unique road name ''' depends on the road name list, cyclically obtain all segments corresponding to a specific path, and finally export them as an OBJ model file ''' for OJB in uniqueselectedobj: Name = "'" + STR (OJB) + "'" # road name # Get all segments objects with the same road name. These segments objects constitute a path targetojb = ce. getobjectsfrom (CE. selection (), ce. withname (name) CE. setselection (targetojb) # Set ce. selection: selected segments with the same name # Set the export parameter settings = objexportmodelsettings () settings. setgenerallocation ("D:/Temp") settings. setgeneralname (name) CE. export (CE. selection (), settings) # export the selected segments as an OBJ model file based on the export parameters. This OBJ model file is the model ce of a road. setselection (selectedobj) # reset ce. selection is a set of all segments to export the next path

Note: This script is only valid for road export. The script will generate a separate OBJ file for each selected road.

 

The road data preprocessing method is the same as that in the previous article. You need to create a new name field and assign a value to the name field, but the name field can be an English name instead of an objectid.

After a model is generated, you can select an export model in the following ways:

1. select from the drop-down box

2. Select the segments of the road in the scene window, and select multiple parts by shift or Ctrl.

Segments with the same name are different lines of the same road. For example, two major edge 40062 segments form a road named Major edge 40062.

Run the script. The script selects the segments with the same name and exports them to an OBJ file. In this way, the model of the selected road is obtained. The name of the road model is the same as the name field.

 

The following describes the script methods:

1. Ce. Selection (): The objects set selected by the current CE instance

2. Ce. setselection (): This method is used to set Ce. Selection ()

3. CE. isgraphsegment: determines whether the selected objects is a segment. Because this script exports roads, the filtering type is segment. To export buildings, select ce. isblock or CE. isshape, which depends on the type of the selected objects, see:

Export models in blocks

Export models in shape

The type of the selected object can be viewed in inspector, for example:

4. Ce. getname (): Obtain the name of the selected objects

5. Ce. withname (): Get Objects Based on name

6. objexportmodelsettings (): sets the OBJ model export parameters.

7. Ce. Export (): export parameters based on the OBJ model to export the objects model selected by Ce. selection.

 

Summary:

  • The name field can be non-Chinese characters because it must be an objectid.
  • You can export any selected road model.
  • A slight modification can be used to export buildings (Ce. isgraphsegment is changed to CE. isblock or Ce. isshape)
  • After selecting objects, you only need to specify its rules. You do not need to generate models in scene or export the model.
  • Run the script by pressing F9 in the script window.

Problem:

  • If you select part segments of a certain road, the model of the exported road is incomplete and only contains the selected segments.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.