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

Understanding Functions

$
0
0

@Shridhar_Mamidalaa wrote:

hi all,
i am trying to understand how functions and classes work.i have set a small goal to educate myself. so i m trying to do this... dividing circles and adding circles on the points (n) times...
python in general examples are good but since i work with geometry its easy to do such small assignments

my friends on social networks have tried to help me with this with their expertise but i couldnt grasp their complex approaches. i m looking for a simplistic approach possible using function(s).

Posts: 3

Participants: 2

Read full topic


Do all doc objects have a 'local' transform?

$
0
0

@nathancoatney wrote:

I recently worked on a texture mapping project in which I retrieved the texture mapping transform from a doc object using Rhino.DocObjects.RhinoObject.GetTextureMapping(). Do all objects have this 'local' transform somewhere, even if they are not texture mapped, or is this transform only tracked if they do have a texture map? If it exists for all doc objects, I would find access to this local space useful. How does the Gumball know what to align to for 'align to object' mode?

Thanks,

Nathan

Posts: 3

Participants: 2

Read full topic

How do store object text as a variable with rhino python?

$
0
0

@180mph wrote:

Hello,

I am new here and new to python as well. Sorry in advance if this has been discussed or if my question doesn't belong here.

The fun part:
I have been tasked with creating a script that takes part information from Rhino (length and area of each part by layer) to export to excel to create a database of part information. This will be used further in several calculators.

