Quantcast
Channel: Scripting - McNeel Forum
Viewing all 5868 articles
Browse latest View live

Load material from file to layer in rhinoscript

$
0
0

How can I load a material from file in Rhino 6+ in Rhinoscript? This is what was working in Rhino4:

Function LoadMaterialToLayer(MatFilename, LayerName)
	Set RDK = Rhino.GetPlugInObject("Renderer Development Kit")
	MatID = RDK.ContentLoadFromFile(MatFilename)
	MatIndex = Rhino.LayerMaterialIndex(LayerName)
	If MatIndex < 0 Then MatIndex = Rhino.AddMaterialToLayer(LayerName)
	LoadMaterialToLayer = RDK.SetMaterialInstanceId(MatID, MatIndex)
End Function

It works so far as loading the material in Rhino 6, but it won’t get assigned to the layer. Instead. an “unnamed” generic material gets created and assigned to the layer. I can manually assign the newly imported material to the layer, so what am I missing? Thanks.

1 post - 1 participant

Read full topic


Purge Layer not working

$
0
0

Hi,

I am trying to use the PurgeLayer function in Rhionscript and it is failing to delete the layer in the screen shot. The layer has children, all of which have geometry in them. I want to delete the geometry, children and the parent layer from the file. Any help would be greatly appreciated.

Eric

image

7 posts - 2 participants

Read full topic

Why Rhino Script Compiler Build the current project errors ?How to solve it?

Get UV plane of Surface using python

$
0
0

Hi I am trying to get the UV plane of a surface using python. Can anyone help?

If I was doing this in grasshopper, I would use the evaluate Surface component, put a uv point of 0.5,0.5, reparametrize the surface, and the plane would come out of the ‘Frame’ output.

I have tried rs.EvaluateSurface, but this only returns a point and not a plane.

Any ideas would be appreciated.
Worth noting that my surfaces are expected to be planar only.

Thanks,
Josh

3 posts - 2 participants

Read full topic

Utilizing Rhino Common SDK with python

$
0
0

Does anyone know how to implement Rhino common methods within python scripts ? I see many interesting methods like Curve.CreateFilletCurves but am not sure how they are implemented and all the examples are in VB or C.

Thanks !

4 posts - 3 participants

Read full topic

Read E57 pointcloud in IronPython

$
0
0

Has anyone found a way to read pointclouds with E57 format in IronPython or C++?

Regards,
Terry.

3 posts - 2 participants

Read full topic

AngularDimension.NumericValue unit

Random points inside box! Looking for ideas

$
0
0

Hi everybody,

I need to recreate a similar behaviour than what the Pop3d (Populate 3d) component does in Grasshopper, but in RhinoPython for a project.
I’m basically looking for a way to populate a box with random, three-dimensional points.

Now, I have no need for perfectly distributed, random sampling, but the formation of too many distinct point clusters should be prevented.

I’ve implemented Poisson Disc Sampling/blue noise sampling before, but in two dimensions? Does anybody know if it scales well into 3D?

Another idea was to subdivide the box into a three-dimensional grid of sub-regions, corresponding to the total number of sample points. Each 3D cell would contain a single point that could be jittered for randomness. I guess a neat by-product here would be the tree-like data structure that would make nearest neighbour searches fast and easy.

What do you think? Have you come a cross something more straightforward?
Any suggestion?

8 posts - 5 participants

Read full topic


Import options C#

$
0
0

Hi,

With C # I am trying to import a sketchup file with:

Rhino.RhinoDoc doc = Rhino.RhinoDoc.CreateHeadless (null) ;;
doc.Import (“Sample.skp”);

The problem I am dealing with is that I cannot specify the import options:
afbeelding

Does anyone know how I can set/modify these options in C#?

3 posts - 2 participants

Read full topic

Subd Toggle state

$
0
0

Is there a way to see what the current subD display state is? If it’s either flat or smooth. I have a script I use for the various points on commands and I would like it to use PointsOn when in flat mode and EditPtOn when in smooth but have been unable to find a way to check the subd display state.

Thanks for any pointers.

2 posts - 2 participants

Read full topic

C# modifying a List within a loop?

$
0
0

Hello! This is some test code for and agent based script. The problem is I can’t .Add () to the list of agents after I first declare and populate it. I don’t get an error, but no output is generated. The problematic line (73 in the editor) is commented out. What am I doing wrong here?

Agentes.gh (9.3 KB)

---------------------------------- code: -----------------------------------------------

private void RunScript(List<Point3d> AgLoc, List<Vector3d> AgDir, int steps, ref object A) {
    List<Agent> agents = new List<Agent>();
    List<Polyline> trails = new List<Polyline>();
    Random rnd = new Random();
    Point3d pt = new Point3d();

    for (int i = 0; i < AgLoc.Count; i++){
      agents.Add(Agent.Spawn(AgLoc[i], AgDir[i]));
    }

    for (int i = 0; i < steps; i++){
      foreach (Agent ag in agents){
        ag.Move(Vector3d.ZAxis);
      }

      //spawn a radom agent each step (not working)
      pt = new Point3d(rnd.NextDouble(), rnd.NextDouble(), 0);
      //agents.Add(Agent.Spawn(pt, Vector3d.ZAxis));
    }

    foreach(Agent ag in agents){
      trails.Add(ag.Trail());
    }

    A = trails;
  }
