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

Grasshopper-Python: How to start a CMD-Window and send commands to it with options

$
0
0

@Tabak wrote:

Hi there.

Within GH via Python code I am trying to open a Command Prompt (Windows 7) and executing some commands in it.
The only thing I manage to do is just to open the CMD window and run a command without options like: “_Run C:/Windows/notepad.exe” or “_Run tasklist”
But any further options to that are ignored. So “_Run tasklist -v” or “_Run echo hello world” doesn’t work.
Can someone point me in the right direction what to do to get this working?
How to run several commands in a row in the same cmd window?

Thanks in advance.

cmd_runTest_2.gh (2.8 KB)

Posts: 2

Participants: 2

Read full topic


How to get object's world coordinate

$
0
0

@davedufour1991 wrote:

Hi!

So, i recently started using Rhino and Python and i’m now hitting a wall.

So here is my problem :

I have to import many models, all different, that are stacking and i need the smallest Z possible at the end with a minimum tolerance between each objects. If i don’t move them from where they are imported in the world coordinate i have no problem but here come the twist. I want to optimize the the Z and to do that i move the object “x” times on the X axis before getting them as close as the minimum tolerance and then i wanted to get the Z of each iteration to see the best position.

It’s working, but not really good because i can’t seem to find a way to return to the original position at the end of the iteration. One thing i wanted to do was to get the lowest point of every object and work with it to move it in the world coordinate but it look like i can’t do that with the imported objects so right now i’m working with vector and the reverse don’t give me exactly the same starting X,Y,Z.

If you have any hint about how to do it, it would be appreciated !

Thank you

-Dave

Posts: 1

Participants: 1

Read full topic

Select item and run script

$
0
0

@onrender wrote:

Hi,

I am looking for way to combine the selection command with python script, that works with the left mouse button. So, I want to select an object and run the script.

Posts: 2

Participants: 2

Read full topic

SaveRenderWindowAs Now saves only the RGB pass

$
0
0

@vlad.posmangiuluchia wrote:

Hi,

I used to use

rs.Command ("_-SaveRenderWindowAs "+FileName)

to save all of the passes inside the V-ray window. Since swapping to the new V-ray and Rhino 6 it seems to only save the RGB pass.

Does anyone know how to revert to saving all of the passes?

Kind regards,

Posts: 2

Participants: 1

Read full topic

rs.OpenFileName() request

$
0
0

@Helvetosaur wrote:

Can the default extension argument be made to accept a list of extensions instead of a single one? Like, say, filtering for .dxf, dwg, and .3dm? Or is this a Windows-controlled thing that Rhino can’t do anything with…

Thanks, --Mitch

Posts: 2

Participants: 2

Read full topic

Plankton Mesh Library

$
0
0

@Amir_Habibi wrote:

Hi @DanielPiker
Since i got found not much information on plankton library and tried to figure out how some methods are used here are some of my struggle to clarification (using latest release) :

  1. What PlanktonXYZ can be used for , and what could the method _getposition do for this property?
  2. The _splitvertex and _splitface : what is their input integers (first , second)(to ,from ) , is it vertices int ,… ?
  3. When using a plankton mesh in an code supplied for grasshopper component does the planktongh namespace reference for mesh conversion (and may other things) makes big difference in computation time if so , is it big enough to make one convert the plankton data in grasshopper canvas for reducing the component operation time ?

//Amir

Posts: 3

Participants: 2

Read full topic

Noob alert - sort output with python

$
0
0

@CountryGolden wrote:

Advanced apologize for my complete lack of knowledge here, I’ve been working through this with google and crtl-c crtl-v.
I have a small script to watch a folder for 3dm files and output the filenames to another grasshopper component, how can I sort the list of files either numerically or alphabetically.

this is what I have so far to watch the folder.

import os
for root, dirs, files in os.walk(y):
    for file in files:
        if file.endswith(".3dm"):
             print(os.path.splitext(file)[0])

I’m assuming I need to use sort() to get the result I want but don’t know how to actually apply it here.

Posts: 2

Participants: 2

Read full topic

Objects change to layer. Help me

$
0
0

@xiix.xoox wrote:

i want change layer for object is selected by code python but i can’t. EX: i have text and text dot in layer default. I select text and move them to new layer (add layer and move).
I dont know command of change layer for object. Please help me

Posts: 10

Participants: 2

Read full topic


GH Python Compiled Component Custom Preview Display

$
0
0

@dadandroid wrote:

Hi

I’ve been compiling GHpython components as instructed in the following post by @piac:

with particular interest in accessing the DrawViewport functionalities for custom display, similar to the C# component.

When I run the script in procedural mode it works like a charm, but when I compile it the resulting component has its preview disabled (grayed out) and there is no way to switch the preview on. I attach a screenshot and the file with the script.

Any Idea why this might be happening? Any help would be much appreciated.

customDisplay.gh (2.5 KB)

Posts: 2

Participants: 2

Read full topic

Cumulative formula script

$
0
0

@ian.vanduivenbode wrote:

Hi,

I am trying to recreate an excel process in Grasshopper using a script. I was initially looking at foreach loops in a C# component but am struggling. To be honest i don’t mind which language its in, so long as it works!

Below is an image of the excel sheet.
image

The process outputs the data in column C based on all other data which is predefined (ideally as lists/numerical inputs into a Grasshopper component). The formula in C5 is a unique initialisation =A5-B5-B1 then all subsequent items on the list follow the pattern as per C6 which is =IF(C5+A6-B6-$B$1>$B$2,$B$2,C5+A6-B6-$B$1).

Any assistance greatly appreciated

Regards,

Ian

Posts: 3

Participants: 2

Read full topic

How to rotate a block on the Y axis of the Gumball , with gumball aligned to object?

$
0
0

@Bogdan_Chipara wrote:

Hi,
I can’t find a way to rotate, with python, a block on the Y axis of the Gumball, with Gumball aligned to object.
BlockInstanceInsertPoint doesn’t return a vector…

Any advice?
Thank you

Posts: 3

Participants: 2

Read full topic

Rhino.Python API [Question]

Autolabel_help

RhinoScript: IsLayerVisible vs IsLayerOn

Get object out of a set

$
0
0

@rainerhartl wrote:

Probably a simple question:

python script:

c = set(a).intersection(b)

print c…set([35])

I have a set with one value.
How do i get this value out of the set? >

Thats what i want:
c = 35

Posts: 3

Participants: 2

Read full topic


RhinoScript: getting AllObjects, including these in Block Definitions

$
0
0

@Jarek wrote:

Hi All,

I am trying to get the list of ALL objects in the current file, including the ones that make up the block definitions.
Rhino.AllObjects does not return these.
If there a way to access them without going through each block definition and querying for its objects list?

I am trying to get all objects ByLayer, but including these inside Blocks.
@Dale, would it make sense to add yet another switch to Rhino.ObjectsBy… functions to include these inside block definitions?
Or also a switch to Rhino.AllObjects to include these in the result ?

Thanks,

–jarek

Posts: 3

Participants: 2

Read full topic

DetailMeasured Property

$
0
0

@Alasdair wrote:

I’m trying to write a python script that changes selected dimensions to be measured from the layout space.

I can find out what detail dimensions have been measured from using:

def dimensionMeasureSpace(dimension):
        DimensionRef = Rhino.DocObjects.ObjRef(dimension)
        DimensionObj = DimensionRef.Object()
        Dimensionbase = DimensionObj.AnnotationGeometry
        detail = Dimensionbase.DetailMeasured
        return detail

If the dimensions are measured from the layout space the function returns an empty guid “00000000-0000-0000-0000-000000000000”. Otherwise it returns the guid of the detail they are measured from.

I would like to set the DetailMeasured property to an empty guid.

def dimensionMeasureSpaceLayout(dimension):
        DimensionRef = Rhino.DocObjects.ObjRef(dimension)
        DimensionObj = DimensionRef.Object()
        Dimensionbase = DimensionObj.AnnotationGeometry
        Dimensionbase.DetailMeasured = "00000000-0000-0000-0000-000000000000"

This returns the error “Message: expected Guid, got str”

Thanks.

dimensionMeasureSpace.py (1.8 KB)

