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

Mesh.Vertices accuracy seems wrong, why?

$
0
0

Hi guys, I am working on some mesh scripts and in evaluations of the vertices I wanted to coerce a point to check against, and then discovered that the vertex is vastly simplified compared to the coerced 3d point of that same vertex, why is that??? It seems very wrong that the mesh returns a lesser version of the vertex than a coerced version of the same point.

(The mesh is just a 100x100 mesh generated from a height field image, close to origin, nothing done to it, so it is as pure as can be)

image

19 posts - 7 participants

Read full topic


Delete layer problem

$
0
0

Hi all,
i tried to wrote a script that delete children layer and move all object to the coresponding parent layer.
This script should than running recursiv till no more child layers are present.

The problem is, after the object in the child layer is moved to the parent layer and the child layer is deleted Rhino dont recognize the objects on that layer.
But if i select the object the property panel shows the right layer.

import Rhino
import scriptcontext as sc

rh_active_doc = Rhino.RhinoDoc.ActiveDoc
# GET THE LOWEST LAYER IN THE HIRARCHY
D = {}
for i in rh_active_doc.Layers:
    D[len(str(i).split('::'))] = i

if max(D) > 1:
    print D[max(D)]
    # FIND OBJECTS ON THIS LOWEST LAYER
    lay_objs = rh_active_doc.Objects.FindByLayer(D[max(D)])
    print lay_objs
    if len(lay_objs) > 0:
        # MOVE OBJECTS ON THE LOWEST LAYER TO THE PARENT LAYER
        lay_parent = D[max(D)].ParentLayerId
        lay_parent_index = rh_active_doc.Layers.FindId(lay_parent).Index
        for obj in lay_objs:
            obj.Attributes.LayerIndex = lay_parent_index
            obj.CommitChanges()
    parent_lay = rh_active_doc.Layers.FindId(D[max(D)].ParentLayerId)
    print parent_lay
    parent_lay_objs = rh_active_doc.Objects.FindByLayer(parent_lay)
    print parent_lay_objs

FIRST PRINT RESULT BEFORE CIRCLE LAYER IS DELETED

Layer 01::Layer 01::Rect::Circle
Array[RhinoObject]((<Rhino.DocObjects.CurveObject object at 0x00000000000000ED [CurveObject: (unnamed) (0)]>))
Layer 01::Layer 01::Rect
Array[RhinoObject]((<Rhino.DocObjects.CurveObject object at 0x00000000000000EE [CurveObject: (unnamed) (0)]>, <Rhino.DocObjects.CurveObject object at 0x00000000000000EF [CurveObject: (unnamed) (0)]>))


SECOND PRINT RESULT

Layer 01::Layer 01::Rect
Array[RhinoObject](())
Layer 01::Layer 01::Rect
Array[RhinoObject]((<Rhino.DocObjects.CurveObject object at 0x00000000000000F5 [CurveObject: (unnamed) (0)]>, <Rhino.DocObjects.CurveObject object at 0x00000000000000F6 [CurveObject: (unnamed) (0)]>))


In the second print result it says empty array in the Rect layer, the object attribute tell a different story.
Why is the Layer 01::Layer 01::Rect empty ?

Help is welcome

4 posts - 3 participants

Read full topic

CurrentView Fails when switching from Named View

$
0
0

Hi,

I am having problems switching from a Named View to a Perspective View. I’ve pasted sample python code below. The code sucessfully creates a named view called DrawView and set’s it as the current view but fails when I try to switch back to Perspective.

Thanks in advance for the help.

import rhinoscriptsyntax as rs

#Add Named View called “DrawView”
rs.AddNamedView(“DrawView”)
#Set View to DrawView
rs.RestoreNamedView(“DrawView”)
#Set View to Perspective
rs.CurrentView(“Perspective”)
#Check to see if view is Perspective
print(rs.IsView(“Perspective”))

Eric

1 post - 1 participant

Read full topic

Question: Why is scripts linked to Rhino's fps?

$
0
0

This is something that has been on my mind for a long time, but I never got around to ask since I have been using rs.EnableRedraw(False/True) to work around the “issue”.

