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

Python script not updating on Rhino

$
0
0

@falola.yusuf wrote:

Hi all

Rhino doesn’t update changes I make on my Python scripts not until I close and re-open Rhino before the changes are recognized. Any possible solution to this?

Thanks

Posts: 3

Participants: 2

Read full topic


PointCloud commit changes (or replace) causes RAM usage creep?

$
0
0

@nathancoatney wrote:

I am building large-ish point clouds and updating the document periodically to show progress. I have noticed Rhino using excessive RAM if I use Rhino.DocObjects.RhinoObject.CommitChanges() (also scriptcontext.doc.replace()). The RAM creeps up as the point cloud is updated, and is never recovered after the script completes, or even if everything is deleted from the document.

This script demonstrates the behavior using two different methods to build the point cloud. Run either function and watch RAM. I’m hoping someone can give me a hint on what is going on. If not I’ll try a conduit.

Thanks.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as R
import random

def make_sub_pc(count=100):
    sub_pc = R.Geometry.PointCloud()
    for _ in range(count):
        sub_pc.Add(R.Geometry.Point3d(random.random(), random.random(), random.random()))
    return sub_pc
    
def add_by_range(pc, count=100):
    point_collection = R.Collections.Point3dList()
    for _ in range(count):
        point_collection.Add(random.random(), random.random(), random.random())
    pc.AddRange(point_collection)

def test_sub_pc_commitchanges(n=1000):
    pc = R.Geometry.PointCloud()
    pc_guid = None
    pc_robj = None
    for i in range(n):
        if sc.escape_test(False, False):
            break
        R.RhinoApp.Wait()
        sub_pc = make_sub_pc(1000)
        if not pc_robj:
            pc.Merge(sub_pc)
            pc_guid = sc.doc.Objects.AddPointCloud(pc)
            pc_robj = sc.doc.Objects.Find(pc_guid)
            sc.doc.Views.Redraw()
        else:
            pc_robj.Geometry.Merge(sub_pc)  # if use pc.Merge() here then CommitChanges doesn't work.
            print pc_robj.CommitChanges()
            sc.doc.Views.Redraw()
        sub_pc.Dispose()  # doesn't seem to matter
        
def test_addrange_pc_commitchanges(n=1000):
    # this still causes memory creep, so must not be the sub point cloud object hanging around.
    pc = R.Geometry.PointCloud()
    pc_guid = None
    pc_robj = None
    for i in range(n):
        if sc.escape_test(False, False):
            break
        R.RhinoApp.Wait()
        
        if not pc_robj:
            add_by_range(pc, 100)
            pc_guid = sc.doc.Objects.AddPointCloud(pc)
            pc_robj = sc.doc.Objects.Find(pc_guid)
            sc.doc.Views.Redraw()
        else:
            add_by_range(pc_robj.Geometry, 100)
            pc_robj.CommitChanges()
            sc.doc.Views.Redraw()
        

# choose one or the other

#test_sub_pc_commitchanges()

test_addrange_pc_commitchanges()

Posts: 4

Participants: 2

Read full topic

Change "Display Colour" to "By Parent" within multiple files Via Script

$
0
0

@leigh.anderson wrote:

Hi,
I am new to Rhino and I am looking for some assistance.
I’ve got 1489 Library items which have “Display Colour” set to “By Layer”, when I insert any of these items into a model as a block they keep their original colour. I was hoping that someone may have a script which will run through all the Library files and change “Display Colour” to “By Parent”.

Many thanks
Leigh

Posts: 14

Participants: 4

Read full topic

Getting a component to watch a point

$
0
0

@matthewaustin233 wrote:

Bit obscure, but how does the point parameter component actually work?

i’ve got a point in Rhino and I have a python component that queries it and returns its attributes - however, when the point is moved or changed, this doesn’t signal the component to recompute - which makes sense, cause I haven’t asked it to. Is there a way to do this?

I.e. Is there a way to embed the point parameter components ‘listener’ functions in a custom python component?

Thanks in advance.

Mattew.

Posts: 5

Participants: 3

Read full topic

Count self intersection for a curve Grasshopper/Python

$
0
0

@claire.dumont wrote:

Hi everyone,
I’m trying to find the number of occurrences of self-intersections for a curve in Grasshopper but I don’t understand why some points aren’t taken into account in my occurences list.
I used Curve|Self (CX) to find the intersections and then count() in Python. For instance, points “2”, “15” and “37” are the same, but, python find 1 occurence for point 2 and two occurences for 15 and 37 (and not 3 for the three points !).
Do you know this problem?
How do I find the self intersection of the curve and right occurences by using Grasshopper and/or Python?

