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

How to make a ghpython component to open a form with double click on the component

$
0
0

@alexholden18 wrote:

Hi guys,

I am looking for a way to open an eto form with double click on a ghpython compiled component.
Any ideas are appreciated.

Thanks,
Alex

@piac

Posts: 2

Participants: 2

Read full topic


Is is possible to run Grasshopper in other IDEs like PyCharm?

$
0
0

@eduszh wrote:

Hello developers @piac,

I am not a big fan of the RhinoPythonEditor, so I am wondering if it is possible to let PyChamr do the same job? I followed the directions outlined in the following post:

However, when I run:

from Rhino import RhinoApp, RhinoDoc
gh = RhinoApp.GetPlugInObject("Grasshopper")

I get:

    "C:\Program Files\IronPython 2.7\ipy.exe" E:/TEST_PROJECT_PYCHARM/TEST
    Traceback (most recent call last):
      File "E:/TEST_PROJECT_PYCHARM/TEST", line 6, in <module>
    SystemError: Unable to load DLL 'rhcommon_c': A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)

    Process finished with exit code 1

May I know if this error is solvable?

Thanks

Posts: 2

Participants: 2

Read full topic

How to choose multiple edges?

How to unregister a python command

$
0
0

@cokepe wrote:

Hello
I´m getting this error. I know why happened, I change the name of the file command, so now rhino can´t find it.
image

The question is how can I fix this, so Rhino is able to find the correct file.
And also related, how do I delete a command…

Thanks.

Posts: 1

Participants: 1

Read full topic

Trying to Delete selected Extrusions

$
0
0

@dylanbahnan wrote:

Hi, I’m sure this is a very basic question but I can’t seem to figure it out. I’m trying to modify an existing script to delete the extrusions from groups after it’s converted them from blocks (I’m using Dale Fugiers Script). At the moment it will convert the blocks to groups but then it deletes everything. Any help is appreciated. Here’s what I’ve got.

’ Local variables
Dim arrBlocks, strBlock, arrObjects(), nBound, strObject, arrExtrusions

’ Get blocks to explode
arrBlocks = Rhino.GetObjects(“Select blocks to convert”, 4096, True, True)
If IsNull(arrBlocks) Then Exit Sub

’ Explode the blocks
For Each strBlock In arrBlocks
’ Reset our array of objects
ReDim arrObjects(-1)
’ Explode the block
Call BlockExplode(strBlock, arrObjects)
’ See if any objects were added to our array
On Error Resume Next
nBound = UBound(arrObjects)
If (Err.Number = 0) Then
’ Group the objects
Call Rhino.AddObjectsToGroup(arrObjects, Rhino.AddGroup())
End If

'Defines arrExtrusions'
arrExtrusions = Rhino.ObjectsByType(1073741824, True)

For Each arrExtrusions In arrBlocks 
  'Deletes Extrusions'
  Call Rhino.DeleteObjects(Rhino.ObjectsByType(1073741824, True))
Next

Next
End Sub

  • Thanks

Posts: 1

Participants: 1

Read full topic

How to remap objects to Top view?

$
0
0

@xiix.xoox wrote:

I want remap object to top view. How can do that. I use ‘TransformObjects’ but it not working.

After remapping i’m use ‘Transform Objects’ to extrude objects.The result are polysurfaces, i want make curve like before it is extruded but not.

import rhinoscriptsyntax as rs
import scriptcontext
import Rhino
objects = rs.GetObjects("Select objects to project")
if objects:
    cplane = rs.ViewCPlane()
    form = rs.XformPlanarProjection(cplane)
    obj=rs.TransformObjects( objects, xform, False )
    #For make curve
    .....

Im try used ‘rs.DuplicateEdgeCurves’ but can’t join curve be created.
Thank you watching!

Posts: 1

Participants: 1

Read full topic

Unexpected token 'XAxis'

$
0
0

@falola.yusuf wrote:

Hello,

I am trying to redraw a circle I generated previously. I saved the plane, but I kept getting the error message "unexpected token ‘XAxis’ "

Find my code below;

rs.AddCircle(Origin=3.11261784461494,12.4843662480556,1.79156261863619 XAxis=0,0.958394482307735,-0.285447046371282, YAxis=-0.96875335366118,0.0707983139213185,0.237706833128784, ZAxis=0.248026086874379,0.276527783464858,0.928447868865989,2)

Error below;