Why is the script excecution speed linked to Rhino’s FPS? I mean, I would like a script to run as fast as it can and have Rhino updating the view as fast as it can, with out those two being influenced by each other. In other words having them run in parallel.

In example: (not the best, but the first simple one I could think of)
Say I want to calculate 1000 intersections and give the user a visual feedback on how the progress is moving along. The script takes 5 second to excecute with redraw off, but the file is heavy and the display mode is rendered, so Rhino only redraws at 10FPS. Now I either have to let the user wait “in the dark” for 5 seconds, OR I can redraw after each intersection and let it take 100 seconds.

OR obviously I can make Rhino redraw every 10 calculations and have it done in 10 seconds, or redraw every second. But that requires coding and prediction handling on my side, not knowing if the system is fast or slow, or what kind of display mode is used, or how complex the model was to begin with.

So are there any easy way to have Rhino run the script as fast as it can and update the view in the background when ever the display is ready to update?

( I guess the answer is no, followed with a question about why redrawing every second is a problem and the answer to that is that it requires more coding, bug tracking etc and I would like my script to be as simple as possible so it is easier to understand and thus adjust in the future, for both me and others)

((Or put in simple words: Is there an “if displaypipeline is idle then redraw” function?))
(((And then could this be baked into Rhino python as default?)))

Cheers!

1 post - 1 participant

Read full topic

Python Editor font colors. Are they accessible in any way?

Setting Save As Options

$
0
0

Hi,

Is there a way to set the save as options using either Rhinoscript or Rhino API? Specifically interested in making sure “Save Textures” is checked when saving a file.
Rhinoscript SaveFileName does not appear to have any ability to set options? I’m using Rhino 6 with Python.

Eric

1 post - 1 participant

Read full topic

Deleting layers not working if objects moved to another layer before

$
0
0

Hi all,

here is a script to flatten all child layers so that no more nested layers are present.
Everything works well except that scriptcontext.doc.ActiveDoc.Layers.Delete(lay.Id,True) does nothing if a object is moved to another layer before.

I guess i miss something simple maybe commit changes to the layer.Table…dont know.
I descriped the problem in big letters on the line wehre nothing happens.

import scriptcontext as sc

act_doc = sc.doc.ActiveDoc

# iterate over layers
for lay in act_doc.Layers:
    # get all child layers
    if len(str(lay).split('::')) > 1:
        # check if objects on this layer
        if len(act_doc.Objects.FindByLayer(lay)) > 0:
            # move objects to the first parent layer
            for obj in act_doc.Objects.FindByLayer(lay):
                lay_first = act_doc.Layers.FindName(str(lay).split('::')[0])
                obj.Attributes.LayerIndex = lay_first.LayerIndex
                obj.CommitChanges()
            # delete the child layer
            # HERE IS THE PROBLEM THE LAYER WILL NOT BE DELETED
            # ONLY IF THE SCRIPT RUN A SECOND TIME
            # BUT THAN ITS THE ELSE STATEMENT
            act_doc.Layers.Delete(lay.Id,True)
            
        else:
            act_doc.Layers.Delete(lay.Id,True)

Maybe someone had the same issue and a solution for it.
Thanks in advanced

2 posts - 1 participant

Read full topic

Rhino Script modification

$
0
0

Is there any way to modify this script export object by Layer) to not fail when nested layers are used? I just spent hours flattening a model hierarchy that I would like to preserve.

ex.rvb (1.2 KB)

5 posts - 3 participants

Read full topic


Is there a way to accomplish this without using rs.Command()?

$
0
0
rs.UnselectAllObjects()
rs.SelectObject(obj)
rs.Command("_CPlane O ", False)

3 posts - 2 participants

Read full topic

Layer.ComponentStatus

$
0
0

Hi @dale,

i am trying to find out if a layer is highlighted (selected) in the Layers dialog. There is a layer.ComponentStatus having IsHighlighted and IsSelected properties, both seem to return False regardless of the selection state:

layer.ComponentStatus.IsHighlighted
layer.ComponentStatus.IsSelected

however if i call other properties like hidden or locked like this:

layer.ComponentStatus.IsHidden
layer.ComponentStatus.IsLocked

the returned booleans show what is present in the Layers dialog. Can you explain how to work (Get, Set) with the ComponentStatus of a layer in python ?

btw. RhinoScriptSyntax is missing Rhino.SelectedLayers method.

thanks,
c.

4 posts - 2 participants

Read full topic

Can you make a script to pick only unwelded edges as seams?

$
0
0

Hello, can you make a script that, within _Unwrap
command, limits the picking of seams of a polygonal mesh to only unwelded edges (the ones which are highlighted by Edge Analisys tool , when “All edges” is selected.

1 post - 1 participant

Read full topic

Can you write a script to save a selection but not as a group?

$
0
0

I want to set Scenes in rhino so when I click a named view it automatically hides a saved selection.

2 posts - 2 participants

Read full topic

Json module python

$
0
0

Hi,
is there a module in python to handle json or do i have to install one ?.

Thanks in advanced

2 posts - 1 participant

Read full topic

AddSrfSectionCrvs works within RhinoScript, but not within Excel VBA

$
0
0

Hi,

I am trying to use AddSrfSectionCrvs by calling it thru Excel VBA. Below are two identical codes for making a section from a cube (One within RhinoScript and another accessing RhinoScript thru Excel VBA).

When running the script within RhinoScript I can get section of the cube without a problem. But when running it thru Excel VBA everything works besides the last command, i.e. AddSrfSectionCrvs.

I’ve run the code in debug mode, both in RhinoScript and Excel VBA. In the former I get the curve and the string for the newly created section curve, but in Excel VBA no string and no curve is returned.

Picture 1. Sections made x=450 and x=400

Calling AddSrfSectionCrvs within RhinoScript:

Const rhObjectSurface = 8
Const rhObjectPolysurface = 16

Dim strObject, arrPlane

strObject = Rhino.GetObject("Select object", rhObjectSurface + rhObjectPolysurface)
arrCPlane = Rhino.ViewCPlane

Dim arrOrigin
Dim arrNormal
Dim strCurves

arrOrigin = array(300, 0, 0)
arrNormal = array(1, 0, 0)

arrPlane = Rhino.PlaneFromNormal(arrOrigin, arrNormal)
strCurves = Rhino.AddSrfSectionCrvs(strObject, arrPlane)

Calling AddSrfSectionCrvs within Excel VBA:

**************************************
* Initializing connection with Rhino *
**************************************

Dim version As Integer

version = Range("C4")

' Create Interface object. Connect to an allready running instance of Rhino 5.

Dim RhinoApp As Object

Select Case version
    Case 1
        On Error Resume Next
        Set RhinoApp = CreateObject("Rhino5.Interface")

        If (Err.Number <> 0) Then
            MsgBox ("Failed to create Rhino5 x86 object")
            Exit Sub
        End If
    Case 2
        On Error Resume Next
        Set RhinoApp = CreateObject("Rhino5x64.Interface")
        
        If (Err.Number <> 0) Then
            MsgBox ("Failed to create Rhino5 x64 object")
            Exit Sub
        End If
End Select

' Make attempts to get RhinoScript, sleep between each attempt.

Dim RhinoScript As Object
Dim nCount As Integer
nCount = 0

Do While (nCount < 10)
  On Error Resume Next
  Set RhinoScript = RhinoApp.GetScriptObject()

  If Err.Number <> 0 Then
    Err.Clear
    Sleep 500 'waits for 500 ms
    nCount = nCount + 1
  Else
    Exit Do
  End If
Loop

' Display an error if needed.

If (RhinoScript Is Nothing) Then
  MsgBox ("Failed to get RhinoScript")
End If

*********************************************************************
* Same part of code as in RhinoScript for calling AddSrfSectionCrvs *
*********************************************************************

    Const rhObjectSurface = 8
    Const rhObjectPolysurface = 16

    Dim strObject As String
    Dim  arrPlane()

    strObject = RhinoScript.GetObject("Select object", rhObjectSurface + rhObjectPolysurface
    
    Dim arrOrigin()
    Dim arrNormal()
    Dim strCurve As String

    arrOrigin = Array(200, 0, 0)
    arrNormal = Array(1, 0, 0)

    arrPlane = RhinoScript.PlaneFromNormal(arrOrigin, arrNormal)

    strCurve = RhinoScript.AddSrfSectionCrvs(strObject, arrPlane)

Thanks,
Andres

2 posts - 1 participant

Read full topic

rs.CurveDirectionsMatch issue

$
0
0

Hello,

I’ve been writing a script that use python CurveDirectionsMatch function to align the curve directions and I ran into an issue - when I have co-linear lines then the above mentioned function always return true, regardless of the actual orientation…
see curves (1) on the attached picture. Find attached picture where I try to present the situation described

When the lines are not co-linear the function works as expected

I also made a test (2) : I split the smooth curve and intentionally flipped one part. function again returned true.
But when I misaligned the edges of the same curves (3) it returned false as it should

Is there an other way to compare curve directions without going deeper into vector math?

Only thing I have on my mind is to compare vectors at start point of each curve if it is less then 90 degrees…

BR
Aleksandar

3 posts - 2 participants

Read full topic


Display and print UV dimension?

$
0
0

Hi,
is there a way to display a mesh UV dimension via script?

Example:
I’ve unrolled a mesh and gave it a known UV dimension (60x60 mm)

Is there a way to retrieve this value on Rhino and print it out on the Notes tab?

Thanks for help

1 post - 1 participant

Read full topic

Sorted one list as an other list

$
0
0

how can i sort one list with the same sort of an another… i make like this:

dim=[5,98,56]
dir=['a','c','b']
for i in range (0,len(dim):
    dimdir.append([dim[i],dir[i]])
sorted_dimdir=sorted(dimdir, key=lambda dimdir: dimdir[0])
dim=[]
dir=[]
for i in range (0,len(dimdir)):
    dim.append(dimdir[i][0])
    dir.append(dimdir[i][1])

but i think there is easier…

5 posts - 3 participants

Read full topic

Add new User Attribute Text key

$
0
0

In Rhinopython I’m trying to add a new key-value pair in the Attribute User Text.

I hoped
rhinoscriptsyntax.SetUserText(object_id, key, value=None, attach_to_geometry=False)
would be able to make a new key if is not yet present, but alas.

How can I do this?

Kind regards,
Dick

3 posts - 3 participants

Read full topic

Add prefix to material names via script

$
0
0

Dear all,

i’m new to scripting in rhino and don’t know the right syntax yet.
Perhaps someone could help with one inconvenience. :wink:

I like to work with worksessions, but i am really bad in properly organizing the used materials in each file.
When it comes to combine them in a worksession there are multiple materials with names like “custom 01”. The first “custom 01” is a carpet, the next wood, the next simple black, and so on…

The problem is, that rhino assigns one material (texture, glossyness, whatever) to all “custom 01s”. So that now all “custom 01s” get a carpet texture.

Is there a simple way scripting a prefix to all file materials?

Means, i have file named 01_floor, 02_walls, 03_ceiling and i can rename all used materials in each file with the number prefix of the file, in order to get “01 custom 01” for the carpet, “02 custom 01” for the wood, “03 custom 01” for the simple black…

Thank you very much!

Seb.

1 post - 1 participant

Read full topic

Automating Rhino

$
0
0

Hello, I’ve recently been looking at automating Rhino operations in order to assist in automated testing of our Rhino plugin.

I was wondering if there is a recommended way to inspect the internal state of Rhino? Ideally I’d like to do things like “Get list of loaded plugins”, “send command”, etc.

I see that there is a large resource of application APIs in RhinoCommon Python docs (this is available via IronPython, right?) https://developer.rhino3d.com/api/RhinoScriptSyntax/

Are there any samples about exposing some external interface (command interface, simple REST API, etc) to at least call the RhinoCommon API from outside the Rhino context? If not, do I get at least full access to the host filesystem from within Rhino’s Python (so I could json.dump() some results of tests for example).

Thanks! I’m new to Rhino but the amount of flexibility looks incredible so far.

2 posts - 2 participants

Read full topic

Viewing all 4140 articles
Browse latest View live