Set section attributes with VisualARQ

To automate the setting of section attributes in Rhino and VisualARQ

Introduction

This script is designed to apply section attributes to objects in Rhino using the VisualARQ.Script library. It allows you to apply section patterns, pattern scales, pattern angles, and line weights based on the layer name of the objects. The script is written in Python and requires the Rhino software with the VisualARQ extension installed.

Features

  • Apply section attributes to objects based on their layer name

  • Set section pattern, pattern scale, pattern angle, and line weight for selected objects

  • Works for Rhino objects and objects contained in Rhino blocks

Usage

  1. Make sure you have Rhino and VisualARQ installed

  2. Download the script

  3. Open Rhino and use the RunPythonScript command to load the script

  4. That's it!

Dependencies

The script has the following dependencies:

  • Rhino software

  • VisualARQ extension

  • Python libraries: clr, rhinoscriptsyntax, math

Known Issues

None reported.

Updates

  • 30/08/2023 : Remove blocks that have "*Plan view", "*Section view" ans "*Section" in their names (VisualARQ objects that don't need to receive section attributes) from selection - 10x faster performance

Script

import rhinoscriptsyntax as rs
import scriptcontext as sc
import math
import clr
clr.AddReference("VisualARQ.Script")
import VisualARQ.Script as va

# global variables
pi = math.pi

# pattern dictionary
solid = 1
single = 10
double = 3
hatch_dash = 5
grid = 6
grid_60 = 7
plus = 8
squares = 9

# function to apply section attributes according to layer name
def apply_section_attributes_by_layer_name(material_name, pattern, pattern_scale, pattern_angle, line_weight):
    rs.EnableRedraw(False)
    selected_objs = []
    all_objs = rs.AllObjects()
    if all_objs:
        for obj in all_objs:
            obj_layer = rs.ObjectLayer(obj)
            if material_name in obj_layer:
                selected_objs.append(obj)
    if selected_objs:
        for obj in selected_objs:
            va.SetObjectSectionPattern(obj, pattern, pattern_angle, pattern_scale)
            va.SetObjectSectionPlotWeight(obj, line_weight)

    idefs = sc.doc.InstanceDefinitions
    for idef in idefs:
        if idef.Name:
            if "*Plan view" not in idef.Name and "*Section view" not in idef.Name and "*Space" not in idef.Name and "*Section" not in idef.Name and "*Table" not in idef.Name:
                idef_objects = idef.GetObjects()
                for obj in idef_objects:
                    obj_id = obj.Id
                    obj_layer = rs.ObjectLayer(obj)
                    if material_name in obj_layer:
                        va.SetObjectSectionPattern(obj_id, pattern, pattern_angle, pattern_scale)
                        va.SetObjectSectionPlotWeight(obj_id, line_weight)

# end message
def end_message():
    print("All section attributes applied :)")

# list options
def set_print_info():
    options = ('20e', '50e', '100e', '200e', '20e-no-hatch', '50e-no-hatch', '100e-no-hatch', '200e-no-hatch')
    if options:
        result = rs.ListBox(options, "Pick an option")
        if result == "20e":
            apply_section_attributes(0.5, 1)
        elif result == "50e":
            apply_section_attributes_50(1, 3)
        elif result == "100e":
            apply_section_attributes(2, 3)
        elif result == "200e":
            apply_section_attributes(4, 4)
        elif result == "20e-no-hatch":
            apply_section_attributes_no_hatch(1)
        elif result == "50e-no-hatch":
            apply_section_attributes_no_hatch(2)
        elif result == "100e-no-hatch":
            apply_section_attributes_no_hatch(2)
        elif result == "200e-no-hatch":
            apply_section_attributes_no_hatch(4)
        else:
            exit()
        
def apply_section_attributes_50(hatch_scale_factor, line_scale_factor):
    apply_section_attributes_by_layer_name("Beton", hatch_dash, 20.00*hatch_scale_factor, pi/4, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Isolant", grid, 15.00*hatch_scale_factor, pi/4, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Dallage", hatch_dash, 10.00*hatch_scale_factor, pi/4, 0.10*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Lino", solid, 1.00*hatch_scale_factor, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Carrelage", solid, 1.00*hatch_scale_factor, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Acier", solid, 1.00*hatch_scale_factor, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Bois", single, 0.70*hatch_scale_factor, pi/4, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Brique", hatch_dash, 20.00*hatch_scale_factor, pi/4, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Structure-brique", hatch_dash, 10*hatch_scale_factor, -pi/4, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Enduit", -1, 1.00*hatch_scale_factor, 0, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Enduit-blanc", -1, 1.00*hatch_scale_factor, 0, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Fermacell", single, 2.00*hatch_scale_factor, pi/4, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Tuile", solid, 1.00*hatch_scale_factor, 0, 0.10*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Zinc", solid, 1.00*hatch_scale_factor, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Porte", single, 10000.00, -pi/4, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Serrurerie", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Fenetre::Bois", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Porte::Bois", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Verre", solid, 1.00*hatch_scale_factor, 0, 0.05*line_scale_factor*0.5)
    sc.doc.Views.Redraw()
    end_message()

def apply_section_attributes(hatch_scale_factor, line_scale_factor):
    apply_section_attributes_by_layer_name("Beton", hatch_dash, 20.00*hatch_scale_factor, pi/4, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Isolant", grid, 15.00*hatch_scale_factor, pi/4, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Lino", solid, 1.00*hatch_scale_factor, 0, 0.01*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Carrelage", solid, 1.00*hatch_scale_factor, 0, 0.01*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Acier", solid, 1.00*hatch_scale_factor, 0, 0.01*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Bois", single, 0.70*hatch_scale_factor, pi/4, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Brique", hatch_dash, 20.00*hatch_scale_factor, pi/4, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Structure-brique", hatch_dash, 10*hatch_scale_factor, -pi/4, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Enduit", -1, 1.00*hatch_scale_factor, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Enduit-blanc", -1, 1.00*hatch_scale_factor, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Fermacell", single, 2.00*hatch_scale_factor, pi/4, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Tuile", solid, 1.00*hatch_scale_factor, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Zinc", solid, 1.00*hatch_scale_factor, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Porte", -1, 2.00*hatch_scale_factor, -pi/4, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Serrurerie", -1, 1.00*hatch_scale_factor, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Fenetre::Bois", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Porte::Bois", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Verre", solid, 1.00*hatch_scale_factor, 0, 0.01*line_scale_factor*0.5)
    sc.doc.Views.Redraw()
    end_message()

def apply_section_attributes_no_hatch(line_scale_factor):
    apply_section_attributes_by_layer_name("Beton", single, 10000.00, 0, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Isolant", single, 10000.00, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Lino", single, 10000.00, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Carrelage", single, 10000.00, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Dallage", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Acier", single, 10000.00, 0, 0.02*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Bois", single, 10000.00, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Brique", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Structure-brique", single, 10000.00, 0, 0.15*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Enduit", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Enduit-blanc", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Fermacell", single, 10000.00, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Tuile", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Zinc", single, 10000.00, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Porte", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Serrurerie", single, 10000.00, 0, 0.05*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Fenetre::Bois", single, 10000.00, 0, 0.09*line_scale_factor*0.5)
    apply_section_attributes_by_layer_name("Verre", single, 10000.00, 0, 0.01*line_scale_factor*0.5)
    sc.doc.Views.Redraw()
    end_message()

if( __name__ == "__main__" ): # perform function
    set_print_info()

Last updated