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

Theoretical question

$
0
0

@ivelin.peychev wrote:

Hi @DavidRutten,

Theoretically, is it possible one component (one single container) to have separately updating parts?

Whatever I try I just cannot avoid recursive errors of components connecting to one another. Like so:


, unless I add another component that updates separately. Is it possible that within one GUI loop I have two classes of type MyComponent?

Posts: 5

Participants: 3

Read full topic


Deleting Rhino objects during solution time

$
0
0

@Will_Wang wrote:

How would I delete objects in RhinoDoc and not break GH?
I have pipeline components getting objects on layers and I’d like to use GhPy
rs.ObjectsByLayer()
rs.DeleteObjects()
to delete objects by layer. It would generate an error saying the guid is no longer available during solution.

Posts: 7

Participants: 3

Read full topic

How to detect an update/change of a number?

$
0
0

@kaspar-ehrhardt wrote:

Hey together,

Im looking for a fast way to get a component which checks whether a number has been updated/changed. As long the number hasnt changed the output should be „false“. Once the number changes the output should be ONE boolean of „true“ and should than switch back to „false“.

I need it for a multi objective optimization where one of the plugin should be reset automatically after each iteration.

Any ideas how to start with?

Best,
Kaspar

Posts: 1

Participants: 1

Read full topic

What is GhCanvasViewport?

C#_BeesAttractor_Algorithm

$
0
0

@obhagwat29 wrote:

Hello,
Idea of this code is that, few spheres(bees) would come to a common point from different location and will keep hovering over it. I am able to create behavior for one single sphere getting attracted towards the point, but when I am making array of an object, there is no error but output is not visible.

Why the output of c# component is giving "Script_Instance+(Mover)’’, it should give a list of surfaces(spheres). 01_Swarm bees.gh (15.2 KB)

Any help would be great! attaching GH file too.

// List<Mover> bees = new List<Mover>();
List<Mover> Allbees = new List<Mover>();
for(int i = 0; i < movers.Length; i++)
{
  movers[i] = new Mover();
  // bees.Add(movers[i]);
}
for(int i = 0;i < movers.Length;i++)
{
  movers[i].Update(point);
  movers[i].Display(radius, reset);
  Allbees.Add(movers[i]);
}
swarms = Allbees;

}

//

Mover[] movers = new Mover[5];

class PVector{
public double X;
public double Y;
//public double Z;

// constructor
public PVector(double x, double y)
{
  X = x;
  Y = y;
  //Z = z;
}

// create a method for vector addition
public void Vadd(PVector v)
{
  X = X + v.X;
  Y = Y + v.Y;
  //Z = Z + v.Z * zVelocity;
}
// create a method for vector subtraction
static public PVector Vsub(PVector v1, PVector v2)
{
  double X = v1.X - v2.X;
  double Y = v1.Y - v2.Y;
  // Z = Z - v.Z * zVelocity;
  return new PVector(X, Y);
}

// create a method for vector multiplication
public void Vmul(double scale)
{
  X = X * scale;
  Y = Y * scale;
  // Z = Z * scale;
}

// create a method for vector division
public void Vdiv(double scale)
{
  X = X / scale;
  Y = Y / scale;
  // Z = Z * scale;
}
// create a method for vector magnitude
public double Vmag()
{
  return Math.Pow(X * X + Y * Y, 1 / 2);
}

// create a method for vector length
public double VmagSq()
{
  return X * X + Y * Y;
}
// create a method for vector Normalization
public void Vnormalize()
{
  double m = Vmag();
  if(m != 0){
    Vdiv(m);
  }
}
// create a method for vector magnitude limit
public void Vlimit(double max)
{
  if(VmagSq() > max * max ){
    Vnormalize();
    Vmul(max);
  }
}
//Random Vector
static public PVector Random2d(){
  double vx; double vy;  PVector target;
  Random rnd = new Random();
  vx = rnd.NextDouble() * rnd.Next(-1, 2);
  vy = rnd.NextDouble() * rnd.Next(-1, 2);
  target = new PVector(vx, vy);
  target.Vnormalize();
  return target;
}

}

// make another class “Mover” to oerate PVector dynamically