Thank you

!grasshopper2|690x368](upload://kdYbAhSKx9hg44OeXHMavWAWH6E.jpeg)

Posts: 2

Participants: 2

Read full topic

Save multiple file to Rhino 5

$
0
0

@banati.bodo wrote:

Hi there!
I’m totally new with rhino/pythonscript, apologies if i ask something obvious.
My problem is the following:
i have a grasshopper file, and in the end i bake multiple objects into different .3dm files with lunchbox.
the problem is, i need these files to be in rhino 5 version instead of rhino 6. i found no solution for this in grasshopper, so i figured it may could be solved with rhinoscript.
it should open files from a folder, and save them as version 5 .3dm.
is it possible to do this in rhinoscript / pythonscript? can someone point me in a direction to start with this?
thanks in advance

Posts: 3

Participants: 2

Read full topic

Laying out contours for laser cutting with Python

$
0
0

@lmboyer04 wrote:

So I’m still fairly new to this all so pardon if I’m asking bad questions. I’m using Rhino Python Editor and I’m trying to create a script (while also learning to script a bit) that will essentially contour any closed polysurface model at an interval of choice, Orient the curves to the C plane or some other plane so they are all together (as if I ran Make2D) and then arrange them so that they are in a line, in order, with a small gap between them.

It gets really messy with the whole organizing of object IDs in the big for loop… I gave it a shot tho.

I can already see there are some sloppy workarounds not to mention just some stuff that just isn’t working… but I just dont know the alternatives. Please provide any ideas you have for bridging the gaps and/or cleaning it up

Thanks so much!

edited with updated script
Contour Model Updated 1.py (1.2 KB)

Posts: 9

Participants: 5

Read full topic

Python Script for AddPolygon?

$
0
0

@lbrooks wrote:

I’m just getting started with rhinoscriptsyntax, and I’m wondering how come there isn’t a function for AddPolygon like there is for AddRectangle and AddEllipse? Am I missing something?

If there isn’t a native function in the library, has anyone written a script for this? (Yes, I am lazy).

Thanks a lot!

Posts: 3

Participants: 2

Read full topic


Brep Center Point in Grasshopper-Python?

$
0
0

@kai.yeh wrote:

Hello guys,

I’m wondering to know if there is any method to get the centre point of a brep in python?
Thank you very much!

Posts: 4

Participants: 3

Read full topic

Grasshopper Python SubD script (got getsetter_descriptor)

$
0
0

@h.h.c.manders wrote:

Hey all,

I have been playing around with Rhino 7 and it’s SubD possibilties. To make the modeling easier I have been trying out to generate the SubD from a mesh through Grasshopper python. One of the functions within Rhino ToSubD is to InterpolateMeshPoints. I wanted to try this within Grasshopper as well however when I define the SubDCreationOptions and call InterpolateMeshVertices I get a getsetter_descriptor error.

Specifically:

Runtime error (ArgumentTypeException): expected SubDCreationOptions, got getset_descriptor

Script:

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg

geometry = rs.coercemesh(x)
options = rg.SubDCreationOptions.InterpolateMeshVertices

a = rg.SubD.CreateFromMesh(geometry, options)

Any one has experience with this?

Posts: 2

Participants: 2

Read full topic

Split rectangle into four pieces

$
0
0

@falola.yusuf wrote:

Hello,

How can I split a rectangle I created using rs.AddRectangle into four pieces? I want to get a different GUIDs for each line.

Thanks

Posts: 3

Participants: 2

Read full topic

Grasshopper python question DataTree with integer

$
0
0

@kai.yeh wrote:

Hello all,

I’m wondering to know how to define integer,float,strings in python DataTree construction?
For instance, I was trying to put a integer in a tree, but what syntax should I fill in the "[ ] "
I tried string, Rhino.Geometry, rhinoscriptsyntax, but could’nt find a proper one

import string
import Rhino.Geometry
import rhinoscriptsyntax

myTree = DataTree

Thank you very much!

Posts: 2

Participants: 2

Read full topic

How to selected curve on surface?

Python Simple problem boolean difference loop

$
0
0

@a.elshafei wrote:

Dear All,

I have a quesition but I don;t have deep experience with python. I have some elements and i want to do boolean differene with main object but in a loop way so all of them in a list and the computer do one by one.

similar to the picture the red in one list and the black is the part that i want to be the main.
image

so can you please help me to write this code.

Regards,
Ahmed Elshafei

Posts: 2

Participants: 2

Read full topic

Slicing a list at integer of when an element is different from the previous

$
0
0

@aeaechan96 wrote:

0

I need to be able to slice a list of points into multiple sublists, to act as a guide for slicing another list.

My list right now is y_vals = [a,a,a,a,a,a,b,b,b,b,b,b,b,b,b,b,b,c,c,c,c,c…] and I need it to slice every time the number changes. a, b and c are actual numbers, but the numbers are rather long, so I typed it out in a,b,c.

I wanted to use the slicing method of [:x], but it’s a list of 5000 over numbers, and I’m not sure how to slice a list. Thank you in advance!

Posts: 8

Participants: 4

Read full topic


How can I move a point through out a custom plane's z axis

$
0
0

@joantomass wrote:

Hi all,

I’m quite new on python scripting and I’m getting stuck with the tansformations, since I’m trying to move a point though a custom plane’s z axis to make then a line and I have no clue on how to manage the transformation.
I know how to do it with gh components, I just deconstruct the plane and then move the point applying the “amplitude” component through the z vector, but how can I translate that to python ?
I’ve been searching in the forum and it seems to me is not an easy thing.
Can someone explain that for a gh python rookie?

Thanks in advance ,

Joan

Posts: 3

Participants: 2

Read full topic

3 "toolbar" methods obsolete

$
0
0

@KeithR wrote:

These rhinoscript methods are all in the V6 autocomplete library, however they throw out an error message when run:

The “IsToolBarVisible” method is obsolete.Command
The “IsToolbarDocked” method is obsolete.Command
The “ShowToolBar” method is obsolete.Command

regards,

Posts: 1

Participants: 1

Read full topic

Delete all objects on Rhino workspace

$
0
0

@falola.yusuf wrote:

Hi all,

I want to do some simulation on Rhino, so I want to delete all objects on the workspace after every iteration.

Please, How can I do this?

Thanks

Posts: 4

Participants: 2

Read full topic

How can compare different of objects?

ObjectClash only working for extrusions

$
0
0

@JoshLobel wrote:

I’m trying to adapt the example ObjectClash script - Rhino3d Object Methods - Object Clash - but the only geometry type that I can get to work are Extrusions. I’ve tried adjusting the geometry type filter, but with no success. Wondering if anyone has insight on how I can get this to work with closed polysurfaces or other geometry? Thanks.

Current script (i’ve left commented out lines to show a couple options i’ve tried):


Sub Main()
	'Const rhSurface = &h8
	Const rhSurface = 8
	
	'Const rhPolysrf = &h10
	Const rhPolysrf = 16

	'Const rhMesh = &h20
	Const rhMesh = 32

	'Const rhExtrusion = &h40000000
	Const rhExtrusion = 1073741824

	Dim arrObjects0, arrObjects1, intFilter, arrEvents, arrEvent, strClash1, strClash2

	intFilter = rhSurface + rhPolysrf + rhMesh + rhExtrusion

	'arrObjects0 = Rhino.GetObjects("Select first set for clash detection", 0)
	arrObjects0 = Rhino.GetObjects("Select first set for clash detection", intFilter)

	'arrObjects1 = Rhino.GetObjects("Select second set for clash detection", 0)
	arrObjects1 = Rhino.GetObjects("Select second set for clash detection", intFilter)

	arrEvents = Rhino.ObjectClash(arrObjects0, arrObjects1, 0.25)

	If IsArray(arrEvents) Then

		For Each arrEvent In arrEvents

			Call Rhino.AddPoints(arrEvent(2))
			strClash1 = arrEvent(0)
			strClash2 = arrEvent(1)
			'Rhino.MessageBox "Clash found between " & Rhino.ObjectName(strClash1) & " and " & Rhino.ObjectName(strClash2)
			Rhino.Print "Clash found between " & Rhino.ObjectName(strClash1) & " and " & Rhino.ObjectName(strClash2)

		Next
	Else
		Rhino.MessageBox "A problem occurred with the clash array, most likely you've selected and object type that the script doesn't like (ie closed solid polysurface)"

	End If 
End Sub

Posts: 1

Participants: 1

Read full topic

Viewing all 4050 articles
Browse latest View live