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

Generating all possible geometries having specific constraints

$
0
0

NicolasM wrote:

Hi,

I a new newbie and wonder if Rhino script (in python) could achieve what I want:

I have a 2d polygon surface (generally 4, 5 sides) and I would like to generate all the possible rectangles having a set of constraints:

  • that fil within the surface of the area
  • having a mininum width/height
  • that touch one or several sides.

  • rendering/visualizing the K generated possibilities?

Is Rhino Script the right tool for that?

Thanks in advances

Nicolas

Posts: 1

Participants: 1

Read full topic


Main Window Form

$
0
0

Bert Gay wrote:

I have a modeless tool window that I want to float on top of the Rhino Main window at all times.

I tried using the form.TopMost property, but realized that this made the dialog sit above EVERY application window even when switching to something other than Rhino.

I have read that the way to do this is to set the Form.Owner property to be the main rhino window, and to this end have tried using the following code:

my_modeless_form.Owner=System.Windows.Forms.Control.FromHandle(rh.RhinoApp.MainWindowHandle())

Unfortunately, this seems to always return None.

I understand that Rhino is built on C++ and not windows forms directly, but is it possible for me to get a .NET Windows Form "version" of the main window?

edit: It seems to work when I do the following:

my_modeless_form.Show(rh.RhinoApp.MainWindow())

Posts: 1

Participants: 1

Read full topic

Autonomous Scripting

$
0
0

David wrote:

DEFINITION
"Self-contained Scripting" or "Autonomous Scripting"
Creating a script which,apart from the initial input, can run to completion
and produce and/or modify an object in a pre-determined manner without additional user input.

(An example of the application of such a script would be to produce a representation of a steel beam.)

PROBLEM:
When trying to use CreateRailRevolvedSurface in the Autonomous Script listed below I get following error message:
"expected Curve, got Guid"
The first two are curves, the third is a line and the fourth boolean?

Parameters required by CreateRailRevolvedSurface
profile: Profile curve for revolution.
| rail: Rail curve for revolution.
| axis: Axis of revolution.
| scaleHeight: If true, surface will be locally scaled.
| Returns: A NurbsSurface or null on failure.

When using AddSweep1 get error message "iteration over non-sequence of type Guid"

Question 1: How do I get Rhino.Geometry.NurbsSurface.CreateRailRevolvedSurface
to function in an Autonomous Script?
Question 2: How do I get rs.AddSweep1 to function in an Autonomous Script?

import rhinoscriptsyntax as rs
import math
import Rhino.Geometry.NurbsSurface as rgns
import System

Length = 20.0
Radius = 3.0
Pitch = 2.0
Turns = 10.0

StartPt = rs.AddPoint(0,0,0)
EndPt = rs.AddPoint(Length,0,0)
RadiusPt= rs.AddPoint(0,Radius,0)

SweepAxis = (StartPt,EndPt)
FullHelixLn=rs.AddLine((0,0,0), EndPt)

plane = (0,3,0)
Outline = rs.AddCircle(plane,0.25)
plane = rs.WorldXYPlane()
plane = (0,0,0)

rs.CurrentLayer( "Layer 04")
Helix_Path = rs.AddSpiral(StartPt,EndPt,Pitch,Turns,Radius,Radius)
rs.CurrentLayer( "Layer 01")

Surface1 = rgns.CreateRailRevolvedSurface(Outline,Helix_Path,FullHelixLn,scaleHeight=False)

Surface2 = rs.AddSweep1(Helix_Path,Outline,closed=True)

Posts: 3

Participants: 3

Read full topic

GetPoint.OnDynamicDraw with shadows

$
0
0

emilio morello wrote:

Hi all,
I'm seeing something unexpected when deriving a class from Rhino.Input.Custom.GetPoint to override the OnDynamicDraw() method.
If the shadows are on, the solids show black sides.

but all is fine without shadows

Here is the sample script that draws the cylinder

import Rhino
import System

def main(): 
  gep = GetPushPullPoint()
  gep.AcceptNothing( True )
  gep.SetCommandPrompt( '... Testing ...' )
  gep.Get()

class GetPushPullPoint( Rhino.Input.Custom.GetPoint ):

  def OnDynamicDraw( self, eventargs ):
    brep = Rhino.Geometry.Brep.CreateFromCylinder(
        Rhino.Geometry.Cylinder( Rhino.Geometry.Circle( 100 ), 100 ),
        True, True )
    color = System.Drawing.Color.Cyan
    eventargs.Display.DrawBrepShaded( 
        brep, Rhino.Display.DisplayMaterial( color ) )

