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

ghPython : create Scribble on the canvas and set its position

$
0
0

@jonahhawk wrote:

I would like to create scribbles at specific locations on the canvas; relative to the bounds of a group.
MetaHopper does this, but I’d like to do it in a ghPython component. I cannot find the attributes, like Pivot, for Special.GH_Scribble that would set its position.

Where should I look for help on this?

Thank you,

Jonah
edit:category

Posts: 1

Participants: 1

Read full topic


Why the button is behind the capsule?

$
0
0

@andrealu2012 wrote:


i add a button on a param component,but,the button is behind the main capsule…help…
the code in custom attribute:
  protected override void Layout()
    {
        base.Layout();
        Rectangle r = GH_Convert.ToRectangle(this.Bounds);
        r.Height = 40;
        rec2 = new RectangleF(Pivot.X - ((this.Bounds.Width - 4) / 2) + 10, Pivot.Y + 27, this.Bounds.Width - 4, 25);
        this.Bounds = r;
    }

    private RectangleF rec2 { get; set; }

    public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e)
    {
        if (((e.Button == MouseButtons.Left) && this.rec2.Contains(e.CanvasLocation)) && (this.Owner != null))
        {
            (Owner as ComponentTest2).IsBtnDown = true;
            Owner.ExpireSolution(true);
            return GH_ObjectResponse.Handled;
        }
        return base.RespondToMouseDown(sender, e);
    }
    public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseUp(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e)
    {
        if ((Owner as ComponentTest2).IsBtnDown)
        {
            (Owner as ComponentTest2).IsBtnDown = false;
            Owner.ExpireSolution(true);
            return GH_ObjectResponse.Release;
        }
        return base.RespondToMouseUp(sender, e);
    }

    protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
    {
        GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, GH_Palette.Normal);
        capsule.Render(graphics, this.Selected, Owner.Locked, true);
        capsule.Dispose();
        Font font = new Font("MS UI Gothic", 3, FontStyle.Italic);
        if (channel == GH_CanvasChannel.Objects)
        {
            bool isbd = (Owner as ComponentTest2).IsBtnDown;
            GH_Capsule gH_Capsule;
            if (isbd)
            {
                gH_Capsule = GH_Capsule.CreateTextCapsule(rec2, rec2, GH_Palette.Black, "On", 2, 0);
                gH_Capsule.AddOutputGrip(this.OutputGrip.X, this.OutputGrip.Y);
                gH_Capsule.Render(graphics, this.Selected, base.Owner.Locked, false);
                gH_Capsule.Dispose();
            }
            else
            {
                gH_Capsule = GH_Capsule.CreateTextCapsule(rec2, rec2, GH_Palette.White, "Off", 2, 0);
                gH_Capsule.AddOutputGrip(this.OutputGrip.X, this.OutputGrip.Y);
                gH_Capsule.Render(graphics, this.Selected, base.Owner.Locked, false);
                gH_Capsule.Dispose();
            }
        }
    }

Thank you.

Posts: 3

Participants: 2

Read full topic

C# .DXF import

$
0
0

@obhagwat29 wrote:

Hello,
I am trying to import .dxf file via grasshopper with c# component. Everytime I run the script dialog box is opened to select a path. What I am looking for is…

a) it shall take file path as an input and import it without opening dialog box.
b) I do not know if it is possible, but I want to have the imported .dxf inside grasshopper and not in rhino so only if it is necessary i ll bake it.

Any help is this regard would be great!

here is the code i used to import

Rhino.RhinoApp.RunScript("_Import", false); // and the it opens up the dialog box to select path

Image

Posts: 2

Participants: 2

Read full topic

Worksession manipulation from Grasshopper?

Why is the maximum of a curve domain different from curve length?

Evaluate Curve rounding problem (or Number Slider digits problem)

How to handle the mouseUp event outside the button?

$
0
0

@andrealu2012 wrote:

2018-10-14%2012_04_04
i click the button,and when mouseUp inside the button,the button become “off”,but if i mouseUp outside the button,the button can not become “off”,it remains “On”,it make me a few hours to try, but all is failed,so need help,thank you very much!

