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

Remove small holes of many selected breps

$
0
0

@Nico_de_Meester wrote:

Rhino has the _UntrimHoles command with an option to remove all holes below a MaximumEdgeLength. Its a nice command but works only when you select a face of a brep.

I like to have this option available for the whole brep and even better for all the breps with I select.

I made a python script with some rhinocommon commands to get all the innerloops of the brep with a MaximumEdgeLength. And show them on the screen. But what I like is to delete these inner loops from the brep. There is a methode to cull these loops. ( Brep.CullUnusedLoops) but the I have to set the m_loop_index to -1 how can I do this in the script?

BrepRemoveSmallHoles.py (2.3 KB)

I already made a script that did the job but isn’t error free and not very fast.

holesinbrep.3dm (350.4 KB)

holes1.py (4.7 KB)

Posts: 1

Participants: 1

Read full topic


rs.PopupMenu stopped working here

$
0
0

@Helvetosaur wrote:

Running this:

import rhinoscriptsyntax as rs
my_list=["ham","eggs","spam"]
result=rs.PopupMenu(my_list)

Gives

Message: Object reference not set to an instance of an object.

Traceback:
line 1210, in PopupMenu, “C:\Users\heynick\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\userinterface.py”
line 3, in , “C:\Users\heynick\AppData\Local\Temp\TempScript.py”

Nothing else seems to be affected so far, all my other scripts not involving PopupMenu seem to work.
(6.6.18156.11421, 05-06-18)
(didn’t get last auto-update either…)
Restart of machine and Rhino did not help…

Posts: 1

Participants: 1

Read full topic

How to get the number of surfaces?

$
0
0

@Alen_Russ wrote:

Hi,

When I select the surfaces I need to know the number of surfaces. eg.I select three surfaces and get the number is 3.

import rhinoscriptsyntax as rs


def do():
    msg="Select the surfaces get the number of surfaces"
    objectIds = rs.GetObjects(msg, filter=8, preselect=True)
    if not objectIds: return

do()

Thanks

Posts: 3

Participants: 2

Read full topic

Using Python to find the owner of a file

$
0
0

@DanBayn wrote:

I need to find a way to easily tell who created a Rhino model, without having to use Windows Explorer, right click on the file, pick Properties, Security, Advanced. I would like to do it with a script that reads the file that is currently open. I’ve tried Google, but all of the examples I’ve found so far require importing modules that don’t appear to be available.

Any suggestions would be appreciated.

Thanks,

Dan

Posts: 11

Participants: 5

Read full topic

What is the easiest way to know the minimal distance between 2 mesh (Objects .stl)?

$
0
0

@davedufour1991 wrote:

Hi!

So i will start with the code i use to do it :

            # Save mesh so we can calculate the smallest distance
            mesh_obj = rs.coercemesh(CurentObj)
            vertices = mesh_obj.Vertices
            normals = mesh_obj.Normals   
            
            # Go through all the points and mesure the smallest distance to the mesh
            for index, vertex in enumerate(vertices): #
                
                ClosestPoint=rs.MeshClosestPoint(Lastobj,[vertex.X,vertex.Y,vertex.Z])
                
                PointDistance=rs.Distance(ClosestPoint[0],[vertex.X,vertex.Y,vertex.Z])
                
                if  PointDistance <  SmallestDistance : #store the good value
                    SmallestDistance = PointDistance
                    GoodIndex=index
                    CurentObjPoints=[vertex.X,vertex.Y,vertex.Z]
                    LastObjPoints=ClosestPoint[0] 

I will now explain why are we doing that. We are importing multiples .STL files and we want to optimize the printing volume. To do so, we check the distance between the two observed objects and we move them to the minimal distance we can due to the printer tolerance.

Doing it that way, with this code, take time and i wanted to know if there was another function or others way to do it faster and more efficiently. We did that with V5, but we have access to V6 now.

Thank you for your help!

  -Dave

Posts: 1

Participants: 1

Read full topic

Customer request: Save filename with date

C# Parallel For Loop, "Data is incomplete or lost"?

$
0
0

@Antonio_Cersosimo wrote:

Hi, recently I been trying to speed up some mesh and matrix operations, by using a Parallel.For loop
When I do a simple Series the result seems to be complete, but when I use a function inside the Parallel For loop, it appears to be loosing some results, I’m new at using threading so I don’t know if the For loop needs something else to wait for completion(I’m pretty sure I’m missing something).

Here I leave the gh file with a c# script, one is with a normal for loop and the other is in parallel. Thanks

Parallel For Loop.gh (61.6 KB)

Posts: 4

Participants: 2

Read full topic

Rhino.Python Scripting: Automatic selection of certain curves

$
0
0

@ZKislost wrote:

I have a model in which out of numerous amounts of curves in the work space, I only want four. So i have curve 1 and cyrve 2 on mesh A, and curve 3 and curve 4 on mesh B. I will do meshintersect+splitmeshwithcurve+deletemeshface, hope that makes sense. Now i am working on a script in which rhino can detect curve 1 and 2 are on mesh A, and perform the intersection etc and this continues on with mesh B.
I originally secluded them by length but each model has different lengths and even range varies, so its not repeatable. SO for now i have settled on selecting these four curves out of the work space using get object and then performing the necessary tasks. BUT of course this is not preferred. Someone gave me advice on using coordinates ( creating bboxes round each curve, finding the centroid and then using either the x y or z coordinates to select the curves) but thats a bit of work for me, although im still looking into it. But for now this get object script i have keeps crashing Rhino, it works at times, and crashes most of the time. can someone check what exactly is wrong with it?

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

bfcrv_id = rs.GetObjects(“Select bf curves”,4)
if bfcrv_id:
#create an empty list
bfcurve=[]
for obj in bfcrv_id:
#find curves among the objects
if abs(rs.CurveLength(obj)<100):
#curve meets selection criteria, append to the list
bfcurve.append(obj)

ffcrv_id = rs.GetObjects(“Select ff curves”,4)
if ffcrv_id:
#create an empty list
ffcurve=[]
for obj in ffcrv_id:
#find curves among the objects
if abs(rs.CurveLength(obj)<100):
#curve meets selection criteria, append to the list
ffcurve.append(obj)

rs.UnselectAllObjects()

target=500

back_objs=rs.ObjectsByLayer(“3.08 Back Face Surface”)
if back_objs:
braces=[]
for obj in back_objs:
if rs.IsMesh(obj):
if abs(rs.MeshQuadCount(obj)>=target):
braces.append(obj)

#get a list of all objects on the layer you want
front_objs=rs.ObjectsByLayer(“3.07 Front Face Surface”)
if front_objs:
faces=[]
for obj in front_objs:
if rs.IsMesh(obj):
if abs(rs.MeshQuadCount(obj)>target):
faces.append(obj)

Split mesh with curve