main()

Is there a way to avoid that ?
Am I missing something ?
Thanks

Posts: 1

Participants: 1

Read full topic

Preselection with -_SelLayer _Pick

$
0
0

Silvan wrote:

Hi All,

I have an object preselected. Then I do:
-_SelLayer _Pick
My previously selected object is still selected.
I hit enter.

The selection does not change. I still have the initially selected object selected, but no other objects of the layer got selected. If I select the object inside the command, the other objects of the layer get selected as expected.

I would like the preselected object being used for the -_SelLayer _Pick. Can I adjust the macro to do so or is this not possible?

Thanks

Posts: 6

Participants: 2

Read full topic

Pyhull in rhino python

$
0
0

Poltak wrote:

Hi,

I would love to use the pyhull module in Rhino Python. But after some research I found out that the pyhull module needs the numpy module.
Here is the problem: numpy is not available for Rhino Python anymore, because numpy is not working with Iron Python.
Is that still true?

  1. Is there any other way to implement the pyhull module in Rhino Python?

Thanks a lot

Posts: 3

Participants: 3

Read full topic

CreateRegions in rhinoscriptsyntax

$
0
0

Kasper Steenstrup wrote:

Are there any rs."something" that dose the same as CreateRegions command in rhino?

If not, can I use the command to call the command:

import rhinoscriptsyntax as rs
s = rs.GetObject("Pick a surface")
rs.Command('CreateRegions' + " " + str(s), False) #know that this do not work, just a example

Looking for answer that do not use any manual interaction, other that picking the first surface.

Posts: 3

Participants: 3

Read full topic

Help to get Material Info (RhinoPython)

$
0
0

Jesus_Lopez wrote:

I'm trying to get the notes information from a material applied with Rhino. I tried the next instruction, but I couldn't obtain what do I want

import rhinoscriptsyntax as rs
import Rhino
obj = rs.GetObject('Select object')
index = rs.ObjectMaterialIndex(obj)
print rs.MaterialName(index)
print Rhino.Render.RenderMaterial.Notes

Does anyone could help me to obtain this info?

Thanks for your help

Jesus Lopez

Posts: 1

Participants: 1

Read full topic


Python code does not work correctly!

$
0
0

@zhangvip0755 wrote:

Hi
I am trying to run the following code in PythonScript:
Source: https://developer.rhino3d.com/samples/rhinocommon/add-radial-dimension/

from Rhino import *
from Rhino.DocObjects import *
from Rhino.Commands import *
from Rhino.Geometry import *
from Rhino.Input import *
from scriptcontext import doc

def RunCommand():
rc, obj_ref = RhinoGet.GetOneObject(“Select curve for radius dimension”, True, ObjectType.Curve)
if rc != Result.Success:
return rc
curve, curve_parameter = obj_ref.CurveParameter()
if curve == None:
return Result.Failure

if curve.IsLinear() or curve.IsPolyline():
    print "Curve must be non-linear."
    return Result.Nothing

# in this example just deal with planar curves
if not curve.IsPlanar():
    print "Curve must be planar."
    return Result.Nothing

point_on_curve = curve.PointAt(curve_parameter)
curvature_vector = curve.CurvatureAt(curve_parameter)
len = curvature_vector.Length
if len < RhinoMath.SqrtEpsilon:
    print "Curve is almost linear and therefore has no curvature."
    return Result.Nothing

center = point_on_curve + (curvature_vector/(len*len))
_, plane = curve.TryGetPlane()
radial_dimension = RadialDimension(center, point_on_curve, plane.XAxis, plane.Normal, 5.0)
doc.Objects.AddRadialDimension(radial_dimension)
doc.Views.Redraw()
return Result.Success

if name==“main”:
RunCommand()

Prompt error, because RadialDimension() does not require parameters!
Hint: “Message: RadialDimension() takes no arguments (5 given)”
Is it wrong? How to correct?

thanks!

Posts: 8

Participants: 3

Read full topic

How to compute the normals at vertices of a mesh face in C#

$
0
0

@mahanmotamedi1991 wrote:

Hello everyone,
I have a simple quad mesh face and I want to retrieve the for normals of the vertices (shown in the Image) using c#. I used mesh.NormalAt(x,x,x,x), but this command as output gives me only one normal which seems to be the average of other for normals. Any idea?

Posts: 5

Participants: 2

Read full topic

