Quantcast
Viewing all 5749 articles
Browse latest View live

RhinoScript Debugging error

@ezgikd wrote:

I am using Rhinoceros 5.0 with educational lab license. When I try to use debug the script button, I always get the same error in the following example. It gives error only when I use if statement. When I do not use if statement, debugger works well.

Here is the code that I copied from the help box examples, so there should not be any error but when I put a breakpoint and debug the script I get the following error. Thank you for your help in advance.

Option Explicit

Call Main()
Sub Main()
	Dim dblRadius, arrPoint

	dblRadius = Rhino.GetReal("Radius of new circle", 3.14, 1.0)

	If Not IsNull(dblRadius) Then

	arrPoint = Array(0, 0, 0)

	Rhino.AddCircle arrPoint, dblRadius

	End If

End Sub

Image may be NSFW.
Clik here to view.

Posts: 1

Participants: 1

Read full topic


Error when intersecting in a specific coordinate

@Charly wrote:

Hello all,
I'm working on a script that creates many vertical planes, intersect each of them with a surface, and then delete the part of the plane that is outside de surface, so the objective is to divide the internal part of the surface (for example an sphere) in many sections.
The script works properly, but if we want to create the vertical plane in the coordinate y = 2, it doesn't work. It only happens with y = 2, for the rest of positions of "y", it works correctly, and the code is exactly the same for each coordinate we introduce.
I think this is very very strange but, does anyone know which could be the problem? Thank you very much

Posts: 6

Participants: 2

Read full topic

Python Equivalent of Cut Plane Command

@rleader wrote:

Does anyone know a quick, reiterable way to generate a surface at the intersection of a plane and lofted surface?

Essentially i'm looking to determine the cross-sectional area along an airplane at various stations which I would define the location of.

Any help would be appreciated, Thanks!

Posts: 2

Participants: 2

Read full topic

SelBoundary RVB Script to PY Help

@kleerkoat wrote:

I have a script @Helvetosaur kindly made for me that would be awesome if someone could help me with a python version.

It takes a picked curve and selects any curves inside and groups them with the picked curve.

Option Explicit
'Script by Mitch Heynick
'Version Wednesday, 10 November, 2010

'Call SelBoundaryForRyan()
Sub SelBoundaryForRyan()
	Dim arrSel,arrObjs,strGroup,msg,strBC
	arrSel=Rhino.SelectedObjects
	msg="Select closed curve to use as a selection boundary within the viewport"
	strBC = Rhino.GetObject(msg, 4,, True)	
	If IsNull(strBC) Then Exit Sub
	Call Rhino.EnableRedraw(False)
	Call Rhino.UnselectAllObjects

	Call Rhino.Command("_SelBoundary _SelectionMode=_Window _SelID "&strBC,False)
	arrObjs=Rhino.SelectedObjects
	
	If IsArray(arrObjs) Then
		strGroup=Rhino.AddGroup
		Call Rhino.AddObjectsToGroup(arrObjs,strGroup)
		Call Rhino.AddObjectToGroup(strBC,strGroup)
		Call Rhino.ObjectsByGroup(strGroup,True)
		If IsArray(arrSel) Then Call Rhino.SelectObjects(arrSel)
	End If
	Call Rhino.EnableRedraw(True)
End Sub

Posts: 3

Participants: 2

Read full topic

Help with PythonScript

Material Name [Beginner]

@Maxence wrote:

Hello !

I'm completly new to python Scripting, and I'm trying to rename all my textures with a shortest name.

so far I have:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext
import System.Drawing

#I  don't understand what I should place here :arrow_down:
mat = scriptcontext.doc.Materials.Find(self.MaterialTable, materialName="complexe name material")