class Mover{
// accessible parameters
public PVector location;
public PVector velocity;
public PVector acceleration;
public double topSpeed;
//public Random rnd;

//constructor
public Mover(){
  Random rnd = new Random();
  location = new PVector(rnd.Next(0, 50), rnd.Next(0, 50));
  velocity = new PVector(1.5, 3);
  acceleration = new PVector(-0.001, 0.01);
  topSpeed = 0.9;

}

//class METHODS (Update location Method)
public void Update(Point3d point){
  PVector attractor = new PVector(point.X, point.Y);
  PVector dir = PVector.Vsub(attractor, location);

  dir.Vnormalize();

  dir.Vmul(0.05);

  acceleration = dir;

  velocity.Vadd(acceleration);
  velocity.Vlimit(topSpeed);
  location.Vadd(velocity);

}

// MEthod to display the object(swarm/sphere/circle/whatever)
public Sphere Display(double radius, bool reset){
  if(reset == false){
    return new Sphere(new Point3d(0, 0, 0), radius);
  }
  else
    return new Sphere(new Point3d(location.X, location.Y, 0), radius);
}

// define function for rectangle boundary
public Polyline Boundary(double width, double height)
{
  List<Point3d> rPts = new List<Point3d>();

  rPts.Add(new Point3d(0, 0, 0));
  rPts.Add(new Point3d(width, 0, 0));
  rPts.Add(new Point3d(width, height, 0));
  rPts.Add(new Point3d(0, height, 0));
  rPts.Add(new Point3d(0, 0, 0));

  Polyline pl = new Polyline(rPts);
  return pl;
}

}

Posts: 1

Participants: 1

Read full topic

Component coordinates on GH canvas

Object attribute assignment

$
0
0

@Nader_Belal wrote:

Hi there,

A noobs question about objects attributes, I intend to create a reusable component (for re-usability) that takes users’ input to assign an object before its creation with the desired attributes (I mean a lot of attributes), so:

  1. Should I list all those attributes values in a list, or is there another method that I’m missing ?

  2. If the past question was true, is there a normalised way to list them ?

  3. What is the #python script I should employ in the second component so that this object gets automatically assigned with those attributes when created ?

Thank you in advance

Posts: 1

Participants: 1

Read full topic

IGH_PreviewData vs IGH_PreviewObject?

$
0
0

@lionpeloux wrote:

Hello,

I think I don’t properly understand the difference between previewing a GH data type (that implements IGH_PreviewData) and its corresponding GH parameter (that implements IGH_PreviewObject).

Can some one give me some precisions ? I don’t see where/how/when a GH data type might be involved in a viewport redraw and when the corresponding DrawViewportWires method is called.

Posts: 2

Participants: 2

Read full topic


C#_Curves Offset

$
0
0

@obhagwat29 wrote:

I have list of closed planar curves and want to offset them on XY plane. But they are not getting offset and script runs fine, No error!

Any help would be great!

Here’s the code!

Tuple<List,List> fl1 = Floors(crv, floors, flrSpacing, rotation, thickness);

List<Extrusion> iSkn = new List<Extrusion>();
List<Curve > c2 = new List<Curve>();

for(int i = 0; i < fl1.Item1.Count;i++){
  fl1.Item1[i].Offset(Plane.WorldXY, 5000, RhinoDocument.ModelAbsoluteTolerance,
    CurveOffsetCornerStyle.None);
  c2.Add(fl1.Item1[i]);
}
FloorCurves = fl1.Item1;
B = c2;

what am I doing wrong here?:sweat_smile:

Posts: 4

Participants: 3

Read full topic

DrawLineArrow with fixed screen size?

$
0
0

@lionpeloux wrote:

args.Display.DrawPoint(point, PointStyle.Circle, radius, color) draws a circle that always have the same size on screen, independently to the zoom level.

I would like to achieve the same behavior with a line arrow, but args.Display.DrawLineArrow(line, color, thickness, size) gives me a fixed length line arrow in the design space, so whenever I zoom in or out the line arrow gets bigger (resp. smaller) on the screen.

The behavior I want to achieve is the same as the one used to show an object’s orientation in rhino viewport (aline arrows keep there screen size).

How can I scale the length of a line arrow to always appear with the same screen size ?

Posts: 3

Participants: 2

Read full topic

C#_ Class(Method error)

$
0
0

@obhagwat29 wrote:

I made a custom class and created method. On using the method it is throwing me an error. when i am using it just as a method not inside a class, its working fine.
Anything I am missing? attached script and error picture

  Building bB = new Building();
    List<Extrusion> eX = bB.InnerSkin(x);
    A = eX;
  }

  // <Custom additional code> 
  class Building{
    
    //Constructor
    public Building()
    {
    }  
    public List<Extrusion> InnerSkin(List<Curve>crvs)
    {
      List<Extrusion> iSkn = new List<Extrusion>();

      for(int i = 0; i < crvs.Count;i++){
        var cT = crvs[i].Offset(Plane.WorldXY, -3000, RhinoDocument.ModelAbsoluteTolerance,
          CurveOffsetCornerStyle.Sharp)[0];
        //c2.Add(cT);
        iSkn.Add(Extrusion.Create(cT, -4000 + 300, false));
      }
      return iSkn;
    }
  }