rs.AddCircle(Origin=3.11261784461494,12.4843662480556,1.79156261863619 XAxis=0,0.958394482307735,-0.285447046371282, YAxis=-0.96875335366118,0.0707983139213185,0.237706833128784, ZAxis=0.248026086874379,0.276527783464858,0.928447868865989,2) ^ SyntaxError: unexpected token 'XAxis'

Posts: 3

Participants: 2

Read full topic

rs.SplitBrep Issue

$
0
0

@spineribjoint1 wrote:

I have a problem with rs.SplitBrep in the file attached and the example code. Can anyone try this. Use the surface on the Brep layer as the “brep”.

import rhinoscriptsyntax as rs

filter = rs.filter.surface + rs.filter.polysurface
brep = rs.GetObject("Select brep to split", filter)
cutter = rs.GetObject("Select cutting brep", filter)
rs.SplitBrep ( brep, cutter )

Splitting works if I use Rhino Split command. Any idea why it doesn’t split with rs.SplitBrep?SplitBrepIssue.3dm (230.2 KB)

Posts: 3

Participants: 2

Read full topic


The Nudge Steps command keeps the original object?

$
0
0

@dangtungx wrote:

I have collected the script below.

Function is to quickly enter Nudge Step values ​​in properties.
But I’m still not satisfied

I want the original object to choose nudge to remain the same, and generate a new object with the value gap entered.

Please guide me to add the nudge object copy command

import rhinoscriptsyntax as rs
import Rhino

#get current setting
nudge_step=Rhino.ApplicationSettings.ModelAidSettings.NudgeKeyStep
ctrl_nudge_step=Rhino.ApplicationSettings.ModelAidSettings.CtrlNudgeKeyStep
shift_nudge_step=Rhino.ApplicationSettings.ModelAidSettings.ShiftNudgeKeyStep

arr_value_text=[]
arr_value_text.append("Arrow Value")
arr_value_text.append("Ctrl+Arrow Value")
arr_value_text.append("Shift+Arrow Value")
arr_nudge_step=[]
arr_nudge_step.append(nudge_step)
arr_nudge_step.append(ctrl_nudge_step)
arr_nudge_step.append(shift_nudge_step)

arr_nudge_step = rs.PropertyListBox(arr_value_text,arr_nudge_step,"Nudge Key Values"," ")


nudge_step=float(arr_nudge_step [0])
ctrl_nudge_step=float(arr_nudge_step[1])
shift_nudge_step=float(arr_nudge_step[2])

#set new value
Rhino.ApplicationSettings.ModelAidSettings.NudgeKeyStep=nudge_step
Rhino.ApplicationSettings.ModelAidSettings.CtrlNudgeKeyStep=ctrl_nudge_step
Rhino.ApplicationSettings.ModelAidSettings.ShiftNudgeKeyStep=shift_nudge_step

print "Arrow Nudge: ",nudge_step,"  Ctrl+Arrow: ", ctrl_nudge_step,"  Shift+Arrow: ", shift_nudge_step

Posts: 2

Participants: 2

Read full topic

Batch convert 2000 rhino files to 3ds and obj files respectively

$
0
0

@uaremycaptain wrote:

Hi~I am puzzled by the problem to convert around 2000 rhino files to obj and 3ds files respectively
I try to use AHK window automatic script to simulate the human click operation,e.g click ‘import’, assign path, click ok, and then wait for a few seconds to totally import, and then click ‘export’, well this is a little fool and clumsy, especially low efficient

Is there any more efficient way to convert a huge amount of files?like 500 rhino files or even 2000 rhino files?The target format is 3ds and obj,I know to convert them in the same open file can be a disaster for CPU,this way i tried is inconvenient and anti-human-and-computer,if one step crash,all crash,and so do i

The core thought should be converting each of them one by one in queue aumatically by script .

Below is a simple example i want to show:

rhino_convert_3ds

i think there must be some script to help me,BTW,i master python,so if you have any direction or good suggestion ,please tell me ,thanks !!!

Posts: 2

Participants: 2

Read full topic

Reduce Mesh - Export OBJ

$
0
0

@m.wilson wrote:

Hi All,

I am extremely new at scripting and found a script online that does almost everything I am looking for…

The problem is that I need to work through a folder of files, opening each one individually and then reducing the mesh, and then Exporting to OBJ format.

I look at trying to find other script command and combining them, but was unsuccessful!

