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

Printing a tuple with a single item

$
0
0

@qythium wrote:

@piac I noticed something odd when using either the __future__ print function or regular print function with a comma at the end - it looks like the GhPython component does not ‘flush’ its print output if it does not end with a new line, and then accumulates the unprinted text between solutions:

Not sure if this is a Mac specific issue?

Posts: 2

Participants: 2

Read full topic


Loop that select biggest Mesh and Nurbs object

$
0
0

@texbls wrote:

Hi,
I have a model in NURBS on layer1 and mesh version of the same thing on layer2 and I need to
select part as a nurbs and then the same part as mesh a then perform an specific action on each pair (NURBS+mesh).

My idea is to create a loop that will find two biggest - in terms of volume or area, geometries, then two second biggest and so on… till it ends with the smallest pair.

I have found some interesting scripts when it comes to selecting geometry by volume but I am getting an error
"

  • Message: ObjectsByType() got an unexpected keyword argument ‘state’

Traceback:
line 6, in SelSrfsByArea, “C:\Users\Dell\Downloads\SelSrfsByArea.py”
line 77, in , “C:\Users\Dell\Downloads\SelSrfsByArea.py”
"SelSrfsByArea.py (2.6 KB)

Posts: 6

Participants: 2

Read full topic

Set text Horizontal to View with script

$
0
0

@james.head-mears wrote:

I’m trying to use the new text features in Rhino 6 but cannot seem to get them to work. I’m inserting text with Rhino.AddText function but this does not have an option to enable Horizontal to view. Does anyone know how to enable this through VB scripting?

Posts: 1

Participants: 1

Read full topic

Google Maps Api

$
0
0

@aononye wrote:

Please is there anyway to import the googlemaps module into ghpython? Or that is not possible at this time?

Thanks.

Posts: 3

Participants: 2

Read full topic

Problem Controlling Range of Sliders with Python

$
0
0

@Antonio_Cersosimo wrote:

Hi, I been having some difficulties trying to change the range of multiple sliders using GhPython, as the range get reduce the ticks of the slider jumps out of the bar, I believe it has to do with the way I’m managing the solution, I was wondering if someone could take a look at the script and tell what I’m doing wrong. Thanks!!!
Control Sliders Python.gh (11.3 KB)

Posts: 3

Participants: 2

Read full topic

Math : Lowering function

$
0
0

@Amir_Habibi wrote:

Couldn’t find Math category :))
Need a mathematical function (X) when given 0 the output will be 1 , 50 the output will be 0.25 , …
0 (X) = 1.0
50 (X) = 0.25
100 (X) = 0.15
and so on …

Posts: 1

Participants: 1

Read full topic

Rhino 6 + scripts "Cut my own ribs" and "Massive unroller"

$
0
0

@claudiofeldman wrote:

Hellow

Does anyone know if the “cut my own rubs” and “massive unroller” scripts can still be used in rhino 6? or if they do not work directly?
for rhino 6 should one use special scripts for rhino 6?

*i try to load them(plugins),… but i receive a message
that Rhino 6,not recognize the command-upload “scripts” ? ??
**Maybe there are others for waflle structures with Rhino 6 ?

Help
Thanks

Posts: 2

Participants: 2

Read full topic

MeshFaceList.DeleteFaces also deletes vertices

$
0
0

@Dani_Abalde wrote:

MeshFaceList.DeleteFaces also deletes vertices, however the SDK says it maintains the rest of the geometry:

“Removes a collection of faces from the mesh without affecting the remaining geometry.”

http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Collections_MeshFaceList_DeleteFaces.htm

It seems to happen when a vertex loses all its faces.
Since there is a method to remove unused vertices, this method shouldn’t change the topology in my place.

 private void RunScript(Mesh M, ref object A)
  {
    M.Faces.DeleteFaces(new int[]{10,8,6,4,2,0});
    A = M;
  }

DeleteFacesBug.gh (10.5 KB)

Please, fix that.
Thanks.

Posts: 2

Participants: 2

Read full topic


Rhino.Display.DefinedViewportProjection

$
0
0

@socken wrote:

Hi,

Don’t know if this is at all right/possible but, can someone help me to get Rhino.Display.RhinoViewport object from Rhino.Display.DefinedViewportProjection.Back

The code is to be used for Rhino.Geometry.HiddenLineDrawingParameters() but my code is fucked up at the moment trying to figure it out, so I would not like to upload it here =)

Please say if you need more information about this.

Best regards

Posts: 4

Participants: 2

Read full topic

V6 rs.LayerVisible() not undoable

$
0
0

@Helvetosaur wrote:

Just open a new file from one of the standard templates and then run the following from the script editor:

import rhinoscriptsyntax as rs
rs.LayerVisible("Layer 01",False)
rs.LayerVisible("Layer 03",False)

That should turn off Layer 01 and Layer 03. Now hit the Undo button or Ctrl+Z. It says “Undoing EditPythonscript”, but the layers don’t turn back on.

In V5, the same script responds correctly to Undo, the layers become visible again.

I didn’t see a youtrack item for this, but maybe I missed it.

–Mitch

Posts: 2

Participants: 2

Read full topic

Mesh Component List - Slower in C-Sharp and Python

$
0
0

@Antonio_Cersosimo wrote:

Hi, recently I been learning a bit of c#, I was trying to do some basic operation on meshes using the c# component but it seems to be slower than expected, when I extract the VertexList, the c# component seems to take the same time than the python one, and they both are a lot slower than the Mesh Deconstruct component , this varies depending on the input mesh. Does anyone know, why this difference in solution time, and if there is any faster way of extracting mesh components. Thanks

Mesh Vertices.gh (119.6 KB)

Posts: 3

Participants: 3

Read full topic

Adding Option for _PictureFrame in GHpython

$
0
0

@Nader_Belal wrote:

Hi everyone,

I was trying to create a this component using GHpython for creating a Picture Frame and I have met with a dead wall with some issues:

  1. If there is way to achieve the same result without the action of baking the image directly in Rhino?

  2. The AddPictureFrame requires a Plane where the image will be inserted, how to tell it that I need the XY Rhino World plane ?
    PS: I have already tried giving it a point and the WorldXYPlane.

Geometry Rhino - Python - Unfinished.gh (11.2 KB)

Thank you in advance

Posts: 2

Participants: 2

Read full topic

Creating a list by selecting coordinates

$
0
0

@ZKislost wrote:

HI,

I am trying to select specific curves by using their area centroid, which is basically three coordinates.

Ive managed to obtain these coordinates using bounding boxes, given these curves are not sitting on cplanes.

However i cant seem to select specific curves by using just the z coordinates. Basically i can put them into lists based on length etc, but not sure how to work with coordinates. Here are my current notes

from Rhino.Commands import Result
from Rhino.DocObjects import ObjectType
import rhinoscriptsyntax as rs
from scriptcontext import doc

layer_objs = rs.ObjectsByType(4,True)
if layer_objs:
#create an empty list
mylist=[]
for obj in layer_objs:
#find curves among the objects
if rs.IsCurve(obj):
if abs(rs.CurveLength(obj)<100):
#curve meets selection criteria, append to “good” list
mylist.append(obj)

rs.UnselectAllObjects()

#bBox = rs.BoundingBox(mylist[0])

#CURVE1
#rs.UnselectAllObjects()
for i in mylist:
bBox = rs.BoundingBox(i)
cent = [(bBox[0][0] + bBox[6][0])/2,(bBox[0][1] + bBox[6][1])/2,(bBox[0][2] + bBox[6][2])/2]
print cent
rs.AddPoint(cent[0],cent[1],cent[2])

newlines = rs.SelectObjects(mylist)

if newlines:
s=[]
for line in newlines:
if rs.IsCurve(line):
if abs(cent[2]< -11):
s.append(line)

rs.UnselectAllObjects()

rs.SelectedObjects(s)

I keep getting the error: expected an indented block.

Help would be appreciated, thank you.

Posts: 2

Participants: 2

Read full topic

Looping repetitive commands, and using their info

$
0
0

@ZKislost wrote:

Hi,

I have a basic code by which im trying to get the center of a number of curves without them sitting on a cplane.

However im currently doing this for each curve in the list manually, i rather just loop it to apply the code to each curve in a list, and then print out the centroid.

I also need to be able to use this centroid values to select specific curves from these lists. Not sure how to go about it, help is so appreciated. My code is down below:

from Rhino.Commands import Result
from Rhino.DocObjects import ObjectType
import rhinoscriptsyntax as rs
from scriptcontext import doc

layer_objs = rs.ObjectsByType(4,True)
if layer_objs:
#create an empty list
mylist=[]
for obj in layer_objs:
#find curves among the objects
if rs.IsCurve(obj):
if abs(rs.CurveLength(obj)<100):
#curve meets selection criteria, append to “good” list
mylist.append(obj)

rs.UnselectAllObjects()

#CURVE1
#rs.UnselectAllObjects()
rs.SelectObjects(mylist[0])
bBox = rs.BoundingBox(mylist[0])
cent = [(bBox[0][0] + bBox[6][0])/2,(bBox[0][1] + bBox[6][1])/2,(bBox[0][2] + bBox[6][2])/2]
print cent
rs.AddPoint(cent[0],cent[1],cent[2])

