Grasshopper

algorithmic modeling for Rhino

All,

  I have found a python script that does something I'm trying to replicate in C# or VB but I can't figure out how to use rhinoscript in the environment.

I'm working with Vray Proxies so I can't use grasshopper geometry types. I have to get the GUID and manipulate the rhino object directly or the proxy link gets broken. 

I simply want to copy, scale, rotate, and move the Proxies to some target points. 

in the script there is a bunch of rs.something and those are rhinoscript functions which I didn't think you could call in C# or VB. Please help

Here is the Python Script:

import math
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
sc.doc = Rhino.RhinoDoc.ActiveDoc

if activate:
rs.AddLayer('ProxyScatter')
for i in range(len(rotationAxis)):
ang=rotationAngle[i]
Proxys=proxies[i]
Refs=referencePlanes[i]
axis=rotationAxis[i]
Basepoints=basepoints[i]
print scaleValue
rotates=rs.RotateObject(Proxys,Basepoints,ang,axis, True)
ProxySc=rs.ScaleObject(rotates,Basepoints,scaleValue, False)
rs.ObjectLayer(ProxySc, 'ProxyScatter')
scatters=rs.OrientObject(ProxySc, referencePlanes, targetPlanes,1)
a= scatters
print True
else:
a=""

Views: 1372

Replies to This Discussion

The rhinoscript wrapper is not available for C# or VB, you'll have to use RhinoCommon SDK methods.

What code have you got so far?

I think this is going to work. I haven't tested it on proxy objects yet because I don't have vray on this machine but check it out and see if you think this will do it. It works great for meshes anyway.

if(go)
{
Random rnd = new Random();

for(int i = 0;i < pts.Count;i++)
{
Transform sc = Transform.Scale(Plane.WorldXY, X.ParameterAt(rnd.NextDouble()), Y.ParameterAt(rnd.NextDouble()), Z.ParameterAt(rnd.NextDouble()));
Transform rot = Transform.Rotation(RhinoMath.ToRadians(Rot.ParameterAt(rnd.NextDouble())), Point3d.Origin);
Transform scRot = Transform.Multiply(sc, rot);

Vector3d v = new Vector3d(pts[i] - Point3d.Origin);
Transform mv = Transform.Translation(v);

Guid id = prox[(int) Math.Floor(rnd.NextDouble() * prox.Count)];

Rhino.RhinoDoc.ActiveDoc.Objects.Transform(Rhino.RhinoDoc.ActiveDoc.Objects.Transform(id, scRot, false), mv, true);
}
}

Attachments:

It works. Thanks for the SDK nudge David.

Hey Andy.

Nice script! Im new to coding and I was wondering if you know how to make the proxies move onto the origin points (the points input in your C# component). I would like be able to control the region where the proxies are duplicated onto. 

Regards Jeppe

If your proxies start at the origin of the file (0,0,0) then they will move the destination points you specify from outside the code. Without the proxies at the origin you'll have to specify the start point of the movement vector. This is the line doing the work:

Rhino.RhinoDoc.ActiveDoc.Objects.Transform(Rhino.RhinoDoc.ActiveDoc.Objects.Transform(id, scRot, false), mv, true);

Thanks!! This is amazing.

Im gonna learn to code now ;)

With my last proxy provider (advanced.name) such errors do not occur. Now switched to a new provider with other tariffs, there appeared a similar problem. Do you think that this may be due precisely to the provider?

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service