Quantcast
Channel: Grasshopper Developer - McNeel Forum
Viewing all 3646 articles
Browse latest View live

Rhino 5: drawing curves with arc, specifying length

$
0
0

@Kenyon_Graham wrote:

Hi, I have been trying to draw a curve using the arc command.

Using centre of circular curve, radius and the length of arc.

Sometimes I seem to get a result. Mostly not.

I am trying to specify the length. Using the segment angle does not provide an exact length due to the no. Of dp's rounding error.

The Arc data is simple R=161m and the length is 250m start point isn't critical. The curve length is.

I was trying to draw in GH, but thought that setting the curve in Rhino was easier, alas not yet.

Posts: 7

Participants: 3

Read full topic


I need a simple sentence for Solid Intersection and Volume Moments

Optimization Plug-In for Grasshopper: How to use Galapagos' interface and gene pool?

$
0
0

@ParamDesSing wrote:

Hallo,

I have built a prototype of a new optimization tool for Grasshopper, using surrogate modelling (https://en.wikipedia.org/wiki/Surrogate_model). Now I want to develop it into something more user-friendly, so I have two questions:

  1. How can I make my component look like Galapagos? Specifically, how do I get the special wires that highlight the number slider they connect to?

  2. Is there any way I can access the gene pool component to use it with with my custom component?
    (I'd need to be able get the variable range and set values, which is what I do with number sliders already.)

Thanks,
Thomas

Posts: 9

Participants: 3

Read full topic

How do I import and set files like .fbx .dxf .obj .skp to Grasshopper?

$
0
0

@parsa wrote:

importToGrasshopper.gh (15.7 KB)

I wrote this python script inside Grasshopper which only import files to Rhino. After that I use a LunchBox component to save the same imported geometry by stating its name and after that I referenced the .3dm file to Grasshopper. The problem I have here is that I need to state the name of imported object every time.
Would somebody please help me out with my python script? I want to get rid off all these process and end up with one python component which outputs the geometrics from whatever .fbx or .obj file. Or at least output the names of the imported geometries.

Posts: 1

Participants: 1

Read full topic

Redraw in every iteration VB.Net

$
0
0

@Christoph1 wrote:

Dear all,
In a custom Grasshopper component, how can you enable redraw in every iteration?
For example I have this AntColonyOptimizer solving a TSP and I would like to see how the Graph changes in every iteration.

For a start, I tried to just put the DA.setData into a for loop inside the Grasshopper component item :

Protected Overrides Sub SolveInstance(DA As IGH_DataAccess)

    Dim pointList As New List(Of Point3d)
    If (Not DA.GetDataList(0, pointList)) Then Return

    Dim cities(pointList.Count - 1)() As Double
    For i As Integer = 0 To pointList.Count - 1
        cities(i) = New Double(2) {}
        cities(i)(0) = pointList.Item(i).X
        cities(i)(1) = pointList.Item(i).Y
        cities(i)(2) = pointList.Item(i).Z
    Next


    For u As Integer = 0 To 100
        Dim tsp As New ACO_TSP()
        tsp.Main(cities)

        Dim pts As New List(Of Point3d)
        For i As Integer = 0 To pointList.Count - 1
            pts.Add(pointList.Item(tsp.bestTrailOut(i)))
        Next
        pts.Add(pointList.Item(tsp.bestTrailOut(0)))
        Dim pline As New Polyline(pts)

        DA.SetData(0, pline)

        For i As Integer = 0 To pointList.Count - 1
            cities(i) = New Double(2) {}
            cities(i)(0) = pts.Item(i).X
            cities(i)(1) = pts.Item(i).Y
            cities(i)(2) = pts.Item(i).Z
        Next
    Next

End Sub

But it still only shows the final polyline... ?
Is there something like an EnableRedraw as in RhinoScripting?
Would such a command also work, if it is in another class-item (in this case, if I'm trying to draw the polyline within my ACO_TSP class) and not in the Grasshopper-Component class item?

Any help is very much appreciated!
Christoph

Posts: 5

Participants: 4

Read full topic

About probabilistic switch in GH_Python

$
0
0

@daizhuo wrote:

Here is some code form Processing with IGEO. You can use IRandom.percent() to create a condition which is switched probabilistically by putting percentage in its argument. Can we do it the same in GH_Python?

add_library('igeo')

size( 480, 360, IG.GL )

for i in range(50) :
for j in range(50) :
x = i*4-100
y = j*4-100
# 50% probability to be executed
if IRand.pct(50) :
ISurface(x,y,0,x+2,y,0,x+2,y,50).clr(1.,1.,1.)
# 50% of the rest ( = 25%)
elif IRand.pct(50) :
ISurface(x,y,0,x+2,y,0,x+2,y,20).clr(0,1.,1.)
# 50% of the rest of the rest ( = 12.5%)
elif IRand.pct(50) :
ISurface(x,y,0,x+2,y,0,x+2,y,10).clr(1.,0,0)

Posts: 8

Participants: 2

Read full topic

I don't know when should I use rhinoscriptsyntax, scriptcontext and rhinocommand

$
0
0

@daizhuo wrote:

In GH_Python, I used scriptcontext to create some geometry, and it would create geometry directly , means I had no need to bake it. I don't know when should I use rhinoscriptsyntax, scriptcontext and rhinocommand.

import rhinoscriptsyntax as rs 
import random as rnd
import Rhino.Geometry as rg
import scriptcontext as sc

uinc = 1/unum
vinc = 1/vnum

panels = []
for i in range(unum):
    for j in range(vnum):
        vlen = rnd.randint(1,10)
        if j + vlen > vnum:
            vlen = vnum - j
        cpts = []
        depth = rnd.randint(0,1)
        for k in range(vlen+1):
             cpts.append(srf.PointAt(i*uinc, (j + k)*vinc))
             cpts.append(srf.PointAt((i+1)*uinc, (j + k)*vinc))
       panel = rg.NurbsSurface.CreateFromPoints(cpts,2,vlen+1,1,1)
       panels.append(panel)

        materialIndex = sc.doc.Materials.Add()
        material = sc.doc.Materials[materialIndex]
        material.DiffuseColor = sd.Color.FromArgb(i/unum*255, j/vnum*255, 0)
        material.CommitChanges()
        attr = rd.ObjectAttributes()
        attr.MaterialSource = rd.ObjectMaterialSource.MaterialFromObject
        attr.MaterialIndex = materialIndex

        panels.append(sc.doc.Objects.AddSurface(panel, attr))
         #rs.ObjectColor(rs.coercesurface(panel),sd.Color.FromArgb(i/unum*255, j/vnum*255, 0)

a=panels

Another question:
rs.ObjectColor(rs.coercesurface(panel),sd.Color.FromArgb(i/unum*255, j/vnum*255, 0))
After I added this line, why it told me that " Runtime error (TypeErrorException): iteration over non-sequence of type NurbsSurface"?

Thanks for your patience to explain these!

Posts: 3

Participants: 2

Read full topic

Pack / Conceal Lists for faster exchange between Nodes

$
0
0

@atair wrote:

Long lists are slow, and there is the 'trick' to pack point3d lists in semi-invalid meshes with all the points and only one face. That way you can exchange data between scripted nodes much much faster.

Now - what would be a good way to do the same with arbitrary data? e.g. lists of strings?

My only working approach till now was to write a custom class and copy paste that one in every node, and than move data around inside this custom class, avoiding the lists to be exposed to Gh.

Is there some better way to do that?

thanks!

Posts: 3

Participants: 2

Read full topic


Speed up args.Display.Draw3dText

$
0
0

@Hugh_Groves1 wrote:

I have created a custom component which draws labels adjacent to points. I draw these labels using Draw3dText, and then orient them towards the camera position so that they always stand up when the user pans/rotates.

Unfortunately I need to draw a fair number of these (likely order ~300 user input points, 3 labels per point :. 900 labels).

I can do a little bit of work cacheing some of the maths I use in my routine (bounding boxes to draw a shaded brep background to the label), however I have profiled and found that the main bottleneck is calls to Draw3dText.

I can't cache everything as if the user updates the viewport all of the 3dText must be drawn again, or does it? Are there any other inventive things I could do e.g. multi-threading the calls to Draw3dText?

Any help much appreciated. The nuclear option is just ask my user to supply a plane to draw the labels on and then only update when that changes, however it is not quite as user friendly as the current arrangement.

Posts: 3

Participants: 2

Read full topic

Stuck adding a .NET *.dll reference in GhPython

$
0
0

@Angel wrote:

Hi!,

I'm migrating the tools I coded some time ago to connect SAP2000 V16 with GH to V17 version. CSi has changed the way the API is used and I cannot figure out how to make it work.

In the help file (with a VB example) the say:

The first step in using the CSi API from an external application is to reference SAP2000v17.DLL or SAP2000v17.TLB from your application. If using Excel VBA, reference SAP2000v17.TLB by opening the VBA editor, clicking the Tools menu > References command and selecting SAP2000v17.TLB from the program installation folder.

Next, within your application, you will create a variable of interface type cOAPI, and an instance of the Sap2000 object which implements cOAPI. In VBA this could be accomplished as:

Dim mySapObject As Sap2000v17.cOAPI
Set mySapObject = CreateObject("CSI.SAP2000.API.SapObject")

The first line creates the interface variable and the second line creates the instance of the Sap2000 object which implements the interface. Now that an instance of the Sap2000 object has been created in your application, start SAP2000 using the following VBA command:

SapObject.ApplicationStart

My translation to Python:

import clr

clr.AddReference('SAP2000v17.dll')

import SAP2000v17 as sap

sapObj = sap.cOAPI()

SapObj.ApplicationStart(6)

Python says:

Runtime error (TypeErrorException): Cannot create instances of cOAPI because it is abstract
Traceback:
line 7, in script

This error refers to line 7: "sapObj = sap.cOAPI()"

Anyone knows where is my mistake? I'm noticing that I'm making something wrong creating the variable interface and the sap2000 object instance.

I've tried with:

sapObj = sap.cOAPI
setattr(sapObj,'SetAsActiveObject',True)

but I get:

Runtime error (MissingMemberException): attribute 'SetAsActiveObject' of 'cOAPI' object is read-only

It seams that I cannot create a proper instance of the Sap2000 object.

Thanks in advance.

Posts: 26

Participants: 4

Read full topic

It's necessary to define Code Encoding when testing Python compiled components

$
0
0

@Angel wrote:

Hi!,

Today I realize that there is a way to build python compiled components in Rhino WIP, so I jumped to test it immediately. And how surprise I was when GH told me this:

So I was a good guy and jumped to the mentioned URL and I found that the error is easily corrected adding this two lines at the top of your code:

#!/usr/bin/python
# -*- coding: latin-1 -*-

I don't know if this is a bug related to the new GhPython component or just that that Encoding information needs to be added manually by every user.

cc/ @piac

Posts: 3

Participants: 2

Read full topic

Load the text Height value from the current DimStyle

$
0
0

@BaptisteC wrote:

Hi there,
I am trying to load the Text Height value from the rhino doc active Dimension Style into Grasshopper through the GH Python component.
I was thinking of running the following code which works in the rhino doc python editor but load a "None" value in Grasshopper :

import rhinoscriptsyntax as rs
import scriptcontext as sc

sc.doc = rh.RhinoDoc.ActiveDoc

if start:
dimStyle = rs.CurrentDimStyle()
textHeigh = rs.DimStyleTextHeight(dimStyle)

# print textHeight --> "None"
arrowSize = rs.DimStyleArrowSize(dimStyle)

# print arrowSize --> "50"`

sc.doc = ghdoc

Does anybody have an explanation or an other way of doing this ?

Thanks for your help

Posts: 6

Participants: 2

Read full topic

[Solved] Am I missing something with data matching using GhPython?

$
0
0

@Angel wrote:

Hi!,

I've found something that disturbs me about how ghPython deal with data matching. I'm just creating a dictionary using some plain list inputs in the component (no loops, no recursion, no anything complex) and the ghPython component is surprisingly returning a grafted data tree o.O...

Is anyone able to figure out why is this happening? I know that the solution is very simple, but this is not the behaviour that I was expecting with such an inputs.

Sidenote: if you replace the code with "i=core+turn" the output is a simple gh-list.

Posts: 2

Participants: 1

Read full topic

Rhino.Geometry.Extrusion using a vector?

$
0
0

@Angel wrote:

I've been struggling trying to get some curves properly oriented before getting them extruded using "Rhino.Geometry.Extrusion.Create()" but there was not fast way to deal with them and I jump to search for an extrusion function that let me specify an extrusion vector.

I've found "Rhino.Surface.CreateExtrusion()" but it doesn't produce a close extrusion but an open Brep and then I have to close it using "myExtrusion.CapPlanarHoles(tolerance)" and at the end I don't get an Extrusion but a closed Brep what is not what I would like.

My question: Is there any way to get a closed extrusion out of a planar curve specifying an extrusion direction?

Thanks in advance.

Posts: 7

Participants: 4

Read full topic

Importing Grasshopper.dll into Eclipse/PyDev

$
0
0

@Angel wrote:

Hi!

Extending my Eclipse to GH coding/debbuging workflow, I was trying to add Grasshopper.dll as reference in Eclipse with no luck; I used this folder path `"C:\Users\Ángel\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)\0.9.69.0"

The curious thing was that copying the Grashopper.dll and *.xml file into the PyDevRhino folder ("C:\Program Files\Eclipse\pydevrhino") it started working instantly. The only problem is that it's not detecting properly functions or types inside "g.Kernel.Data.", but the rest seams to work flawlessly.

And I say that it's curious because the Rhinoscript reference is loaded from "C:\Users\Ángel\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib" with no problem.

Posts: 1

Participants: 1

Read full topic


Faster voronoi

Quad Mesh display is different from baked geometry

$
0
0

@raf2205 wrote:

Hi,
It seems that in some case the display of quad mesh is different from the baked geometry. Please see the GH file attached. If you bake the mesh you will see that the "diagonal" of the quad is reversed. Not sure if it's a bug, but pretty confusing. Any idea?

QuadDiagonalIssue.gh (1.6 KB)

Posts: 1

Participants: 1

Read full topic

DataTree is not working

$
0
0

@tsiddikee wrote:

DataTree is not working .. which name space I should use. I am making Grasshopper component SDK in C#.

DataTree tree=new DataTree();

which name space I should use?

Posts: 4

Participants: 2

Read full topic

Any sample for 3 level of branches in DataTree Grasshopper c# dotnet code?

$
0
0

@tsiddikee wrote:

I am looking for a sample code to create three level of braches in a DataTree.
I know I will need to use IGH_Goo but I do not know how to use it.

I could not find GH_Structure either. which namespace I should use?

Posts: 13

Participants: 3

Read full topic

GH Preview makes PlaceTarget and ZoomSelected go crazy

$
0
0

@declan wrote:

Has anyone else seen this? If I have not GH preview enabled, I can use PlaceTarget and ZoomSelected no problem. All works normally.

If I enable a GH preview - crvs, srfs, whatever - camera target is immediately lost and my view rotation goes haywire. Even if I reset the target (or ZoomSelected) it makes no difference.

Gumball on/off makes no difference. Turning off the GH preview and everything is back to normal....

help please!

Posts: 4

Participants: 2

Read full topic

Viewing all 3646 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>