if mat 

    rs.MaterialName(mat,"1")`

As I said I'm a total beginner. I don't understand what the first argument should be in the Materials.Find()

Thank you.

Kind regards
Maxence

Posts: 1

Participants: 1

Read full topic

Rhino python language highlighting?

Rhinocommon strategy for auto-sorting Polyline Through Points?

@NikWillmore wrote:

Problem detailed here:

http://www.grasshopper3d.com/forum/topics/point-sorted-rhinocommon-version-of-rhino-polyline-through-points

"I'm converting Tetgen program 3D Voronoi diagrams faces to meshes in Python/Rhinocommon. However, unlike the Rhino Polyline Through Points command that automatically sorts the points to always give a single non-overlapping closed loop, Rhinocommon only seems to have a generic Polyline structure that fails to sort the points, so my unordered input points are giving self-overlapping curves that can't then be converted to mesh faces.

Must I use Python to sort the points around their center using math? Or does Rhinocommon have a trick or two to do this for me? Each group of points are coplanar, albeit at various 3D angles.

I'm disappointed in Rhinocommon today since I can't use Rhino power commands now that I sadly realize the Tetgen tetrahedral mesh generator binary is not offering ordered points, just a list of lines I have to extract endpoints from and cull duplicates.
Just a "clockwise" sorting function would do.

The Grasshopper Polyline component also fails to sort the points so I can't use node-in-code for that. I must use several components, to fit a circle then sort points along curve, which is a lot of Grasshopper binding I may wish to avoid."

Posts: 2

Participants: 2

Read full topic


GetEdgeCurves Hangs with transform message

@Keith1634 wrote:

This Rhinoscript code will hang a while

Dim arrEdges
arrEdges = Rhino.GetEdgeCurves(,,, True)
rhino.command "_ProjectToCPlane _Yes"

Is there a better route ?

Thx,
Keith

Posts: 4

Participants: 3

Read full topic

Quicker Block Select Instances

@benjamin wrote:

My current method for quickly selecting all the instances of a selected block is by bringing up the block manager and then hitting the select button.

Is there a method that could be written which does this quicker? Bringing up the block manager is quite time consuming once the model builds up.

Of course there is SelBlockInstanceNamed but scrolling through the names to remember which one you want is also not ideal.

So the logic would be something like: (Prompt user to select block) ▶ Select all items with reference block ID ▶ return selected Blocks

Would also be good if it could work with multiple selections of block instances

Any ideas?
Cheers

Posts: 3

Participants: 2

Read full topic

Remove UTF8_BOM from txt file

@Keith1634 wrote:

Hi,

I am reading a text file to feed a Rhino.ListBox - however I always get a UTF8_BOM (  ) mark on the first line. Is there a way to remove this ?

thanks,
Keith

Posts: 3

Participants: 2

Read full topic

RemoveMultiKnot scripted

Background screen capture thread

@amit.lzkpa wrote:

Hi,

Is there a way to start a background thread that continually performs screen grab and pushes the screen grab to a socket?

I am currently working in RhinoPython.
Following is a part of what I have:
`


import Rhino
RhinoDocument = Rhino.RhinoDoc.ActiveDoc
view = RhinoDocument.Views.Find("Perspective", False)