rs.Command("-_SplitMeshWithCurve selid “+str(braces[0])+” selid “+str(bfcurve[0]))
rs.Command(”-_SplitMeshWithCurve selid “+str(braces[0])+” selid “+str(bfcurve[1]))
rs.Command(”-_SplitMeshWithCurve selid “+str(faces[0])+” selid “+str(ffcurve[0]))
rs.Command(”-_SplitMeshWithCurve selid “+str(faces[0])+” selid "+str(ffcurve[1]))

delete smaller meshes

sm=500

layer4_objs=rs.ObjectsByType(32,select=False)
if layer4_objs:
fourmesh=[]
for obj in layer4_objs:
if rs.IsMesh(obj):
if abs(rs.MeshQuadCount(obj)<sm):
fourmesh.append(obj)

rs.DeleteObjects(fourmesh)

Posts: 2

Participants: 2

Read full topic


Any method to change selected objects' layer in python script

$
0
0

@Kinan.Fleihan wrote:

Hi,

I am trying to build a script that changes the selected object’s layer into another existing layer, couldn’t find such a thing in the rhinoscriptsyntax documentation.
any Ideas?

thank in advance

Posts: 3

Participants: 2

Read full topic

Finding Rhinopython command equivalent

$
0
0

@Rhino_Gandalf wrote:

Hi everyone,

I have some queries regarding Rhinopython commands.

In most cases, I am able to find the Rhinopython equivalent of the Rhino commands (or option from Rhino toolbars) based on the name of the command but not in some cases.

Could someone please help me out in getting the command for these 2 cases?

  1. Arc: start, end, direction at start

  2. Rebuild surface UV option.
    image

  3. Also is there any provision to set the U,V discretization of Network curve surface while calling the AddNetworkSurf command itself rather than pursuing the “Rebuild surface UV” option in Rhino?

Regards,

Posts: 1

Participants: 1

Read full topic

New Script for Cosmetic

$
0
0

@Pongomarco wrote:

Hello to the McNeel Community,
I’ll probably need your help to create a script (or plugin I’m not sure yet :slight_smile: ) to solve a problem I currently have.

I need to add information like category, product name, quantity, product code… to a specific object, in the jpeg example let’s say is block 1.

I’ll have to add other information to each block from 2 to 4.

then I’ll create a new file (block 5 ) where I import all blocks from 1-4 and I assemble my system.

On the layout page all the information that I have manually added in each block have to show up as I designed.
This is really important

Another important piece of the puzzle is that somehow, in the layout page, the text should follow what in our example is block 2.
I’ll try to explain my self better… it happens that we have to move our products from a shelf to another and I would like all information associated to this block to follow it without manually do it.

You have to imagine that I’ll have to change the position of the block 2 and block 3 multiple times and I want to reduce the human error.

I hope this is clear enough, if not please feel free to ask questions!

This is freelancer job , please PM if you are interested

Who’s up for this challenge? :smiley:

Thank you,
Marco

Posts: 1

Participants: 1

Read full topic

Recording manual moves within a python script

$
0
0

@Telfer_Scott wrote:

I’m wondering if there is a way to record the moves and rotations made to an object by a user within a python script? In short, the user would be asked to align an object using the move and rotation tools, and the series of moves and rotations performed (or overall transformation matrix) would be stored and could be applied to other objects.

Posts: 4

Participants: 3

Read full topic

Need debug on a Very very simple python script. Just want to get the text of the text dots

$
0
0

@Wiley wrote:

import Rhino
import scriptcontext 
import rhinoscriptsyntax as rs


ids = rs.GetObjects("Select text dots")

if rs.IsTextDot(ids):
    text = Rhino.TextDotText(ids)
    print text

WHat is the problem?

Posts: 3

Participants: 2

Read full topic

It's Time for Sublime

$
0
0

@cdholjes wrote:

Can whoever made the rhino atom listener/atom auto-complete for mac rhino-python make one for sublime? There is some small fraction of this world that would <3 you.

Posts: 1

Participants: 1

Read full topic

Running rhino w/out directly opening program

$
0
0

@cdholjes wrote:

Has anyone figured out how to execute rhino python etc without opening rhino. Effectively running an instance of it in the background. Similiar to the python QGIS workflow if anyone is familiar with that.

Posts: 2

Participants: 2

Read full topic


RhinoScript Offset Closed curve

$
0
0

@direyes_11 wrote:

Hello, everyone

I’m trying to develop a script to offset a closed curve certain distance, I’m using this code but it does not work. It may be possible to get some help with it?

Option Explicit
 
 Function RhinoOffsetClosedPlanarCurve(ByVal strCurve, ByVal dblDistance, ByVal blnOutside)
 
   ' Local variables
   Dim arrPlane, arrOldPlane, strView, arrBox, arrPoint
 
   ' Default return value
   RhinoOffsetClosedPlanarCurve = Null
 
   ' Quick parameter validation
   If (VarType(strCurve) <> vbString) Then Exit Function
   If Not IsNumeric(dblDistance) Then Exit Function
   If (VarType(blnOutside) <> vbBoolean) Then Exit Function
 
   ' Curve validation
   If (Rhino.IsCurve(strCurve) = False) Then Exit Function
   If (Rhino.IsCurveClosed(strCurve) = False) Then Exit Function
   arrPlane = Rhino.CurvePlane(strCurve)
   If Not IsArray(arrPlane) Then Exit Function
 
   ' Calculate plane-based bounding box
   strView = Rhino.CurrentView()
   arrOldPlane = Rhino.ViewCPlane(strView, arrPlane)
   arrBox = Rhino.BoundingBox(strCurve, strView)
   Call Rhino.ViewCPlane(strView, arrOldPlane)
 
   ' Offset point so its outside of bounding box
   arrPoint = Rhino.PointAdd(arrBox(0), Rhino.VectorCreate(arrBox(0), arrBox(2)))
 
   ' Offset the curve 
   If (blnOutside = False) Then dblDistance = -dblDistance
   RhinoOffsetClosedPlanarCurve = Rhino.OffsetCurve(strCurve, arrPoint, dblDistance, arrPlane(3))
 
 End Function

Posts: 1

Participants: 1

Read full topic

How to call squish command in Rhino Script

$
0
0

@direyes_11 wrote:

Hello, everyone

I’m barely new to scripting and programming. I was trying to develop a script to create different surfaces automatic for my graduate project. In order for the script to be completed, I need to use the squish command. I don’t know how to call it, I was trying to use UnrollSrf but I need more accuracy. Is it possible to call the command?

Posts: 2

Participants: 2

Read full topic

Return object parameters from its name

$
0
0

@juancarreras wrote:

I need a Python script to rotate an object which I only know its name (I named it). How would I go about rotating it ? I would need to find its id from its name (is it possible?), center of rotation and angle. The object is a vray dome light so it only rotates about the z axis. Any ideas?

Posts: 3

Participants: 2

Read full topic

How to access to each tree

$
0
0

@alexholden18 wrote:

Hi everyone

I am new to ghpython and I have a simple question. How can I access to a branch of data in ghpython. This is my code:

import rhinoscriptsyntax as rs

lines = rs.AddLine(x,y)
a = rs.DivideCurve(lines,10, False, True)

In this screenshot you could see that ’ a ’ has an output in two different branches. I want to choose the first branch inside the python code.

Posts: 4

Participants: 3

Read full topic

Rhino save as

$
0
0

@J11 wrote:

Is there a way to set the default save option in Rhino 6 to save as a Rhino 5 file.

I looked in preferences and don’t see the option.

Otherwise is there a way to script the setting to toggle the dropdown to choose Rhino5?

I love rhino 6 but I have a 3rd party plugin that I frequently use and they are not Rhino6 compatible yet…

~J

Posts: 2

Participants: 1

Read full topic

Viewing all 5823 articles
Browse latest View live