Capture

Posts: 8

Participants: 2

Read full topic

Fillet Edge of Solid

How to suppress "Server Busy" warning in Rh6

$
0
0

@timkado wrote:

Hi - I have a custom compiled C# component in Grasshopper that starts a longer process using process.Start();
In Rhino5 I used Rhino.Runtime.HostUtils.DisplayOleAlerts(false); to suppress the Server Busy warning. In Rhino 6 this does not seem to work anymore. Any hints on how to avoid these warnings in Rh6 would be greatly appreciated.

Posts: 1

Participants: 1

Read full topic

Setting a DataTree type as output

$
0
0

@a.ai wrote:

Hi, I (still) seem to have a problem with a custom component I made, that should output a datatree (storing block - parcel relationships). I get a Null Exception at
DA.SetData(0, dataTree);

What is going wrong here?

public class TestDataTree : GH_Component

    {

    
    public DataTree<GH_Curve> dataTree = new DataTree<GH_Curve>();
    public List<int> nrOfParcels { get; set; }

    /// <summary>
    /// Initializes a new instance of the C_TestDataTree class.
    /// </summary>
    public TestDataTree()
      : base("Test that Tree", "x",
          "x",
          "Tryout", "Optimisation")
    {
    }

    /// <summary>
    /// Registers all the input parameters for this component.
    /// </summary>
    protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
    { 
        pManager.AddCurveParameter("Blocks", "Blocks", " Add the blocks within which the parcels are located.", GH_ParamAccess.list);
        pManager.AddCurveParameter("Parcels", "Parcels", "Add the parcels as polyline curves.", GH_ParamAccess.list);
        pManager.AddCurveParameter("Buildable Parcels", "Buildable Parcels", "Add those parcels that are buildable (not predefined as green spaces or similar, optional).", GH_ParamAccess.list);
    

        pManager[2].Optional = true;
        
    }

    /// <summary>
    /// Registers all the output parameters for this component.
    /// </summary>
    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
    {
        pManager.AddGenericParameter("data Tree", "data Tree", "data Tree", GH_ParamAccess.tree);
        
        
    }
    /// <summary>
    /// This is the method that actually does the work.
    /// </summary>
    /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
    protected override void SolveInstance(IGH_DataAccess DA)
    {
        InitializeDataTree(DA);
        DA.SetData(0, dataTree);
        
    }

    /// <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;
        }
    }

    /// <summary>
    /// Gets the unique ID for this component. Do not change this ID after release.
    /// </summary>
    public override Guid ComponentGuid
    {
        get { return new Guid("686e3dc4-9bc4-4e5f-ae1c-353d6f4fbfbe"); }
    }

    public void InitializeDataTree(IGH_DataAccess DA)
    {
        
        // read in blocks, conversion check
        List<Curve> _blocks = new List<Curve>();
        DA.GetDataList<Curve>(0, _blocks);

        List<GH_Curve> BlockCurves = new List<GH_Curve>();
        foreach (object item in _blocks)
        {
            if (item != null)
            {
                GH_Curve curveGoo = null;
                if (GH_Convert.ToGHCurve(item, GH_Conversion.Both, ref curveGoo))
                    BlockCurves.Add(curveGoo);
            } 
        }
        // read in parcels, conversion check 
        List<Curve> _parcels = new List<Curve>();
        DA.GetDataList<Curve>(1, _parcels);

        List<GH_Curve> ParcelCurves = new List<GH_Curve>();
        foreach (object item in _parcels)
        {
            if (item != null)
            {
                GH_Curve curveGoo = null;
                if (GH_Convert.ToGHCurve(item, GH_Conversion.Both, ref curveGoo))
                    ParcelCurves.Add(curveGoo);
            }
        }
        // read in buildable parcels, conversion check
        List<Curve> _buildParcelCurves = new List<Curve>();
        DA.GetDataList<Curve>(2, _buildParcelCurves);

        List<GH_Curve> BuildParcelCurves = new List<GH_Curve>();
        foreach (object item in _buildParcelCurves)
        {
            if (item != null)
            {
                GH_Curve curveGoo = null;
                if (GH_Convert.ToGHCurve(item, GH_Conversion.Both, ref curveGoo))
                    BuildParcelCurves.Add(curveGoo);
            }
        }

        List<GH_Curve> myParcelCurves = new List<GH_Curve>();
        
        // check if information on buildable areas has been passed by user, use respective curve collection
        if (BuildParcelCurves == null) myParcelCurves.AddRange(ParcelCurves);
        else myParcelCurves.AddRange(BuildParcelCurves);

        for (int i = 0; i < BlockCurves.Count; i++)   //for each block create path and fill in GH_Curve
        {
            Polyline block;
            bool cast = BlockCurves[i].Value.TryGetPolyline(out block);
            if (cast)
            {
                GH_Path pth = new GH_Path(i);
                dataTree.Add(BlockCurves[i], pth);
            }
            else { Exception e = new Exception("Block at index " + i + " is either invalid or not a polyline."); }

            int parcelPathIdx = 0;
            for (int j = 0; j < myParcelCurves.Count; j++)    //for each parcel check if in block, if yes, append to data tree 
            {
                Polyline parcel;
                bool cast2 = myParcelCurves[j].Value.TryGetPolyline(out parcel);
                if (cast2) 
                {
                    if (IsInside(parcel.CenterPoint(), block))
                    {
                        GH_Path pth2 = new GH_Path(i, parcelPathIdx);
                        dataTree.Add(myParcelCurves[j], pth2);
                        
                        /* child node of type List<GH_Number>, stores building parameters
                        List<GH_Number> buildingParams = new List<GH_Number>();
                        GH_Path pth3 = new GH_Path(i, parcelPathIdx, 0);
                        this.DataTree.AppendRange(buildingParams, pth3);*/

                        parcelPathIdx++;
                    }
                        
                }
                else { Exception e = new Exception("Parcel at index " + j + " is either invalid or not a polyline."); } 
            }
            int parcelNr = parcelPathIdx++;
            nrOfParcels.Add(parcelNr); 
            
        }         


    }

    //method that checks if point is inside curve
  public static bool IsInside(Point3d _pt, Polyline _crv) { //... }

}