Can anyone assist with modifying the script below so it will automate the script process through an entire repository:

Option Explicit
'Script written by
'Script copyrighted by
'Script version Friday, March 30, 2012 2:05:45 PM

Call Main()
Dim strMesh, nFaceCount
strMesh = Rhino.GetObject(“Select mesh to reduce”, 32)
If Not IsNull(strMesh) Then
nFaceCount = Rhino.MeshFaceCount(strMesh)
Rhino.ReduceMesh strMesh, nFaceCount * .3
End If
Sub Main()

End Sub

Posts: 2

Participants: 2

Read full topic

Mirror point axes

$
0
0

@0904 wrote:

Hi! All,

Dim a: a = rhino.GetObject("Sel Axs")

Call rhino.Command("Mirror " & rhino.CurveStartPoint(a) & " " & rhino.CurveEndPoint(a))

why doesn’t it work?
thanks!

Posts: 4

Participants: 2

Read full topic

GUID generation in python

$
0
0

@keerthana wrote:

Hi
I’m trying to create á GUID for my geometry before i bake it so i can retrieve it later for further operations

I found this very clear example in Visual Basics

However i’m unsure how to get this working in python due to my lack of knowledge of VB

Thanks in advance

Posts: 4

Participants: 4

Read full topic

Please guide "extrude, offset" this uneven curve?

How could I represent my code in a 3D environment?

$
0
0

@haithamalnasrawi wrote:

I’m working on my Python code of the A-star algorithm and I want to implement it in a 3D environment . How could I add the the third dimension until to draw it as a 3D, what I need to do in specific?. How could I change or modify my map until to draw it as a 3D?. Could I get any guidance or assistance please?.

This is below my code:

import random
import math

grid = [[0, 1, 0, 0, 0, 0],
        [0, 1, 0, 0, 0, 0],
        [0, 1, 0, 0, 0, 0],
        [0, 1, 0, 0, 0, 0],
        [0, 0, 0, 0, 1, 0]]

heuristic = [[9, 8, 7, 6, 5, 4],
             [8, 7, 6, 5, 4, 3],
             [7, 6, 5, 4, 3, 2],
             [6, 5, 4, 3, 2, 1],
             [5, 4, 3, 2, 1, 0]]

init = [1,0]                            #Start location is (1,0) which we put it in open list.
goal = [len(grid)-1,len(grid[0])-1]     #Our goal in (4,5) and here are the coordinates of the cell.


#Below the four potential actions to the single field



delta =      [[1, 0, 1],
              [0, 1, 1],
              [-1, 0, 1],
              [0, -1, 1],
              [-1, -1, math.sqrt(2)],
              [-1, 1, math.sqrt(2)],
              [1, -1, math.sqrt(2)],
              [1, 1, math.sqrt(2)]]




delta_name = ['V','>','<','^','//','\\','\\','//']

cost = 1   #Each step costs you one