Posts: 2

Participants: 2

Read full topic

Double-click on object invoking python script command?

$
0
0

@ivelin.peychev wrote:

Hi,

Assume we have a command (myBox.py) e.g. myBox(height,width,depth) to create a box.

How can I invoke this command, to edit the box, by double clicking on the box?

Thanks in advance

Posts: 1

Participants: 1

Read full topic

Point from intersection event python

$
0
0

@flokart wrote:

Hi all,

how can i convert the intersection event to a point object ?

Rhino.Geometry.Intersect.Intersection.CurveSelf(Curve,0.001)

or better how can i use the result ?

Rhino.Geometry.Intersect.IntersectionEvent

Thanks for Tips

Posts: 4

Participants: 3

Read full topic

[Help] How to draw line segments while picking the points

$
0
0

@ivelin.peychev wrote:

Hi,

First a small complain, RhinoCommon, RhinoPython, and the other APIs are really not helpful for beginner programmers. Same goes for the examples. Very few comments not really explaining what is going on.

Now on the point. Can anyone explain, please…
How can I make the code below draw the line segments between the points while I’m creating them? I am getting its length after all.
Please excuse me for the useless lines, I’m trying to understand how it all works.

import Rhino
import scriptcontext

def zPolyline():
    # For this example we will use a GetPoint class, but all of the custom
    # "Get" classes support command line options.
    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("GetPoint with options")

    # set up the options
    intOption = Rhino.Input.Custom.OptionInteger(1, 1, 99)
    dblOption = Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9)
    boolOption = Rhino.Input.Custom.OptionToggle(True, "Off", "On")
    listValues = "Item0", "Item1", "Item2", "Item3", "Item4"
    # set up options' defaults
    gp.AddOptionInteger("Integer", intOption)
    gp.AddOptionDouble("Double", dblOption)
    gp.AddOptionToggle("Boolean", boolOption)
    listIndex = 3
    list = Rhino.Collections.Point3dList
    # WHA?
    opList = gp.AddOptionList("List", listValues, listIndex)
    pl = Rhino.Geometry.Polyline()
    while True:
        # perform the get operation. This will prompt the user to
        # input a point, but also allow for command line options
        # defined above
        for i in range(0,5):
            get_rc = gp.Get()
            #if you don't comply with the next if loop keep the command open
            if gp.CommandResult()!=Rhino.Commands.Result.Success:
                return gp.CommandResult() 
            #the if loop that completes the command
            if get_rc == Rhino.Input.GetResult.Point:
                
                point = gp.Point()
                scriptcontext.doc.Objects.AddPoint(point)
                scriptcontext.doc.Views.Redraw()
                #print "Command line option values are"
                #print " Integer =", intOption.CurrentValue
                #print " Double =", dblOption.CurrentValue
                #print " Boolean =", boolOption.CurrentValue
                #print " List =", listValues[listIndex]
                print "x= ",point.X,", y= ",point.Y,", z= ",point.Z
                pl.Add(point.X,point.Y,point.Z)
                print pl.Length
                #print list
                
                
                # 
            elif get_rc==Rhino.Input.GetResult.Option:
                if gp.OptionIndex()==opList:
                    listIndex = gp.Option().CurrentListOptionIndex
                    Rhino.Geometry.Polyline(list)
                    
                continue
        break
    return Rhino.Commands.Result.Success


if __name__ == "__main__":
    zPolyline()

I know I have a lot to learn, but still reusing pieces of code should be relatively easy. Replacing a thing or two. If a Line requires two points and can be defined as Line(startPt,endPt), then why can’t a Polyline be defined from a list like Polyline(list)? It requries point3dlist, ok, but when I add a point to it as point3dlist.Add(pt.X,pt.Y,pt.Z) it slaps me in the face with an error that there’s one more argument to be given. According to the api this should be “self”… :face_with_symbols_over_mouth: What is going on?

Thanks in advance.

EDIT: Is there plan in the future to abandon pythonscript and stick only with RhinoCommon, because in many examples both are used and this adds to the confusion.

Posts: 5

Participants: 3

Read full topic

Viewing all 5809 articles
Browse latest View live