Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5850

Set object color

$
0
0

@elaner wrote:

I am trying to set the color of a cylinder I created using python. Cylinder is created, but the color does not change.

Here is the script. Any help is appreciated.

import Rhino
import utility as rhutil
import scriptcontext
import System.Guid
import re
import math
import time
import sys

import System.Windows.Forms.DialogResult
import System.IO.File

import object as rhobject

from scriptcontext import doc

import Rhino.UI
import rhinoscriptsyntax
import System.Drawing.Color
import System.Enum
import System.Array
import System.Windows.Forms
from view import __viewhelper

import os

def AddCylinder(base, height, radius, cap=True):
    """
    Adds a cylinder-shaped polysurface to the document
    Parameters:
      base = The 3D base point of the cylinder or the base plane of the cylinder
      height = if base is a point, then height is a 3D height point of the cylinder. The height
        point defines the height and direction of the cylinder. If base is a plane, then height
        is the numeric height value of the cylinder
      radius = radius of the cylinder
      cap[opt] = cap the cylinder
    Returns:
      identifier of new object if successful
      None on error
    """
    cylinder=None
    height_point = rhutil.coerce3dpoint(height)
    if( height_point!=None ):
        #base must be a point
        base = rhutil.coerce3dpoint(base)
        if( base!=None ):
            normal = height_point-base
            plane = Rhino.Geometry.Plane(base, normal)
            height = normal.Length
            circle = Rhino.Geometry.Circle(plane, radius)
            cylinder = Rhino.Geometry.Cylinder(circle, height)
    else:
        #base must be a plane
        base = rhutil.coerceplane(base)
        if( base!=None ):
            circle = Rhino.Geometry.Circle(base, radius)
            cylinder = Rhino.Geometry.Cylinder(circle, height)
    if( cylinder==None ): return scriptcontext.errorhandler()
    brep = cylinder.ToBrep(cap, cap)
    id = scriptcontext.doc.Objects.AddBrep(brep)
    if( id==System.Guid.Empty ):
        return scriptcontext.errorhandler()
    return id
    """
    scriptcontext.doc.Views.Redraw()
    """

x = 20.
y = 30.
thickness = .5
radius = .5
base = Rhino.Geometry.Point3d(x, y, thickness)
top = Rhino.Geometry.Point3d(x, y, thickness+.1)
scyl = AddCylinder(base, top, radius)

rhinoscriptsyntax.ObjectColor(scyl,(25,50,255))

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5850

Latest Images

Trending Articles



Latest Images