I have been making progress writing snippets to achieve those goals and now Im moving on to the actual exporting to CSV process of the script. All of our part numbers appear on our "design template" according to the name of the filename (using %< filename(3") >%) under the object properties.

So basically, I want the user to select an object, and then have the actual text of that object stored as a string inside a variable. It will only be one object that is selected.

currently this is the closest to the solution I have found:

filename = rs.GetObject()
print rs.GetUserText(filename)

When debugging I see that there is a text value stored inside "Rhino.Docbjects.TextObjects.DisplayText" but I have no clue on how to access that part of it.

Hints, Help, or Suggestions would be greatly appreciated!

Posts: 5

Participants: 3

Read full topic

Rhinoscript-ing orienting a plane on a surface

$
0
0

@JimCarruthers wrote:

I'm doing a script where I want to orient a block relative to a surface according to the following parameters:

-There is a plane slicing through the target surface in which the block must stay oriented
-The block has a 'base' reference surface that is supposed to 'mate' to the target surface...inasmuch as is possible given the slice plane, if the slice plane is not perpendicular to the target surface then whichever EDGE of the block touches it first has to be aligned with the target surface as best as it can.
-There is a line defining a starting position for the block to orient that we want to stay as close to as possible. If a straight extension of that line would have the block 'fall off' the target surface, it needs to fully rest on it.

So I could imagine doing this(and have done similar tasks) by just brute-force moving and rotating the block along the plane until it "just touches" the target surface. The problem is I would need to do this whole iterative operation possibly 500 times per script run, and that would take forever and use up too much memory. In general terms how might I try to do this while minimizing the undo stack that gets generated?

Posts: 2

Participants: 2

Read full topic

Open second instance of rhino and control both

$
0
0

@Norsemen23 wrote:

Hi All,

I am working on writing a script to extract some curve geometry from one rhino file and I would like to import it into a second, pre-existing rhino file and perform some secondary operations on it. I can certainly do it by writing an export and import script and use a dummy file to store the info in between running each script. I feel that this is a fairly sloppy way to handle it and more prone to human error which is why I want to do it all from one script. That means controlling 2 instances of Rhino and I have no knowledge of how one might go about doing that.

Is this possible? If so, can someone please provide me some direction on how to do it?

Thanks,

Andrew

Posts: 3

Participants: 2

Read full topic

Set ViewProjection (Bug ?)

$
0
0

@hans1 wrote:

Hello,
I'm working on my first RhinoScript, but, there is a problem.
Rhinoscript Helpfile tells me :
ViewProjection
Returns or sets a view's projection mode. A view's projection mode can be either parallel or perspective.

Option Explicit

Call NViewports()

Sub NViewports()

Dim strNewTitle, strOldTitle, blnResult ,blnProjection

Call Rhino.RenameView("Top", "TopEx")
Rhino.Command "_NewViewport"

strNewTitle = Rhino.StringBox("Set name of new viewport","","New Viewport")

If Not IsNull(strNewTitle) Then

    strOldTitle = Rhino.CurrentView("Top")
    Call Rhino.RenameView(strOldTitle, strNewTitle)
    blnResult = Rhino.IsViewPerspective(strNewTitle)

    If blnResult = False Then

        blnProjection =    Rhino.ViewProjection (strNewTitle, 2) '!!! Nothing changed !!!


    End If

End If

End Sub

I use integer 2, but nothing will change to perspective mode....
This problem relates to Rhino V4

Best regards

Posts: 2

Participants: 1

Read full topic

Splitting surface by u,v cordinats

$
0
0

@kasper_steenstrup wrote:

Meaby i have mised it, but are there any way of splitting or taking a subsuface by u v cordinats, it could look somthing like

import rhinoscriptsyntax as rs
surface = rs.GetObject("pick a surface")
rs.SplitsBrep(surface, (1, 2), (0, 3))

Where (1,2) is (min_u, max_u) and (0, 3) is (min_v, max_v)

Posts: 2

Participants: 2

Read full topic

RhinoCommon equivalent of "Explode"

$
0
0

@Helvetosaur wrote:

I seem to be missing something here. In the file attached, there is one polycurve consisting of two segments, the split points are indicated with points. Each of the two subcurves is "kinked", meaning it will explode into more segments.

Running the Rhino command "Explode" on the original curve produces 25 segments. I would like to be able to do this with RhinoCommon. I guess I am missing something, because I can't find an exact way.

I ran the following script on the curve to test:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def TestExplode():
    crvID=rs.GetObject("Pick polycurve",4,True)
    p_crv=sc.doc.Objects.Find(crvID).Geometry
    msg=""
    msg+="Original has {} segments\n".format(p_crv.SegmentCount)
    if p_crv.IsNested:
        msg+="Polycurve is nested\n"
        p_crv.RemoveNesting()
    else:
        msg+="Polycurve is NOT nested\n" 
    exploded=p_crv.Explode()
    msg+="Number of segs after crv.Explode()={}\n".format(len(exploded))
    dup_segs=p_crv.DuplicateSegments()
    msg+="Number of segs found with crv.DuplicateSegments={}\n".format(len(dup_segs))
    ex_crvs=rs.ExplodeCurves(crvID,False)
    msg+="Number of segs found after rs.ExplodeCurves()={}\n".format(len(ex_crvs))
    rs.SelectObject(crvID)
    rs.Command("Explode",False)
    lco=rs.LastCreatedObjects()
    msg+="Number of segs found after Rhino Explode command={}\n".format(len(lco))
    print msg
TestExplode()

The results are as follows:

Original has 2 segments
Polycurve is NOT nested
Number of segs after crv.Explode()=2
Number of segs found with crv.DuplicateSegments=19
Number of segs found after rs.ExplodeCurves()=19
Number of segs found after Rhino Explode command=25

I did not find any method that would completely explode the curve as the Rhino explode command does. Am I missing something? Or do I have to write my own function with FindNextDiscontinuity (painful) and split the curve, something like the following:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

def SplitAtAllDiscontinuities(crv):
    dom=crv.Domain
    params=[]
    if crv.IsClosed:
        cd=Rhino.Geometry.Continuity.C1_locus_continuous
    else:
        cd=Rhino.Geometry.Continuity.C1_continuous
    param=dom[0]
    while True:
        chk,next_param=crv.GetNextDiscontinuity(cd,param,dom[1])
        if chk:
            params.append(next_param)
            param=next_param
        else:
            break
    return params
    
crvID=rs.GetObject("Select polycurve",4,preselect=True)
crv=sc.doc.Objects.Find(crvID).Geometry
parameters=SplitAtAllDiscontinuities(crv)
if len(parameters)>0:
    pts=[rs.EvaluateCurve(crvID,p) for p in parameters]
    rs.AddPoints(pts)
    rs.SplitCurve(crvID,parameters,False)

However, although this does give me 26 split points (not 25), they are not exactly the same as the results from the Rhino command "Explode"... Some curves with kinks remain, and some without kinks have been split... confused

Edit: and, a corrolary to this question: Is there a RhinoCommon tool to detect a kinked single NURBS curve (as Properties>Details reports) as opposed to a polycurve?

--Mitch

ExplodeQuestion.3dm (26.0 KB)

ExplodeQuestion.zip (10.8 KB)

Posts: 8

Participants: 3

Read full topic


How to use downloaded libraries?

$
0
0

@Petras wrote:

Hi,

Where should I copy downloaded libraries for python in order to use in Rhino, python?

For example I want to use "pybulletphysics-master" and where should I copy these files:

Thank you in advance,
Petras

Posts: 5

Participants: 5

Read full topic

Trying to make a chain

$
0
0

@rhinorudi wrote:

Looking for some tips on doing this correct.

I have a chain link as a closed polysurface and a curve.

I want to array along curve the link and rotate every 2nd link 90ª .

So I can get the object and copy and rotate it. What I am wondering is the array part. I don't see any commands on the Rhinoscript syntax page.

Here is my script for rotating the object

import rhinoscriptsyntax as rs

def createLinks():
    obj = rs.GetObject("Select object to rotate")

    if obj:
        bb=rs.BoundingBox(obj)
        # find object's bounding box center point
        center=rs.AddPoint.Origin=(bb[0]+bb[6])/2
        # rotate and copy original object
        cplane = rs.WorldXYPlane()
        xform = rs.XformRotation2 (90.0, cplane[1], center)
        link2 = rs.TransformObjects( obj, xform, True )


    rs.MoveObject(link2, (2.75,0,0))


createLinks()

Would it be better to Array along curve first then rotate every second one with …

Slice notation a[low:high:increment]

Posts: 5

Participants: 2

Read full topic

New Python user - GUI on a Mac?

$
0
0

@agmckenna wrote:

I'm starting to get my head around Python, but trying to find a way to access som eGUI elements that could be combined together in a simply form/dialog?

I've installed Atom and have seen references to Tkinter as a library, but not sure how to import that into Atom for use? Radio buttons, text box, numbers...

I've looked at the Meier_UI_Utility also, but think it might be windows only?

Thanks in advance!

Adrian

Posts: 16

Participants: 6

Read full topic

External editor possibility

$
0
0

@xliotx wrote:

I code mainly in ghpython and would like to use emacs as an external editor.

Is there a way to import the rhinoscriptsyntax as well as rhino common command in a way that can be used in emacs for auto completion?

It is not necessary to run the commands in Emacs and I can always use ghpython to import the *.py file.

Just try to make the coding and editing process faster...

Posts: 15

Participants: 6

Read full topic

Command/Python for create new empty layer?

$
0
0

@radio412 wrote:

Hello, I am using Atom with Python to script. I have a python script I wrote to export OBJ files. This is still working fantastic as per my previous forum questions and the helpful answers from the community. thank you!

However, now I would like to not only export the OBJ files, but also redistribute objects to layers via Python. Each discrete object is to be copied to a unique layer and the layer is given a unique name - perhaps simply a epoch timestamp or something. I looked at the command list but could not find a layer creation command. Is there one? Is there a more direct way to redistribute discrete/ joined objects to layers?

For example I have a model produced by an architect which has multiple discrete building masses on a single layer. I would like to check for multiple child objects and redistribute the massings to unique layers. Here You can see each building is a distinct group but they're all on the Building_Mass layer and I need them each to have their own layer for further operations in Python with a cloud database:

Posts: 3

Participants: 2

Read full topic

Setting Active Viewport down to precise rectangle area

$
0
0

@krsnadas wrote:

Is there any scriptcontext method that could be used to set the active viewport's visible area precisely say using 4 3d points of a rectangle. I'm looking for something similar to rhinoscriptsyntax's ViewCorners except that I want to set the corners. SetFrustum does not seem to be useful in this regard. Any thoughts?

Posts: 11

Participants: 3

Read full topic

"pipe" command or any profile curve extrusion along curve, in RhinoCommon

$
0
0

@tsiddikee wrote:

I want to extrude curve along curve.
I have to create curved beams and specific profiles with specific profile curves.

I need to do it in RhinoCommon.
What is the rhinoCommon way of Pipe command? or extrude closed curve along curve?

I will break the long path curve into pieces and then I will extrude profile along curve, as I need to rationalize them too.
I am not finding the right way in Rhino Common, for extruding profile curve along a curve path...
If I need to write a c++ plugin then I am also happy to do that.

Please give me some clue and advise.

Best Regards

Posts: 4

Participants: 3

Read full topic


Quirky Indenting in Rhino Python Editor

$
0
0

@krsnadas wrote:

Well, this is a little embarrassing but this piece of code for a tile render script seems to be acting bizarre. The problem seems to be within MoveTarget. The function returns the correct value of center in the first two while loops but in the third while loop, it returns the same value without adding adding distance to it. Why??

def MoveTarget(current,direction,distance):
    if direction == 'Up':
        current.Z= current.Z + distance
    if direction == 'Left':
        current.X= current.X - distance
    if direction == 'Down':
	current.Z= current.Z - distance
    if direction == 'Right':
	current.X= current.X + distance
    return Rhino.Geometry.Point3d(X, Y, Z)

#Move left until the left edge exceeds bb left (X)
while pt[0].X > bb[0].X:
	center= MoveTarget(center, 'Left', horizontal)
	rs.ViewTarget('Front',center)

#Move up until the top edge exceeds bb top (Z)
while pt[2].Z < bb[4].Z:
	center= MoveTarget(center, 'Up', vertical)
	rs.ViewTarget('Front', center)

while pt[2].Z > bb[0].Z:
    #Move right and count until right edge exceeds bb right
    while pt[0].X < bb[1].X:
        center= MoveTarget(center, 'Right', horizontal)
        rs.ViewTarget('Front', center)

Posts: 2

Participants: 1

Read full topic

How do I install modules where Rhino mac python can see them?

$
0
0

@nicoles wrote:

Hey there!

I'm okay with python, and pretty into Rhino, but for the life of me, I can't figure out how I go about installing modules so that the python that works with Rhino can see them. I've got pip for my system python, and it looks like things like chiplotle are installed, but when I try to access them from within rhino scripts, I get no module installed errors.

Help?

Thanks!

Posts: 1

Participants: 1

Read full topic

Donut donut donut :) (but more about Cplane)

$
0
0

@julz wrote:

Hi everyone,
how can we simply create a point from a "dynamic" cplane in a loop (in python) ?
in the attached exemple, i just try to describe a simple circle while revolving from Z
for making a simple donut shape smile , for that i need to orient my Cplane, so i easily do that with a crossproduct... but i still can't create from the new Cplane at given time before the next loop ... i try to keep thinks simple but there... what i have missed ?
thanks for any help (i don't think that is an hard topic to fix) ^^
TorusModel.py (2.4 KB)

Posts: 4

Participants: 2

Read full topic

GhPython problem

Cannot access MouseCallBackEventArgs in GHPython

$
0
0

@jpullutasigiza wrote:

Hello - I cannot access the MouseCallbackEventArgs in GHPython but in RhinoPython it works perfectly fine. Any suggestions?

from Rhino.UI import *
import scriptcontext as sc
import Rhino.RhinoDoc as rhdoc

class MyMouseCallback(MouseCallback):
  def OnMouseDown(self, e):
    print "active viewport: {0}".format(e.View.ActiveViewport.Name)
    ghenv.Component.ExpireSolution(True)
    self.Enabled = False
 
 
sc.doc = rhdoc.ActiveDoc
m_mc = MyMouseCallback()
m_mc.Enabled = True

Posts: 2

Participants: 2

Read full topic

Viewing all 5732 articles
Browse latest View live