public class Agent {
    //fields
    public Point3d Location;
    public Vector3d Direction;
    public List<Point3d> Hystory = new List<Point3d>();

    //constructors
    public Agent(){
      this.Location = new Point3d();
      this.Direction = new Vector3d();
    }

    public Agent(Point3d loc){
      this.Location = loc;
      this.Direction = new Vector3d();
    }

    public Agent(Point3d loc, Vector3d dir){
      this.Location = loc;
      this.Direction = dir;
    }

    //methods
    public static Agent Spawn(Point3d loc){
      Agent ag = new Agent(loc);
      return ag;
    }

    public static Agent Spawn(Point3d loc, Vector3d dir){
      Agent ag = new Agent(loc, dir);
      return ag;
    }

    public void Move(Vector3d dir){
      this.Hystory.Add(this.Location);
      this.Location = this.Location + dir;
    }

    public Polyline Trail(){
      Polyline poly = new Polyline(this.Hystory);
      return poly;
    }
  }

5 posts - 3 participants

Read full topic

Need help with python component

$
0
0

i have made thes two adjustable lofts and now I would like to add a top and a bottom surface. These surfaces should be made from the edges of the two lofts.

  1. how do I get these two surfaces?

  2. how do I get the closed volume of all 4 surfaces?

thx 4 help

4 posts - 2 participants

Read full topic

Identifying object from string

$
0
0

I have some objects stored in UserText in another object. These are saved as strings. How do I treat this a an actual object later on, when retrieving it from GetUserText, and not just a list of characters? I want to be able to traverse the object(s) with a for-loop.

Thank you!

4 posts - 2 participants

Read full topic

Render & Volume Python

$
0
0

Hi, Does anyone know of a python code that can open rhino on a networked machine, calculate the volume of a jewellery model and then send it to a render farm code to render in different materials. A long shot I know but must be such a code out there. Thank you in a dvance

1 post - 1 participant

Read full topic

Adding x amount of lines

$
0
0

Hi there

I’m currently working on a simple alignment script that is pretty similar to PerspectiveMatch for when we have a photogrammetry model of a site and a satellite photo. What I’d like to do is to set a x amount of vectors between points on the Photogrammetry mesh and between the Satellite photo and then calculate the average of all the vectors and to move the mesh accordingly, this would allow for a slightly better alignment than by doing it by eye as we currently do.

I’ve run into two issues within this.

  1. How do I create an average vector from a list of vectors?
  2. How do I make it possible for the user to set x amount of vectors, preferably live, like in PerspectiveMatch

Here’s where I’m at currently:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
import math

drone = rs.GetObject("Select Mesh")
num = 3

vecPairs = []

for x in range(num):
    line = rs.GetLine(1,message1 = "Select Point on Mesh", message3 = "select Point on SAT")
    vecDir = line[1] - line[0]
    vecPairs.append(vecDir)


trans  = sum(vecPairs) / ln(vecPairs)

rs.MoveObject(drone, trans) 

1 post - 1 participant

Read full topic


Ascii codec can't decode character

$
0
0

Hi everyone.
We are receiving more and more files that contain fonts in the layers names or in the file name that cause me this message:


Do you have any solution to avoid this?

6 posts - 4 participants

Read full topic

Modify Instance Definition Slow

$
0
0

Using the, InstanceDefinitions.ModifyGeometry() to modify multiple blocks with python in a command. sometimes it is very fast and other times it is very very slow. Are there any tricks or tips to improve performance? Thanks!

1 post - 1 participant

Read full topic

Variable Curve.OffsetOnSurface

$
0
0

Documentation states that since Rhino 5 there is an overload method to offset a crv on a surface, by variable distances:

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Curve_OffsetOnSurface_2.htm

@piac , @dale , @stevebaer Is it possible to provide a small sample code? C#/VB/python?

What I am struggling to understand is ‘curveParameters’ array input.

Attached is an example surface with its border crv.
srf_example.3dm (31.9 KB)

As a workaround I can use the basic method and offset each crv’s segment individually, then split it with other segment offsets in order to get the final offset of the initial crv. But I am interested if this can be done instead with the upper overload.

Thank you in advance for any help.

1 post - 1 participant

Read full topic

Python message error

$
0
0

hello!!!
what does mean:
image ,

when i launch the python script from the Python editor, the script run, but from the button with ! _-RunPythonScript “script.py” it give this message…

1 post - 1 participant

Read full topic

IsVectorParallelToPlane

$
0
0

what is the simpler way to verify if a vector or a line is parallel to WorldXYPlane?

i Can substract Z coordinates of the start and the end point of the line, if it’s equal to 0 the line is parallel.

5 posts - 3 participants

Read full topic

Viewing all 5868 articles
Browse latest View live