code:

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Forms;
using Rhino;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;
using System.Drawing;
using Grasshopper.Kernel.Attributes;
using Grasshopper.GUI.Canvas;


namespace FabUnionRobot
{
public class AttributesCustom2 : GH_Attributes<ComponentTest2>

{
    public override bool HasInputGrip => false;

    public AttributesCustom2(ComponentTest2 owner) : base(owner)
    {

    }

    protected override void Layout()
    {
        base.Layout();
        Rectangle r = GH_Convert.ToRectangle(this.Bounds);
        r.Height = 40;
        rec2 = new RectangleF(Pivot.X + 20, Pivot.Y , this.Bounds.Width/2, 25);
        this.Bounds = r;
    }
    
    private RectangleF rec2 { get; set; }

    public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e)
    {
        if (((e.Button == MouseButtons.Left) && this.rec2.Contains(e.CanvasLocation)) && (this.Owner != null))
        {
            (Owner as ComponentTest2).IsBtnDown = true;
            Owner.ExpireSolution(true);
            return GH_ObjectResponse.Handled;
        }
        return base.RespondToMouseDown(sender, e);
    }
    public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseUp(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e)
    {
        if ((Owner as ComponentTest2).IsBtnDown)
        {
            (Owner as ComponentTest2).IsBtnDown = false;
            Owner.ExpireSolution(true);
            return GH_ObjectResponse.Release;
        }
        return base.RespondToMouseUp(sender, e);
    }

    protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
    {
        
       // Font font = new Font("MS UI Gothic", 3, FontStyle.Italic);
        if (channel == GH_CanvasChannel.Objects)
        {
            GH_Capsule BigCapsule = GH_Capsule.CreateCapsule(Bounds, GH_Palette.Normal);
            
            GH_CapsuleRenderEngine.RenderOutputGrip(graphics, canvas.Viewport.Zoom, this.OutputGrip, false);
            BigCapsule.Render(graphics, this.Selected, Owner.Locked, false);

            bool isbd = (Owner as ComponentTest2).IsBtnDown;
            GH_Capsule btn_Capsule;
            if (isbd)
            {
                btn_Capsule = GH_Capsule.CreateTextCapsule(rec2, rec2, GH_Palette.Black, "On", 2, 0);
               // btn_Capsule.AddOutputGrip(this.OutputGrip.X, this.OutputGrip.Y);
            }
            else
            {
                btn_Capsule = GH_Capsule.CreateTextCapsule(rec2, rec2, GH_Palette.Black, "Off", 2, 9);
               // btn_Capsule.AddOutputGrip(this.OutputGrip.X, this.OutputGrip.Y);
            }
            
            btn_Capsule.Render(graphics, this.Selected, base.Owner.Locked, false);



            btn_Capsule.Dispose();
            BigCapsule.Dispose();
            
        }
    }
}
public class ComponentTest2 : GH_Param<IGH_Goo>
{
    /// <summary>
    /// Initializes a new instance of the ComponentTest class.
    /// </summary>
    public bool IsBtnDown { get; set; }
    public override bool IconCapableUI => true;
    public override GH_ParamData DataType => GH_ParamData.local;
    public override GH_ParamKind Kind => GH_ParamKind.floating;

    public ComponentTest2()
      : base(new GH_InstanceDescription("ComponentTest", "CT",
          "This is the Description",
          CommonValues.Test, CommonValues.subCatalogOthers))
    {
        IsBtnDown = false;
    }
    public override void CreateAttributes()
    {
        base.m_attributes = new AttributesCustom2(this);
    }

    protected override void CollectVolatileData_Custom()
    {
        if(IsBtnDown)
        {
            this.m_data.Append( GH_Convert.ToGoo(true), new Grasshopper.Kernel.Data.GH_Path(0));

        }
        else
        {
            this.m_data.Append(GH_Convert.ToGoo(false), new Grasshopper.Kernel.Data.GH_Path(0));

        }
    }




    /// <summary>
    /// Provides an Icon for the component.
    /// </summary>
    protected override System.Drawing.Bitmap Icon
    {
        get
        {
            //You can add image files to your project resources and access them like this:
            // return Resources.IconForThisComponent;
            //return null;
            return Resource1.ABC2Matrix;
        }
    }