def search():

    closed = [[0 for row in range(len(grid[0]))] for col in range(len(grid))]

    '''
    Here we are making field as the same size as the grid, we memorize for each cell what action it took to get there. 
    '''
    action = [[-1 for row in range(len(grid[0]))] for col in range(len(grid))]

    #We initialize the starting location as checked
    closed[init[0]][init[1]] = 1


    expand=[[-1 for row in range(len(grid[0]))] for col in range(len(grid))]


    # we assigned the cordinates and g value
    x = init[0]
    y = init[1]
    g = 0
    h = math.sqrt((x - goal[0])**2 + (y - goal[1])**2)
    #h = heuristic[x][y]

    f = g + h 

    #our open list will contain our initial value
    open = [[f, g, h, x, y]]


    found  = False   #flag that is set when search complete
    resign = False   #Flag set if we can't find expand
    count = 0

    #print('initial open list:')
    #for i in range(len(open)):
            #print('  ', open[i])
    #print('----')


    while found is False and resign is False:

        #Check if we still have elements in the open list
        if len(open) == 0:    #If our open list is empty, there is nothing to expand.
            resign = True
            print('Fail')
            print('############# Search terminated without success')
            print()
        else: 
            #if there is still elements on our list
            #remove node from list
            open.sort()             #sort elements in an increasing order from the smallest g value up
            open.reverse()          #reverse the list
            next = open.pop()       #remove the element with the smallest g value from the list
            #print('list item')
            #print('next')

            #Then we assign the three values to x,y and g. Which is our expantion.
            x = next[3]
            y = next[4]
            g = next[1]

            expand[x][y] = count
            count+=1

            #Check if we are done
            if x == goal[0] and y == goal[1]:
                found = True
                print(next) #The three elements above this "if".

                print('############## Search is success')
                print()

            else:
                #expand winning element and add to new open list
                for i in range(len(delta)):       #going through all our actions the four actions

                    x2 = x + delta[i][0]
                    y2 = y + delta[i][1]

                    #if x2 and y2 falls into the grid
                    if x2 >= 0 and x2 < len(grid) and y2 >=0 and y2 <= len(grid[0])-1:
                        #if x2 and y2 not checked yet and there is not obstacles
                        if closed[x2][y2] == 0 and grid[x2][y2] == 0:
                            g2 = g + cost             #we increment the cose
                            h2 = math.sqrt((x2 - goal[0])**2 + (y2 - goal[1])**2)
                            #h2 = heuristic[x2][y2]
                            f2 = g2 + h2 

                            open.append([f2,g2,h2,x2,y2])   #we add them to our open list
                            #print('append list item')
                            #print([g2,x2,y2])
                            #Then we check them to never expand again
                            closed[x2][y2] = 1
                            action[x2][y2] = i

    for i in range(len(expand)):
        print(expand[i])
    print()

    policy=[[' ' for row in range(len(grid[0]))] for col in range(len(grid))]
    x=goal[0]
    y=goal[1]
    policy[x][y]='*'
    while x !=init[0] or y !=init[1]:
        x2=x-delta[action[x][y]][0]
        y2=y-delta[action[x][y]][1]
        policy[x2][y2]= delta_name[action[x][y]]
        x=x2
        y=y2
    for i in range(len(policy)):
        print(policy[i])



search()

Posts: 2

Participants: 2

Read full topic


Missing CoordinateSystem object in python RhinoCommon

$
0
0

@rocarbajal wrote:

Hello, I’m having trouble using the GetTransform() method of the Rhino.Display.RhinoViewport object. According to it’s documentation, it takes two CoordinateSystem objects as arguments, but I can’t find anywhere how to create this kind of object in python, I have run into it in Vb and C but not in python. Thanks for your help!

Posts: 5

Participants: 2

Read full topic

Extrude like sketchup (plugin joint push pull)

Importing layers via Rhino.FileIO

$
0
0

@Helvetosaur wrote:

Hi there,

I’m toying around with an “import layers from file” function. I am able to successfully import layers (including tree hierarchy, which is good) using the following code:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def ImportLayersFromFileTest():
    filename=rs.OpenFileName("Choose file to import layers")
    if not filename: return
    #optional, doesn't change much
    #tbl_filt=Rhino.FileIO.File3dm.TableTypeFilter.None
    #no_obj=Rhino.FileIO.File3dm.ObjectTypeFilter.None
    #read_file=Rhino.FileIO.File3dm.Read(filename,tbl_filt,no_obj)
    read_file=Rhino.FileIO.File3dm.Read(filename)
    if read_file:
        layer_list=read_file.AllLayers
        for layer in layer_list:
            sc.doc.Layers.Add(layer)

ImportLayersFromFileTest()

This does work to import the layer arrangement without objects, which is what I want. But, some of the layer characteristics are not imported - notably the layer material assignment if any the linetype. OTOH, layer print color and print width are imported.

So the question is this: is there some easy trick I’m missing or do I also need to get the material table separately, add the materials to the file if they do not already exist, and then re-assign them to the imported layers? Same for the linetypes?

I also understand that I will need to do some checking for existing layers and possible conflict resolution, but that’s for later…

Posts: 3

Participants: 3

Read full topic

sc.doc.Objects.Delete Help info?

Reverse an equation

$
0
0

@Helvetosaur wrote:

Hi all,

I have the following formula for calculating the “scallop height” (h) with a spherical cutter of radius ®, given the “stepover” (x).

h=r-\sqrt{r^2-(x^2/4})

With my remnants of high-school algebra, I tried to “reverse” the formula to solve for x given a desired h. However, my formula does not give me an accurate result, so I must have done something wrong…

x=\sqrt{8*h*r-h^2}

So, does anyone know how to do this correctly?

TIA, --Mitch

Posts: 6

Participants: 5

Read full topic

Viewing all 4079 articles
Browse latest View live