Posts: 3

Participants: 2

Read full topic

Help with phyton to rhino button

$
0
0

@amilanese wrote:

Hi , all . I’m very not experienced in this kind of things . I’ve tried to get a script working helping me to export models from my workflow with some basic checks before to export them .

Some how difficult to explain but it should be easy to understand the script :slight_smile:

import rhinoscriptsyntax as rs

# seleziona l'insieme dellegeometrie da esportare

modello = rs.GetObjects ( " seleziona il modello " , select=True )

#isola la selezione

if modello : 
   rs.Command ("_hide")


geometrie = rs.Command ("_selall")

if geometrie : 
  rs.Command("_hideswap")

if not geometrie : 
   rs.Command ("_show")


modellofinale = rs.Command( "_SelAll" )

if modellofinale :
    rs.Command("_selall _ShrinkTrimmedSrf ")

# verifica che le poli e le srf siano chiuse


solidi = rs.GetObjects(" verifico i solidi " , preselect=True)

if solidi : 
 rs.Command( " _SelOpenPolySrf ")


verificapoly = rs.SelectedObjects()
if verificapoly:
    msg = "ci sono polisuperfici aperte"
    rs.Command(" _SelOpenPolysrf")
    print msg
if not verificapoly :
    rs.Command (" _SelOpenSrf ")
    verificasrf = rs.SelectedObjects()

if verificasrf:
   msg = "ci sono superfici aperte"
   rs.Command(" _SelOpenSrf")
   print msg
if not verificasrf :
    rs.Command (" _SelDup ")
    duplicati = rs.SelectedObjects()

#verifica presenza di duplicati

if duplicati:
    msg = "ci sono duplicati"
    rs.Command(" _Seldup")
    print msg
if not duplicati :

#esporta la selezione

    rs.Command (" _selall _-Export _Pause _Version=5 _Browse" )
    print "tutto bene"

Basically , let’s say you get 5 groups of 10 solids . I want to export one group and check if any of the geometry is open and if any duplicate .

If I run the script on the debug it does what it should … stop me each time any issue is found and drop a message of what the issue is .

If I run it in a rhino command , Including the script in ! _-RunPythonScript ( … )
it still find the issue but it doesn’t show me the right issue message but all of them .

Seems like it should be forced to stop once each time a ‘msg’ is printed

Anyone knows how to fix it ??

thanks :slight_smile:

Posts: 3

Participants: 2

Read full topic


Add Point() and scriptcontext

$
0
0

@onrender wrote:

Hi there,

I have found a link how to add new point to the document and just wondering why do we need to use scripcontext.doc because rs.AddPoint(point3d) is already in the script. Can you please give me a short explanation ?

  # creates a point where the mouse is clicked
  # using the RhinoScript syntax
  point3d = rs.GetPoint("Click for point")
  if point3d == None: return Result.Nothing
  rs.AddPoint(point3d)
  doc.Objects.AddPoint(point3d)

Posts: 3

Participants: 2

Read full topic

Get 3dpoint coordinate isntead of object3dpoint

Picture frame

$
0
0

@ricardo.eira wrote:

Hello ,

I need to insert a photo (Pictureframe) from python script, but I need to insert attributes for the size.

Anything like, get image and first point 0.0.0 and length 20.0.0?
Any idea?

Posts: 7

Participants: 3

Read full topic

Optimize __CustomGetObjectEx in selection.py

$
0
0

@Willem wrote:

Hi,

I found rhinoscriptcontext.GetObjectEx() to be slow when setting the allowed objects.
There is an annoying delay between the clicking and selection of an object.
After some digging and testing the method below (from selection.py) is noticeably faster when testing for containment (last 2 lines) than the iteration and equality test(current implementation)

class __CustomGetObjectEx(Rhino.Input.Custom.GetObject):
    def __init__(self, allowable_geometry):
        self.m_allowable = allowable_geometry
    def CustomGeometryFilter(self, rhino_object, geometry, component_index):
        #for id in self.m_allowable:
        #    if id==rhino_object.Id: return True
        #return False
        if rhino_object.Id in self.m_allowable: return True
        return False

-Willem

Posts: 1

Participants: 1

Read full topic

OnModifyObjectAttributes event not triggered

$
0
0

@felix_frischmann wrote:

Hi,

If I script in RhinoPython and modify the user text of an object (rs.setUserText) the event OnModifyObjectAttributes(…) of my custom plugin is not triggered?! If I perform the same step manually within Rhino command prompt everything works fine as expected…
Also all the other events of my event watcher are triggered fine, like e.g. addObject(…)
Is this a desired behaviour?

Posts: 1

Participants: 1

Read full topic

Viewing all 5806 articles
Browse latest View live