Posts: 3

Participants: 2

Read full topic

Which component class should I use to change the behavior of a number_slider?

$
0
0

@ivelin.peychev wrote:

Is it special class or simply GH_Component with custom attributes?

Here as far as I understand ghpython is derived from a special type. Is there something special for sliders too?

image

Thanks in advance

Posts: 2

Participants: 2

Read full topic


Is there a way to make Galapagos work with Domains instead of sliders?

Get brep Interior curves

Flange/Extrusion with Draft Angle in Grasshopper

$
0
0

@Cadworx wrote:

Rhino offers the functionality of extruding an edge, curve or profile along a vector with an additional draft angle or taper. Found this this pic in the forum :

Why isnt this available in Grasshopper?

This would be so handy. I use extrusions with draft angles daily. Workarounds are a hassle!

Please add this to the Grasshopper toolset! .

Additionally this tool might output “edges” as well to use with the new fillet edges tool!

Best regards,

Cadworx

Posts: 2

Participants: 2

Read full topic

How to call rhino6 devloft command in python?

$
0
0

@thomas.sicouri wrote:

Hello,
i am currently developing a method to create complex geometries out of a developable surface.

In that purpose, I am trying to test some of my resulting curves geometries inside a python grasshopper for more efficiency.
Since that command doesn’t not exist in rhinoscript syntax i was wondering if there was a possibility to parametrize it anyway in a python script ?

Thanks

Posts: 2

Participants: 2

Read full topic

C#_CurveTransform_VisualStudio

$
0
0

@obhagwat29 wrote:

Hello,
I am successfully able to scale the curves as I wanted in C# grasshopper,
but when I use same code in VS after build solution succeeded, in Grasshopper it is showing me error.
where am I going wrong?
attached scrip and picture of image

List<Curve>floorCurves = new List<Curve>();
for(int k =0; k<allFloors.Count; k++)
{
    allFloors[k].DuplicateCurve();
    Curve c = allFloors[k];
    AreaMassProperties cA = AreaMassProperties.Compute(c);
    Point3d cent = cA.Centroid;
    double sk = Math.Sin(k * Scale);
    double sC = (sk - (-1)) / (1 - (-1)) * (1 - 0.85) + 0.85;
    //Remap Formula
    //(Value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
    Transform scl = Transform.Scale(cent, sC );
    c.Transform(scl);
    Curve cO = c;
    floorCurves.Add(cO);
}
return floorCurves;

11

Posts: 7

Participants: 2

Read full topic

Viewing all 3652 articles
Browse latest View live


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