Grasshopper

algorithmic modeling for Rhino

Creating a bar graph using a python component - Stuck on how to use meshes

Hi everyone

I am trying to create a bar graph like seen in the 1st picture below,

I am already able to create the texts and simple lines which represent the data seen in the very uneventual 2nd picture.

But what I am struggling with is how do you create what I believe are called meshes and how do you colour them. At the moment I can only create lines to represent data but I want to be able to create think bars and colour them blue.

Can anyone write the basic code structure for me?

Views: 1032

Replies to This Discussion

Hi,

how about asigning a weight and a color to your lines?

Best,

RM

How do I do that I cant see this method in Rhino commons

The Human plugin has a component for displaying curves/lines with custom weights. If you want to script this you could use the CustomDisplay class. It can be a tricky though, having to dispose of the display and what not. I think a simpler approach would be to draw each bar as a quad mesh face and scale these meshes by their the value they represent.

I have here an snippet in C# maybe you can adapt it:

    Line my_line;
    my_line = x;
    
    Rhino.Display.CustomDisplay my_display = new Rhino.Display.CustomDisplay(true);
    my_display.AddLine(x, Color.Red, 10);

Cheers,

RM

For the future reference of anyone looking to do this its done along these lines to draw the blue bars in the graph itself

dataMeshes = []

for numseg, i in enumerate(datain): # numseg is 0 to 23 i is the data itself

planeRec = rc.Geometry.Plane.WorldXY
startPt = rc.Geometry.Point3d((width/len(datain))*numseg, 0, 0) # The point where that segment of the bar graph starts
textBasePts.append(rc.Geometry.Point3d((width/len(datain))*numseg+(width/len(datain))/2, 0,startPt.Z-width/100)) # The points where the hour of the bar graph will be placed
labelPts.append(rc.Geometry.Point3d((width/len(datain))*numseg+(width/len(datain))/2, 0,startPt.Z+(iscale*i)+width/100))

# Create the points of the mesh of the bars themselves

facePt1 = rc.Geometry.Point3d(startPt.X + width/240, startPt.Y, startPt.Z)
facePt2 = rc.Geometry.Point3d(startPt.X+ width*0.0375, startPt.Y, startPt.Z)
facePt3 = rc.Geometry.Point3d(startPt.X+ width/240, startPt.Y, startPt.Z+(iscale*i))
facePt4 = rc.Geometry.Point3d(startPt.X+ width*0.0375, startPt.Y, startPt.Z+(iscale*i))

# Create the values of each bar to display later as labels ontop of the bar graphs

labels.append(round(iscale*i,2))

# Create the mesh of the bars themselves
barMesh = rc.Geometry.Mesh()
for point in [facePt1, facePt2, facePt3, facePt4]:
barMesh.Vertices.Add(point)
barMesh.Faces.AddFace(0, 1, 3, 2)
# Color the mesh faces of the bars themselves
barMesh.VertexColors.CreateMonotoneMesh(System.Drawing.Color.Blue)

dataMeshes.append(barMesh)

I plan to make Youtube videos in the future about see my youtube channel - Anton Szilasi

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service