How to change the style of annotations of several blocks with Python?

$
0
0

@David_B wrote:

Hi,

I’m working on a cleaning script.
My goal is to associate every annotation of my drawing to the “Default” style.

This is the part of the script for simple objects (not in block):

def clean_annotations(annotations):
    annotations_nb=len(annotations)
    for i in range(0, annotations_nb):
        rs.DimensionStyle(annotations[i], "Default")

clean_annotations(dim)

It works : dimensions, texts and leaders style become “Default”.

I want to apply the same thing inside blocks :

blocks_names=rs.BlockNames(sort=False)
blocks_count=rs.BlockCount()

for i in range (0, blocks_count):
    objs_block_id=rs.BlockObjects(blocks_names[i])
    objs_block_nb=len(objs_block_id)
    for j in range(0, objs_block_nb):
        rs.DimensionStyle(objs_block_id[j], "Default")

This one doesn’t work and I don’t know why.

When I debug :

print objs_block_id[j]

… display the GUID (it’s good)…

print rs.DimensionStyle(objs_block_id[j])

… display the style (it’s good) but…

rs.DimensionStyle(objs_block_id[j], "Default")

doesn’ modify the style (it’s not good!).

Thank you!

Posts: 6

Participants: 3

Read full topic

Export selected by automatically using the object name as a file name? Rhino 7 wish

$
0
0

@Rhino_Bulgaria wrote:

Hello, is there a way to do a macro and assign it to a single custom icon, doing the following?
Once I select a group of curves that forms a flat drawing for laser cutting, I need to run these commands all in once to automate the process:

  1. Copying the object name (for example “HL-3-15”).
  2. Export selected (here is the prompt for selecting the file type, where I pick DXF).
  3. Using the copied object name as a file name (should be “HL-3-15.dxf”).

Or, is there a way that in a future release Rhino will have an option to use the object name to export multiple objects depending on their object name? For example, if there are 287 selected objects with 4 different names, Rhino would save 4 new files where the 287 objects were sorted out and allocated depending on their unique object name.

Thanks,

Bobi

Posts: 19

Participants: 4

Read full topic

Find point in a particular distance

$
0
0

@sumuk wrote:

Hi,
Greetings!
I have a problem, I need to find a point in a particular distance

example:
consider a curve which has points on it
image

Consider this point on the curve, lets call A
image

Suppose if i need to find all the points which are at a distance of 8mm to 11 mm, but along the curve like this
image

but though the point D satisfy the condition, I dont want to be my output,
My expected output would be a list [B,C]
image

This article would help to find length of points along curve: Get distance between 2 points on line

My input would be list of guids of all point and guid of point A, expected output to be guid of Point B and Point C

Requesting help from all on the forum

Thanks in advance.

Please find the attachment
curve_with_equidistant_pts.stp (21.3 KB)

Posts: 9

Participants: 6

Read full topic

BoxEdit and Python?

Using Python to set the colour of the largest sphere

$
0
0

@DanBayn wrote:

I’ve got a project that is going to require something like this:

It’s easy enough to find the radii of the spheres, but I’m not sure if there is a fairly straightforward way of separating the largest from the smallest then applying the colour.

Any pointers would be appreciated. In the meantime I’m going to keep trying.

Thanks,

Dan

Posts: 11

Participants: 3

Read full topic


Calculating the distance between all the combinations made by one column by python3

$
0
0

@tinkuhim007 wrote:

I need to calculate the distance between all possible contact points present in the dataframe using python3. My code is working but it is very slow. How to reduce the time?

Condition: If chr string is same in the dataframe. Then distance between all gene will be calculated. Chr1 is present in row Index 1,3,5 so three combination will be made:

1)MK1 MI5 40 (62~17)

2)MK1 MR4 9 (62~51)

3)MI5 MR4 34 (17~51)

Similarly chr2 is present in index 1 and 2. So the only combination will be LC1 LI6 18 (16~34).

INPUT
       chr   st  st1 gene
 0     chr1  62  62  MK1
 1     chr2  16  16  LC1
 2     chr2  34  34  LI6
 3     chr1  17  17  MI5
 4     chr3  15  15  LI6
 5     chr1  51  51  MR4

  OUTPUT
  gene1 gene2  dist
  MK1   MI5    45 
  MK1   MR4    11 
  MI5   MK1    45