    /// <summary>
    /// Gets the unique ID for this component. Do not change this ID after release.
    /// </summary>
    public override Guid ComponentGuid
    {
        get { return new Guid("1f8281f7-4f08-4ab3-8823-6646071ce866"); }

    }
}
}

Posts: 1

Participants: 1

Read full topic

How to do laplacian smoothing on a nurbs surface

$
0
0

@Dani_Abalde wrote:

I want to do a laplacian smoothing on a surface moving the control points towards the average of its neighbors, but something I’m doing wrong because the following failures arise:

How should I update the edges?

How do I keep the seams fixed when it’s closed?

private void RunScript(Brep Brp, double S, int I, bool N, ref object A)
{

  if(Brp == null || !Brp.IsValid)return;
  if(I <= 0 || S <= 0){ A = Brp; return;}

  S = Math.Min(1.0, S);
  double S1 = 1.0 - S;

  BrepFace bf = Brp.Faces[0];
  NurbsSurface nurbs = bf.ToNurbsSurface();
  Brep newBrep = Brp.DuplicateBrep();

  int UC = nurbs.Points.CountU;
  int VC = nurbs.Points.CountV;
  bool cu = nurbs.IsClosed(0);
  bool cv = nurbs.IsClosed(1);

  while(I-- > 0){
    NurbsSurface newSrf = new NurbsSurface(nurbs);
    for(int i = 0; i < UC ; i++){
      for(int j = 0; j < VC; j++){
        if(N){
          PointFaceRelation pfr = bf.IsPointOnFace(i, j);
          if(pfr == PointFaceRelation.Boundary || pfr == PointFaceRelation.Exterior )continue;
        }
        Rhino.Geometry.ControlPoint cp = nurbs.Points.GetControlPoint(i, j);
        Point3d avePt = new Point3d();
        double aveW = 0;
        int cnt = 0;
        int id = -1;
        if(GetID(i - 1, cu, UC, out id)){
          Rhino.Geometry.ControlPoint cpa = nurbs.Points.GetControlPoint(id, j);
          avePt += cpa.Location;
          aveW += cpa.Weight;
          cnt++;
        }
        if(GetID(i + 1, cu, UC, out id)){
          Rhino.Geometry.ControlPoint cpa = nurbs.Points.GetControlPoint(id, j);
          avePt += cpa.Location;
          aveW += cpa.Weight;
          cnt++;
        }
        if(GetID(j - 1, cv, VC, out id)){
          Rhino.Geometry.ControlPoint cpa = nurbs.Points.GetControlPoint(i, id);
          avePt += cpa.Location;
          aveW += cpa.Weight;
          cnt++;
        }
        if(GetID(j + 1, cv, VC, out id)){
          Rhino.Geometry.ControlPoint cpa = nurbs.Points.GetControlPoint(i, id);
          avePt += cpa.Location;
          aveW += cpa.Weight;
          cnt++;
        }
        avePt /= cnt;
        aveW /= cnt;

        newSrf.Points.SetControlPoint(i, j, new ControlPoint(
          avePt * S + cp.Location * S1,
          aveW * S + cp.Weight * S1));
      }
    }
    nurbs = newSrf;
  }
  newBrep.Faces[0].ChangeSurface(newBrep.AddSurface(nurbs));
  newBrep.Compact();
  string log;
  if(!newBrep.IsValidWithLog(out log)) Print(log);

  A = newBrep;

}  

public static bool GetID(int i, bool cu, int U, out int ri){
  ri = -1;
  if(!cu && (i < 0 || i >= U))return false;
  ri = (i + U) % U;
  return true;
} 

SurfaceSmooth.gh (33.7 KB)

Posts: 3

Participants: 3

Read full topic


Weird Data Tree behavior within a C# component

$
0
0

@ale2x72 wrote:

I came across a weird behavior while I was trying to make a simple C# scripted component to append data on a new branch at the end of an input data tree (supposing, for an initial simplified case, that the tree structure had just one level so the branch indices are {0}, {1}, … {n}). I’ve tried to append data with 2 methods. One works as expected, while the other acted funny: when I tested it with a ‘Series’ component, the index of its last branch (the INPUT one) increases by one each time I re-plug it in the C# one.
This is weird and to me, I tried with new Series components, copy-pasting the C# into a new definition and it still messes with the Data Tree index of the input component. I am uploading it here in case this might expose a potential bug that needs fixing. I’m using Rhino 6, latest SR as of today.
See the screenshot (and the attached gh file) below.

Weird tree behavior.gh (10.0 KB)

Posts: 1

Participants: 1

Read full topic

Unweld mesh edges by indices

$
0
0

@massimo.romanato wrote:

Hi everyone!

I need to trim a mesh on specified edges, I tried creating trimming solid (mesh/brep) in several ways but it doesn’t work well. I think that the easiest way is to unweld the mesh at some edges selected by indices and then explode the mesh without unweld it again, but there isn’t any component in gh to do that operation, you can only unweld a mesh by a range of angles.
In rhino it works with “unweld mesh edges + explode”, but you have to select the edges one by one with the mouse, selecting it by indices in grasshopper it’s gonna be really easier.

anyone can help me? thanks

Posts: 1

Participants: 1

Read full topic

How do I iterate over branches and sub-branches in a tree with python?

$
0
0

@ivelin.peychev wrote:

When I try to treat the tree as a list and find out its length I get an error that it does not have an attribute length.

Posts: 5

Participants: 3

Read full topic

How to change the hint on inputs in Python GH component?

Data panel of the data of the notes where a line is between

$
0
0

@e.m.vanderpas wrote:

Hello,

I have a Rhino Grasshopper file which I want to convert to Rfem.
I will do this with excel, there for I want the data of my lines in the form of the nodes between how the line is.
Just like in this example.


Can someone help me with how to get is data of the lines in my model in a panel??

Kind regards,
Eef

Posts: 1

Participants: 1

Read full topic

Diagrid on a freeform

$
0
0

@CH_Au wrote:

Hi everyone, I am trying to create a diagrid on a free-form cone. The problem is I don’t know how to connect the divided points diagonally and make those curves lay on the free-form surface, could anyone help? Thanks.

Posts: 1

Participants: 1

Read full topic

Can you bake to a specific 3dm file without open it?


Grasshopper Patition a data tree

How to add input & output text in component

$
0
0

@andrealu2012 wrote:


these days ,i am doing custom attribute.
in this case,i override the render and use a capsule.
but the text is null(i draw in red area),i know,may be i can add text by graphics.DrawString(),but i guess there may be more easier method(than DrawString)to do this.
hope some one can help,thank you!

Posts: 2

Participants: 2

Read full topic

How to add a Textbox in component?

$
0
0

@andrealu2012 wrote:

image
for example, people can input string in this white text box…
like this:
image
I find it is hard to code in custom attribute…
do you have some idea to do this?,thank you!

Posts: 2

Participants: 2

Read full topic

Update All Clusters in a GH Script

$
0
0

@bushdylanj wrote:

When working with a large script with many clusters, is there any way to update all clusters at once, as opposed to having to comb through the script and update one-by-one?

If not, any ideas for strategies to approach this issue with?

Thanks

Posts: 1

Participants: 1

Read full topic

C# - Custom Data Output - Input: Where to start?

$
0
0

@RIL wrote:

OK, I give up on DataOutput/Datainput.

I’ve had a look at splitting my huge GH definitions using DataOutput and DataInput and yes, they would have done the job, but only if :

  1. I could define the File name via an input (I need to concatenate file names), and
  2. Save and Read back data from (default) the same directory as the Rhino model (or the GH def), or from an optional (input) Path

I need to have full control of my “data flow” (which can vary, and can be complex) so I will have to write my own Data Output/Input components for my needs.

Q: But how do I save individual GH objects (do I have to bake them first?) to file (fast & compact format?) in the most straight forward way? Are there any code examples/links? Prefered File format? Etc. A simple (C#) example would get me started.

// Rolf

Posts: 12

Participants: 4

Read full topic

Viewing all 3658 articles
Browse latest View live


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