width = 1080
height = 720
size = System.Drawing.Size(width,height)`

def updateOneSecond():
    frames = 75                     # i am targeting 75 fps, on a gaming rig
    for i in range(frames):
        capture = view.CaptureToBitmap(size)
        # the save to file is just hold in function
        # I want to stream it without storing it
        file_name = "E:\\....\\cap" + str(cyc) + str(i) + ".bmp"
        capture.Save(file_name)
    print("Process complete")

This is a demo example, where I am writing the screen capture to a file. For my actual use, I plan to set up a continuous loop, which performs the screen grab and serves the bitmap as a server to a socket address and another application(an Oculus) will be listening to that address and collect the bitmap data.

It is important to hand the control back to the user for working normally with the file. So I figured the continuous loop should be ideally located on a parallel thread.

I came across the following parts which I believe may be a solution, but I have no clue what exactly they do and the documentation didn't covered them in much detail.


# the ForEach method kept asking for a thread as the first argument
# i am not sure how do I create a new thread and pass it to that method
import System.Threading.Tasks as tasks
tasks.Parallel.ForEach(<some thread name>, updateOneSecond())

# Thread has some methods under it, which sound relevant with method names like
# 'Invoke', 'Start', 'IsBackground', but I don't know to use them.
from System.Threading import Thread, ThreadStart, ParameterizedThreadStart

Also, I came across posts which documented that document methods can't be accessed from parallel threads, but there seems to be an ugly hack for it.
It's in C# I think, and I am having tough time figuring it out.
Ugly hacks will work for me for the time being.

Any help will be appreciated.
Thanks.

Posts: 1

Participants: 1

Read full topic

Combine flags into one hexadecimal value - how?

@Jarek wrote:

Hi Group,

Is there a way to easily represent a combination of flags (for example for object types in ObjectsByType method) into a single hexadecimal value that can be provided into the method?
For example, I want 4+8+16 - can I instead provide a single &H... value for that combo?

--jarek

Posts: 7

Participants: 3

Read full topic

How to convert an RGB color value to grayscale in python inside GH?

@daizhuo wrote:

Hi!
Although I finally found that someone said "grayscale = RGB.R*0.3+RGB.G*0.59+RGB.B*0.11", but it seems not work. I had tomultiply 0.007 and got a result that seems grayscale was form 0 to 1. Here is my code:

import rhinoscriptsyntax as rs
import math
import System as sys
import Rhino.Geometry as rg
import scriptcontext as sc

path = path
bitmap = sys.Drawing.Bitmap.FromFile(path)
width = bitmap.Width
height = bitmap.Height

unum = 20
vnum = 20
uinc = 1.0/unum
vinc = 1.0/vnum

imageW=width/unum
imageH=height/vnum

panels=[]
temp=[]
for i in range(unum):
for j in range(vnum):
valRGB = sys.Drawing.Bitmap.GetPixel(bitmap,i*imageW,j*imageH)
val = (valRGB.R*0.3+valRGB.G*0.59+valRGB.B*0.11)*0.007

    pt1 = srf.PointAt(i*uinc,j*vinc)
    pt2 = srf.PointAt((i+1)*uinc,j*vinc)
    pt3 = srf.PointAt(i*uinc,(j+1-val)*vinc)
    pt4 = srf.PointAt((i+1)*uinc,(j+1-val)*vinc)

    panel = rg.NurbsSurface.CreateFromCorners(pt1,pt2,pt4,pt3)
    panel2= rg.NurbsSurface.CreateFromCorners(pt1,pt2,pt4,pt3)
    center = srf.PointAt((i+0.5)*uinc, (j+0.5)*vinc)
    normal = srf.NormalAt((i+0.5)*uinc, (j+0.5)*vinc)

    panel = rs.RotateObject(sc.doc.Objects.AddSurface(panel),center,val*math.pi*4,normal)

    panels.append(panel)

a = panels

Posts: 3

Participants: 2

Read full topic


Silent Execution

@Alexander_Kaplan wrote:

I'm using a slightly modified version of http://wiki.mcneel.com/developer/scriptsamples/exportlayerobjects for a mass fbx export but have to hold down enter for a minute while it exports. Silly. Is there a reason the "-" flag on Export wouldn't work?

Snippet with the rhino command

If IsArray(arrSelected) Then

		' Generate a modified path string
		' that includes the layer name
		strFile = strPath
		strFile = Replace(strFile, ".3dm", "_" & strLayer & ".fbx")
		' strFile = strLayer & ".fbx"

		' Export the selected objects
		Rhino.Command "_-Export " & strFile, 0

	End If
Next

Posts: 7

Participants: 2

Read full topic

Surface from points

@daizhuo wrote:

In the below code"panel = rg.NurbsSurface.CreateFromPoints(cpts,2,vnum2,2,2)", I want to generate a surface with 1 degree from points. But now, I get a wrong thing.
Thx for ur help!

import random as rnd
import Rhino.Geometry as rg

uinc = 1/unum
vinc = 1/vnum

panels = []

for i in range(unum):
    for j in range(vnum):
        vlen = rnd.randint(1,10)
        if j + vlen > vnum:
            vlen = vnum - j
        cpts = []
        depth = rnd.randint(0,1)
        for k in range(vlen+1):
             cpts.append(srf.PointAt(i*uinc, (j + k)*vinc))
             cpts.append(srf.PointAt((i+1)*uinc, (j + k)*vinc))
        vnum2=int(len(cpts)/2)
        panel = rg.NurbsSurface.CreateFromPoints(cpts,2,vnum2,2,2)
        panels.append(panel)

a = panels

Posts: 4

Participants: 2

Read full topic

RS: StringBox - control position on screen?

@Jarek wrote:

Is there a way I could control the position of StringBox dialog on the screen?
(similar way the PopUpMenu allows). I know there is no direct way in the method (could we add it as optional argument for future?) but I thought maybe the last position is stored somewhere in the registry or other place I could access and modify ?

thanks,

--jarek

Posts: 8

Participants: 2

Read full topic

PlaneFitFromPoints

@gianpaolo_savio1 wrote:

I’m trying the rs.PlaneFitFromPoints function.
Using the example in the RhinoPython Help:

    import rhinoscriptsyntax as rs
    points = rs.GetPoints()
    if points:
        plane = rs.PlaneFitFromPoints(points)
        if plane:
            magX = plane.XAxis.Length
            magY = plane.YAxis.Length
            rs.AddPlaneSurface( plane, magX, magY )

an error occurred:
Message: 'type' object has no attribute 'index'
Traceback:
line 402, in coerce3dpointlist, "C:...\utility.py"
line 119, in PlaneFitFromPoints, "C:...\plane.py"
line 5, in , "C:...\TempScript.py"

Posts: 4

Participants: 2

Read full topic

BrepBrep intersection not threadsafe in Rhino 5 64bit?

@SmallChief wrote:

Using the Grasshopper python component I wrote a code that intersects lots of breps with each other.
To make it faster I used parallel processing wich worked fine under Rhino 5 32bit, on a 64bit Rhino the component crashes my whole Rhino instantly.

The function used was Rhino.Geometry.Intersect.Intersection.BrepBrep()

Is this function not threadsafe?

Posts: 3

Participants: 2

Read full topic

Viewing all 5749 articles
Browse latest View live