data1 = {‘chr’: [‘chr1’,‘chr2’,‘chr2’,‘chr1’,‘chr3’,‘chr1’],
‘st’: [62,16,34,17,15,51],
‘st1’: [62,16,34,17,15,51],
‘gene’:[‘MK1’,‘LC1’,‘LI6’,‘MI5’,‘LI6’,‘MR4’]}
data = pd.DataFrame(data1)
chr = pd.Series(data.chr.unique())

cols = [‘gen1’,‘gen2’,‘dist’]
all_dist_comb = pd.DataFrame()

for chr_num in chr:
for i in range(0,len(data)):
for j in range(0,len(data)):
if i != j and chr_num == data.iloc[i,0] and chr_num == data.iloc[j,0]:
dist = abs(data.iloc[i, 1] - data.iloc[j, 1])
all_dist_comb=all_dist_comb.append(pd.Series([data.iloc[i,3],data.iloc[j,3],dist],index={‘gene1’:‘str’,‘gene2’:‘str’,‘dist’:int}),ignore_index=True)

all_dist_comb=all_dist_comb.reindex(columns=[‘gene1’, ‘gene2’, ‘dist’])
all_dist_comb[‘dist’] = all_dist_comb[‘dist’].astype(int)

print(all_dist_comb)

Posts: 4

Participants: 2

Read full topic

Splitting surface with curves python component in GH

$
0
0

@revink wrote:

Hi all,

I have several surfaces I have to split with curves within a grasshopper python component.
I think I have managed to split them and the result are breps. However, I need these breps inside the component to be surfaces/polysurfaces (I can’t output them and use a different component) but I don’t know how to convert them via script. Possibly due to my limited knowledge of Rhino Common.

See image and script below, should describe better what I am trying to do. Any ideas?

Thanks you so much in advance

  • surfaces contains all surfaces to be split (guids)
  • cuttercurves contains all curves used to split the surfaces (guids)

cut_surfaces_breps = [ ]
for surface in surfaces:

        cutter_elements = [rs.coercecurve(curve) for curve in cuttercurves]
        brep = rs.coercebrep(surface)
        split_brep = brep.Faces[0].Split(cutter_elements, 0.01)
        cut_surfaces_breps.append(split_brep)
  • how do I convert all cut_surfaces_breps to surfaces?

The image belows shows cute_surfaces_breps, but I need this to be as polysurfaces/surfaces within rhino

brep%20resulting

Posts: 2

Participants: 2

Read full topic

PointCloud AddRange

$
0
0

@Mrothart wrote:

Hello,

I am trying to import a pointcloud with a .txt/pts format with x,y,z,r,b,g values using a python script. I am currently using “pc.Add” for each individual point, but I am finding this takes a lot of time for large files (~8 gb) and tends to crash. I am looking to optimize my script by using pc.AddRange instead to bunch and append the points. I am stuck with the formatting of pc.AddRange.

I have read this post:

I am still unfamiliar with how the points needs to formatted. Are they supposed to be in an array format, I.E., “[ x, y, z, r, b, g]”? Thanks for any help.

Posts: 26

Participants: 4

Read full topic

Create linear / rectangular lights in grasshopper!

$
0
0

@arkadius.belov wrote:

Hi all

I am aware that Human has a Light component, but i want to create linear or rectangular lights in gh. Searched through the plugins, and i can’t find anything, maybe there is a way or, maybe someone knows how to iterate this in c# or python.

All help appreciated

thanks

Arkadius

Posts: 9

Participants: 3

Read full topic

ProjectToCPlane command doesn't run on my C# script

$
0
0

@hk1 wrote:

Hi,

I was developing my command to call “ProjectToCPlane” internally but it never get through the command. Feels like I need some special trick before calling ProjectToCPlane… Can you help me out?

        Rhino.DocObjects.RhinoObject recentObject = doc.Objects.MostRecentObject();
        if (recentObject != null)
        {
            recentObject.Select(true, true);
            //bool result = Rhino.RhinoApp.RunScript("_-ProjectToCPlane Yes", true);
            Rhino.RhinoApp.RunScript("! _-ProjectToCPlane _Pause  _Yes", true);
            //r = Rhino.RhinoApp.ExecuteCommand(RhinoDoc.ActiveDoc, "_-ProjectToCPlane _Yes");
            doc.Views.Redraw();
        }

I tried ExecuteCommand, -ReadCommandFile, RunScript and RunScript only showed “_ProjectToCPlane” on prompt but still nothing happens…

While if I type this command(totally same script) manually in Rhino, perfectly works.

Posts: 2

Participants: 2

Read full topic

Viewing all 4152 articles
Browse latest View live