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

Tekla link update

$
0
0

@tim.messer wrote:

I currently use a telka live link, it allows rhino to link with tekla in “live”.

The problem is that editing grasshopper is not possible if tekla isn’t open. This causes an issue as fast editing of the script isn’t possible now, as it must run live with all build models linked from rhino to tekla. Which is you have a large build takes a while to complete. I used to be able to edit all lines and calcs up to import without building into tekla.

This is a problem that has come into play in the latest update to grasshopper V1, from what I can tell. please note I am not a developer I am only a user, that would like to see if we can tell Tekla what they should look for to change it back.

The error is from the list of error is:
failed to deserialize itself: The type initializer for Tekla.Structures.ModelInternal.DelegateProxy’ threw an exception.

Posts: 1

Participants: 1

Read full topic


GH: Point3dList.ClosestIndex() Extremely slow - why?

$
0
0

@RIL wrote:

For some reason the Point3dList suddenly seems very slow.

I’m prototyping two versions of a component, one working directly on a mesh and it’s Vertices list, and the other working on a pointlist from the input (same points from the same mesh). I mainly use the function mesh.ClosestPoint(pt) and Point3dList.ClosestIndex(pt) respectively, but the Point3dList method is extremely slow compared to the mesh ditto.

Profiling info shows that the mesh doesn’t even show up on the radar while the Point3dList spends 500+ms doing exactly the same job. (Important: I’m not reloading the pointlist each time, I hold a cached version which reloads only if the lits changes, which it never does after first read)

Fig 1. The upper component works on a pointlist and the lower directly on the mesh.

The code that differs is minimal:

  private bool SomeMethod(Mesh mesh, Point3d from_pt, ...)
  {
    hit_point = mesh.ClosestPoint(from_pt);    
    // ...
    var pt = mesh.ClosestPoint(some_pt);

End the Point3dList version:

  private bool SomeMethod(ref Point3dList pointcloud, Point3d from_pt... )
  {
    var ix = pointcloud.ClosestIndex(from_pt);
    hit_point = pointcloud[ix];
    // ...
    ix = pointcloud.ClosestIndex(some_pt);
    var pt = pointcloud[ix];

The number of points is about 224.000, but why is Point3dList.ClosestIndex() so much slower than the mesh ditto?

// Rolf

Posts: 5

Participants: 3

Read full topic

How to iterate layers

$
0
0

@zhipengli1995 wrote:

for some purpose, I want to iterate all layers in a document in python
well, there are several ways, for example:
(1) get the list of the names of all layers, so we can write:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

list =  rs.LayerNames()

for current_layer in list:
    layer = sc.doc.Layers.FindName(current_layer)
    print layer

(2)get the number of all layers, the use for loop:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

layer_num = rs.LayerCount()
for current_layer in range(layer_num):
    layer = sc.doc.Layers.FindIndex(current_layer)
    print layer

it seems that I find the third way, use sc.doc.Layers.GetEnumerator(), but I don’t know how to continue. I guess it well be a more advanced solution.
anyone can help me ? thank you

Posts: 1

Participants: 1

Read full topic

Reference surface read as null

$
0
0

@youssef_aboualghar wrote:

Hello guys, my question is kinda basic here but it has been screwing my head up for hours and hours

I’m developping this flocking plugin based on Long Nguyen’s definition for flocking.
I’m converting a 2d flock into a flock to UV coordinates.

the surface is well referenced in rhino to grasshopper. but when I get into my class it gives me a null reference exception

any help would be much appreciate I’ve been trying for hours and no luck

Here is my difinition:

namespace SurfaceTrails2.FlockingOnSrf
{
public class GhcFlockingOnSrf : GH_Component
{
private FlockSystem flockSystem;

    public GhcFlockingOnSrf()
        : base(
              "Flocking on surface",
              "FlockOnSrf",
              "Creates a swarm on a surface",
              "YFAtools",
              "AgentBased")
    {
    }


    protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
    {
        pManager.AddBooleanParameter("Reset", "Reset", "Reset", GH_ParamAccess.item, false);
        pManager.AddBooleanParameter("Play", "Play", "Play", GH_ParamAccess.item, false);
        //pManager.AddBooleanParameter("3D", "3D", "3D", GH_ParamAccess.item, true);
        pManager.AddSurfaceParameter("srf", "srf", "srf", GH_ParamAccess.item);
        pManager.AddIntegerParameter("Count", "Count", "Number of Agents", GH_ParamAccess.item, 50);
        pManager.AddNumberParameter("Timestep", "Timestep", "Timestep", GH_ParamAccess.item, 0.02);
        pManager.AddNumberParameter("Neighbourhood Radius", "Neighbourhood Radius", "Neighbourhood Radius", GH_ParamAccess.item, 3.5);
        pManager.AddNumberParameter("Alignment", "Alignment", "Alignment", GH_ParamAccess.item, 0.5);
        pManager.AddNumberParameter("Cohesion", "Cohesion", "Cohesion", GH_ParamAccess.item, 0.5);
        pManager.AddNumberParameter("Separation", "Separation", "Separation", GH_ParamAccess.item, 0.5);
        pManager.AddNumberParameter("Separation Distance", "Separation Distance", "Separation Distance", GH_ParamAccess.item, 1.5);
        pManager.AddCircleParameter("Repellers", "Repellers", "Repellers", GH_ParamAccess.list);
        pManager[10].Optional = true;
        pManager.AddBooleanParameter("Use Parallel", "Use Parallel", "Use Parallel", GH_ParamAccess.item, false);
        pManager.AddBooleanParameter("Use R-Tree", "Use R-Tree", "Use R-Tree", GH_ParamAccess.item, false);
    }


    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
    {
        pManager.AddTextParameter("Info", "Info", "Information", GH_ParamAccess.item);
        pManager.AddPointParameter("Positions", "Positions", "The agent positions", GH_ParamAccess.list);
        pManager.AddVectorParameter("Velocities", "Velocities", "The agent veloctiies", GH_ParamAccess.list);
    }


    protected override void SolveInstance(IGH_DataAccess DA)
    {
        // ===============================================================================================
        // Read input parameters
        // ===============================================================================================

         bool iReset = true;
        bool iPlay = false;
        //bool i3D = false;
        Surface surface = null;
        int iCount = 0;
        double iTimestep = 0.0;
        double iNeighbourhoodRadius = 0.0;
        double iAlignment = 0.0;
        double iCohesion = 0.0;
        double iSeparation = 0.0;
        double iSeparationDistance = 0.0;
        List<Circle> iRepellers = new List<Circle>();
        bool iUseParallel = false;
        bool iUseRTree = false;

        DA.GetData("Reset", ref iReset);
        DA.GetData("Play", ref iPlay);
        //DA.GetData("3D", ref i3D);
        DA.GetData("srf", ref surface);
        DA.GetData("Count", ref iCount);
        DA.GetData("Timestep", ref iTimestep);
        DA.GetData("Neighbourhood Radius", ref iNeighbourhoodRadius);
        DA.GetData("Alignment", ref iAlignment);
        DA.GetData("Cohesion", ref iCohesion);
        DA.GetData("Separation", ref iSeparation);
        DA.GetData("Separation Distance", ref iSeparationDistance);
        DA.GetDataList("Repellers", iRepellers);
        DA.GetData("Use Parallel", ref iUseParallel);
        DA.GetData("Use R-Tree", ref iUseRTree);


        // ===============================================================================================
        // Read input parameters
        // ===============================================================================================


        if (iReset || flockSystem == null)
        {
            flockSystem = new FlockSystem(iCount/*, i3D*/,surface);
        }
        else
        {
            // ===============================================================================================
            // Assign the input parameters to the corresponding variables in the  "flockSystem" object
            // ===============================================================================================

            flockSystem.Timestep = iTimestep;
            flockSystem.NeighbourhoodRadius = iNeighbourhoodRadius;
            flockSystem.AlignmentStrength = iAlignment;
            flockSystem.CohesionStrength = iCohesion;
            flockSystem.SeparationStrength = iSeparation;
            flockSystem.SeparationDistance = iSeparationDistance;
            flockSystem.Repellers = iRepellers;
            flockSystem.UseParallel = iUseParallel;


            // ===============================================================================
            // Update the flock
            // ===============================================================================

            if (iUseRTree)
                flockSystem.UpdateUsingRTree();
            else
                flockSystem.Update();

            if (iPlay) ExpireSolution(true);
        }

        // ===============================================================================
        // Output the agent positions and velocities so we can see them on display
        // ===============================================================================

        // Reparameterize Surface (You're not reparameterizing the surface here)
      

        List<GH_Point> positions = new List<GH_Point>();
        List<GH_Vector> velocities = new List<GH_Vector>();

        foreach (FlockAgent agent in flockSystem.Agents)
        {
            var pointToTranslate = agent.Position;
            positions.Add(new GH_Point(surface.PointAt(pointToTranslate.X, pointToTranslate.Y)));
            velocities.Add(new GH_Vector(agent.Velocity));
        }

        DA.SetDataList("Positions", positions);
        DA.SetDataList("Velocities", velocities);
    }

and here is the class that won’t reference correctly

Thanks.

Posts: 2

Participants: 2

Read full topic

Trouble Overriding Custom UI in GH_Component methods

$
0
0

@Nguyen_Minh_Chau wrote:

Hi all,

I’m trying to custom grasshopper by override certain methods in GH_Component. However, there are two errors. Not sure if I’m missing something obvious here.

public class MyClass : GH_Component
{
            ↓↓↓↓↓↓↓↓
  protected override void AppendAdditionalComponentMenuItems(System.Windows.Forms.ToolStripDropDown menu)
  {
                                            ↓↓↓↓
    base.AppendAdditionalComponentMenuItems(menu);
    Menu_AppendItem(menu, "My Custom Menu Item");
    Menu_AppendObjectNameEx(menu);
  }
}

I have two error at the bold words.

1: Override. It says There is no suitable methods for override (There is obviously is!?)
2. Menu: Argument type is not assignable to parameter type (how can it be not suitable when they are exactly the same type. I already included System.WindowsForms)

Some people on SpaceSyntax encountered similar problem before but they were answered to check the base class, in this case is GH_Component.

Thank you very much!

Posts: 2

Participants: 2

Read full topic

Mapping points to surface

$
0
0

@youssef_aboualghar wrote:

Alright, so I’m trying to map boids on a surface to make a flocking behavior on a surface for my new plugin
(based on long Nguyen’s workshop)

My approach was to convert positions to UV parameters by remapping x,y values of points in 2d to surface domain in U and V.

It doesn’t give the desired effect can anyone help me with this ?

thanks.
here is the code

using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;

namespace SurfaceTrails2.FlockingMapToSurface
{
public class GhcFlockingSimulation : GH_Component
{
private FlockSystem flockSystem;

    public GhcFlockingSimulation()
        : base(
              "Flocking Map To Surface",
              "FlockingMapToSurface",
              "Flocking Map To Surface",
              "YFAtools",
              "AgentBased")
    {
    }


    protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
    {
        pManager.AddBooleanParameter("Reset", "Reset", "Reset", GH_ParamAccess.item, false);
        pManager.AddBooleanParameter("Play", "Play", "Play", GH_ParamAccess.item, false);
        pManager.AddBooleanParameter("3D", "3D", "3D", GH_ParamAccess.item, true);
        pManager.AddSurfaceParameter("srf", "srf", "srf", GH_ParamAccess.item);
        pManager.AddIntegerParameter("Count", "Count", "Number of Agents", GH_ParamAccess.item, 50);
        pManager.AddNumberParameter("Timestep", "Timestep", "Timestep", GH_ParamAccess.item, 0.02);
        pManager.AddNumberParameter("Neighbourhood Radius", "Neighbourhood Radius", "Neighbourhood Radius", GH_ParamAccess.item, 3.5);
        pManager.AddNumberParameter("Alignment", "Alignment", "Alignment", GH_ParamAccess.item, 0.5);
        pManager.AddNumberParameter("Cohesion", "Cohesion", "Cohesion", GH_ParamAccess.item, 0.5);
        pManager.AddNumberParameter("Separation", "Separation", "Separation", GH_ParamAccess.item, 0.5);
        pManager.AddNumberParameter("Separation Distance", "Separation Distance", "Separation Distance", GH_ParamAccess.item, 1.5);
        pManager.AddCircleParameter("Repellers", "Repellers", "Repellers", GH_ParamAccess.list);
        pManager[10].Optional = true;
        pManager.AddBooleanParameter("Use Parallel", "Use Parallel", "Use Parallel", GH_ParamAccess.item, false);
        pManager.AddBooleanParameter("Use R-Tree", "Use R-Tree", "Use R-Tree", GH_ParamAccess.item, false);
    }


    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
    {
        pManager.AddTextParameter("Info", "Info", "Information", GH_ParamAccess.item);
        pManager.AddPointParameter("Positions", "Positions", "The agent positions", GH_ParamAccess.list);
        pManager.AddVectorParameter("Velocities", "Velocities", "The agent veloctiies", GH_ParamAccess.list);
    }


    protected override void SolveInstance(IGH_DataAccess DA)
    {
        // ===============================================================================================
        // Read input parameters
        // ===============================================================================================

        bool iReset = true;
        bool iPlay = false;
        bool i3D = false;
        Surface baseSurface = null;
        int iCount = 0;
        double iTimestep = 0.0;
        double iNeighbourhoodRadius = 0.0;
        double iAlignment = 0.0;
        double iCohesion = 0.0;
        double iSeparation = 0.0;
        double iSeparationDistance = 0.0;
        List<Circle> iRepellers = new List<Circle>();
        bool iUseParallel = false;
        bool iUseRTree = false;

        DA.GetData("Reset", ref iReset);
        DA.GetData("Play", ref iPlay);
        DA.GetData("3D", ref i3D);
        DA.GetData("srf", ref baseSurface);
        DA.GetData("Count", ref iCount);
        DA.GetData("Timestep", ref iTimestep);
        DA.GetData("Neighbourhood Radius", ref iNeighbourhoodRadius);
        DA.GetData("Alignment", ref iAlignment);
        DA.GetData("Cohesion", ref iCohesion);
        DA.GetData("Separation", ref iSeparation);
        DA.GetData("Separation Distance", ref iSeparationDistance);
        DA.GetDataList("Repellers", iRepellers);
        DA.GetData("Use Parallel", ref iUseParallel);
        DA.GetData("Use R-Tree", ref iUseRTree);


        // ===============================================================================================
        // Read input parameters
        // ===============================================================================================

        if (iReset || flockSystem == null)
        {
            flockSystem = new FlockSystem(iCount, i3D);
        }
        else
        {
            // ===============================================================================================
            // Assign the input parameters to the corresponding variables in the  "flockSystem" object
            // ===============================================================================================

            flockSystem.Timestep = iTimestep;
            flockSystem.NeighbourhoodRadius = iNeighbourhoodRadius;
            flockSystem.AlignmentStrength = iAlignment;
            flockSystem.CohesionStrength = iCohesion;
            flockSystem.SeparationStrength = iSeparation;
            flockSystem.SeparationDistance = iSeparationDistance;
            flockSystem.Repellers = iRepellers;
            flockSystem.UseParallel = iUseParallel;


            // ===============================================================================
            // Update the flock
            // ===============================================================================

            if (iUseRTree)
                flockSystem.UpdateUsingRTree();
            else
                flockSystem.Update();

            if (iPlay) ExpireSolution(true);
        }

        // ===============================================================================
        // Output the agent positions and velocities so we can see them on display
        // ===============================================================================

        List<GH_Point> positions = new List<GH_Point>();
        List<GH_Vector> velocities = new List<GH_Vector>();
        List<GH_Point> surfacePositions = new List<GH_Point>();

        var surface = baseSurface.ToNurbsSurface();
        foreach (FlockAgent agent in flockSystem.Agents)
        {
            positions.Add(new GH_Point(agent.Position));
            velocities.Add(new GH_Vector(agent.Velocity));


            // ===============================================================================
            // Position on surface 
            // ===============================================================================
            Interval u = new Interval(0, 1);
            Interval v = new Interval(0, 1);

            surface.SetDomain(0, u);
            surface.SetDomain(1, v);



            var remappedU = NumberOperations.remap(0,1,surface.Domain(0).T0,surface.Domain(0).T1,agent.Position.X);
            var remappedV = NumberOperations.remap(0,1,surface.Domain(1).T0,surface.Domain(1).T1,agent.Position.Y);

            surfacePositions.Add(new GH_Point(surface.PointAt(remappedU, remappedV)/*surface.PointAt(agent.Position.X, agent.Position.Y*/)); 

        }

       

        DA.SetDataList("Positions", surfacePositions);
        DA.SetDataList("Velocities", velocities);
    }


    protected override System.Drawing.Bitmap Icon { get { return Properties.Resources._28_8_18_FlockSimulation; } }


    public override Guid ComponentGuid { get { return new Guid("7066d2ac-3c0a-47db-b22f-4d8c25bf8baa"); } }
}

}

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Rhino.Geometry;

namespace SurfaceTrails2.FlockingMapToSurface
{
public class FlockSystem
{
public List Agents;

    public double Timestep;
    public double NeighbourhoodRadius;
    public double AlignmentStrength;
    public double CohesionStrength;
    public double SeparationStrength;
    public double SeparationDistance;
    public List<Circle> Repellers;
    public bool UseParallel;


    public FlockSystem(int agentCount, bool is3D)
    {
        Agents = new List<FlockAgent>();

        if (is3D)
            for (int i = 0; i < agentCount; i++)
            {
                FlockAgent agent = new FlockAgent(
                    Util.GetRandomPoint(0.0, 30.0, 0.0, 30.0, 0.0, 30.0),
                    Util.GetRandomUnitVector() * 4.0);

                agent.FlockSystem = this;

                Agents.Add(agent);
            }
        else
            for (int i = 0; i < agentCount; i++)
            {
                FlockAgent agent = new FlockAgent(
                    Util.GetRandomPoint(0.0, 30.0, 0.0, 30.0, 0.0, 0.0),
                    Util.GetRandomUnitVectorXY() * 4.0);

                agent.FlockSystem = this;

                Agents.Add(agent);
            }
    }


    private List<FlockAgent> FindNeighbours(FlockAgent agent)
    {
        List<FlockAgent> neighbours = new List<FlockAgent>();

        foreach (FlockAgent neighbour in Agents)
            if (neighbour != agent && neighbour.Position.DistanceTo(agent.Position) < NeighbourhoodRadius)
                neighbours.Add(neighbour);

        return neighbours;
    }

    private void ComputeAgentDesiredVelocity(FlockAgent agent)
    {
        List<FlockAgent> neighbours = FindNeighbours(agent);
        agent.ComputeDesiredVelocity(neighbours);
    }


    public void Update()
    {
        if (UseParallel)
            Parallel.ForEach(Agents, ComputeAgentDesiredVelocity);
        else
            foreach (FlockAgent agent in Agents)
                ComputeAgentDesiredVelocity(agent);

        // Once the desired velocity for each agent has been computed, we update each position and velocity
        foreach (FlockAgent agent in Agents)
            agent.UpdateVelocityAndPosition();
    }


    public void UpdateUsingRTree()
    {
        /* First, build the R-Tree */

        RTree rTree = new RTree();

        for (int i = 0; i < Agents.Count; i++)
            rTree.Insert(Agents[i].Position, i);

        /* Then, we use the R-Tree to find the neighbours
            and compute the desired velocity */

        foreach (FlockAgent agent in Agents)
        {
            List<FlockAgent> neighbours = new List<FlockAgent>();

            EventHandler<RTreeEventArgs> rTreeCallback =
            (object sender, RTreeEventArgs args) =>
            {
                if (Agents[args.Id] != agent)
                    neighbours.Add(Agents[args.Id]);
            };

            rTree.Search(new Sphere(agent.Position, NeighbourhoodRadius), rTreeCallback);

            agent.ComputeDesiredVelocity(neighbours);
        }



        // Once the desired velocity for each agent has been computed, we can update each position and velocity               
        foreach (FlockAgent agent in Agents) agent.UpdateVelocityAndPosition();
    }
}

}

using System.Collections.Generic;
using Rhino.Geometry;

namespace SurfaceTrails2.FlockingMapToSurface
{
public class FlockAgent
{
public Point3d Position;
public Vector3d Velocity;

    public FlockSystem FlockSystem;

    private Vector3d desiredVelocity;
  private  double boundingBoxSize = 1;

    public double BoundingBox
    {
        get { return boundingBoxSize;} set { boundingBoxSize=value; } }

    public FlockAgent(Point3d position, Vector3d velocity)
    {
        Position = position;
        Velocity = velocity;
    }
     
    public void UpdateVelocityAndPosition()
    {
        Velocity = 0.97 * Velocity + 0.03 * desiredVelocity;

        if (Velocity.Length > 8.0) Velocity *= 8.0 / Velocity.Length;
        else if (Velocity.Length < 4.0) Velocity *= 4.0 / Velocity.Length;

        Position += Velocity * FlockSystem.Timestep;
    }



    public void ComputeDesiredVelocity(List<FlockAgent> neighbours)
    {
        // First, reset the desired velocity to 0
        desiredVelocity = new Vector3d(0.0, 0.0, 0.0);

        // ===============================================================================
        // Pull the agent back if it gets out of the bounding box 
        // ===============================================================================

        

        if (Position.X < 0.0)
            desiredVelocity += new Vector3d(-Position.X, 0.0, 0.0);
        else if (Position.X > boundingBoxSize)
            desiredVelocity += new Vector3d(boundingBoxSize - Position.X, 0.0, 0.0);

        if (Position.Y < 0.0)
            desiredVelocity += new Vector3d(0.0, -Position.Y, 0.0);
        else if (Position.Y > boundingBoxSize)
            desiredVelocity += new Vector3d(0.0, boundingBoxSize - Position.Y, 0.0);

        if (Position.Z < 0.0)
            desiredVelocity += new Vector3d(0.0, 0.0, -Position.Z);
        else if (Position.Z > boundingBoxSize)
            desiredVelocity += new Vector3d(0.0, 0.0, boundingBoxSize - Position.Z);


        // ===============================================================================
        // If there are no neighbours nearby, the agent will maintain its veloctiy,
        // else it will perform the "alignment", "cohension" and "separation" behaviours
        // ===============================================================================

        if (neighbours.Count == 0)
            desiredVelocity += Velocity; // maintain the current velocity
        else
        {
            // -------------------------------------------------------------------------------
            // "Alignment" behavior 
            // -------------------------------------------------------------------------------

            Vector3d alignment = Vector3d.Zero;

            foreach (FlockAgent neighbour in neighbours)
                alignment += neighbour.Velocity;

            // We divide by the number of neighbours to actually get their average velocity
            alignment /= neighbours.Count;

            desiredVelocity += FlockSystem.AlignmentStrength * alignment;


            // -------------------------------------------------------------------------------
            // "Cohesion" behavior 
            // -------------------------------------------------------------------------------

            Point3d centre = Point3d.Origin;

            foreach (FlockAgent neighbour in neighbours)
                centre += neighbour.Position;

            // We divide by the number of neighbours to actually get their centre of mass
            centre /= neighbours.Count;

            Vector3d cohesion = centre - Position;

            desiredVelocity += FlockSystem.CohesionStrength * cohesion;


            // -------------------------------------------------------------------------------
            // "Separation" behavior 
            // -------------------------------------------------------------------------------

            Vector3d separation = Vector3d.Zero;

            foreach (FlockAgent neighbour in neighbours)
            {
                double distanceToNeighbour = Position.DistanceTo(neighbour.Position);

                if (distanceToNeighbour < FlockSystem.SeparationDistance)
                {
                    Vector3d getAway = Position - neighbour.Position;

                    /* We scale the getAway vector by inverse of distanceToNeighbour to make 
                       the getAway vector bigger as the agent gets closer to its neighbour */
                    separation += getAway / (getAway.Length * distanceToNeighbour);
                }


            }

            desiredVelocity += FlockSystem.SeparationStrength * separation;
        }


        // ===============================================================================
        // Avoiding the obstacles (repellers)
        // ===============================================================================

        foreach (Circle repeller in FlockSystem.Repellers)
        {
            double distanceToRepeller = Position.DistanceTo(repeller.Center);

            Vector3d repulsion = Position - repeller.Center;

            // Repulstion gets stronger as the agent gets closer to the repeller
            repulsion /= (repulsion.Length * distanceToRepeller);

            // Repulsion strength is also proportional to the radius of the repeller circle/sphere
            // This allows the user to tweak the repulsion strength by tweaking the radius
            repulsion *= 30.0 * repeller.Radius;

            desiredVelocity += repulsion;

        }
    }
}

}

Posts: 3

Participants: 2

Read full topic

c#_Brep Brep Intersection_nested for loops

$
0
0

@obhagwat29 wrote:

Hello,
I am trying create simple waffle structure using c#. I am always getting a intersection curve at last index and no points in the output. Attached script and image.
Any help would be great!

Tuple<Curve[],Point3d[]> waf = Waffel(x, y, mtrThk);
A = waf.Item1;
B = waf.Item2;

}

//
public Tuple<Curve[],Point3d[]> Waffel(List srfA, List srfB, double thk)
{
double tolr = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

Curve[] crv = null;
Point3d[] iPts = null;
////////////////////////////////////
for(int i = 0; i < srfA.Count; i++)
{
  for(int j = 0; j < srfB.Count;j++)
  {
     Rhino.Geometry.Intersect.Intersection.BrepBrep(srfA[i], srfB[j], tolr, out crv, out iPts);
  }
}
return Tuple.Create(crv, iPts);

}

w1

Posts: 2

Participants: 2

Read full topic

c#_BrepBrep_Boolean Difference Operation

$
0
0

@obhagwat29 wrote:

Script is not giving any output.
I have move the curves in Z direction by half of its length, made them into pipes and now trying to perform BrepBrep boolean operation to create a notch in input surface.

I am not able to resolve an error!
where is it going wrong? have Attached script. and image.

I think i know what’s the problem here, at some indexes there is no intersection taking place and it is returning null due to failure. If that’s right how can I solve it>
Thanks!

//x is a list of surfaces, pi1 is a list of pipes and tolr = tolerance value
List be1 = new List();
for(int k = 0; k < x.Count;k++)
{
for(int l = 0; l < pi1.Count;l++)
{
Brep[] bP = Brep.CreateBooleanDifference(x[k], pi1[l], tolr);
if(bP != null && bP.Length > 0 )
{
be1.AddRange(bP);
}
else continue;
}
}
C = be1;
w2

Posts: 1

Participants: 1

Read full topic


How to make a such user object Like this?

$
0
0

@andrealu2012 wrote:

image
this component is Taco,for robot.
but i find somethin interesting:
most component of Taco is a UserObject,but you cannot open it by double click it,or it cannot have place to input password to open it, it acts like a “gha” component.
image
Can someone know how to do that component?
Thank you very much!

Taco Link in food4rhino:https://www.food4rhino.com/app/taco-abb

Posts: 3

Participants: 3

Read full topic

How to trigger a component serialization?

$
0
0

@ParamDesSing wrote:

How can I trigger a component serialization in code, using C#?

I have implemented Read and Write (which works when, for example, saving the definition), but would like to trigger Write also by myself.

Posts: 6

Participants: 3

Read full topic

c#_DataTree_alternate selection of Objects

$
0
0

@obhagwat29 wrote:

Hello,
I have divided the curves by length factor. I want to select the output points alternatively. I am able to sort them alternatively using DataTree. Since all the branch item counts are not same, last few points I am not able to select.
Any help in this regard would be great!

ps.1) I am pretty new to c# and trying out data tree in c# for the first time. I would like to know more about it, if there is any material out on this please let me know.

  1. Attached image, script and GH file with internalised geometry

    DataTree < Point3d > pD1 = new DataTree();
    DataTree < Point3d > fD1 = new DataTree();

// bC1 is list of curves

for(int k = 0; k < bC1.Count; k++)
{
  Point3d[] p1;
  bC1[k].DivideByLength(0.5, true, out p1);
  GH_Path gP1 = new GH_Path(k); 
  pD1.AddRange(p1, gP1);
}
for(int l = 0; l < pD1.BranchCount; l++)
{
  for(int m = 0;m < pD1.Branch(3).Count;m += 2)
  {
    GH_Path gF1 = new GH_Path(l); 
    fD1.Add(pD1.Branch(l)[m], gF1);
  }
}

B = pD1;
C = fD1;


d2
05_Brick Wall.gh (23.3 KB)

Posts: 2

Participants: 2

Read full topic

Missing API documentation?

$
0
0

@ivelin.peychev wrote:

Could anyone tell me where can I find the API entry for

Grasshopper.Environment ?
Grasshopper.Kernel.Special ?

Thanks in advance.

Posts: 6

Participants: 2

Read full topic

Random points are not generated inside brep despite a correct code

$
0
0

@youssef_aboualghar wrote:

Hello guys,

So I’m this code to make boids inside a brep and everything seems to work just fine except that I’m using a correct code to generate points inside a brep.
yet it doesn’t work.
can anybody tell me why > ?
here is the code :

public class FlockSystem
{
public List Agents;

    public double Timestep;
    public double NeighbourhoodRadius;
    public double AlignmentStrength;
    public double CohesionStrength;
    public double SeparationStrength;
    public double SeparationDistance;
    public List<Circle> Repellers;
    public bool UseParallel;
    public Brep Brep;
    Random random = new Random();

    public Box BBox { get; set; }  
    public Point3d Min { get; set; }
    public Point3d Max { get; set; }
    public FlockSystem(int agentCount,Brep brep)
    {
        Brep = brep;
        Agents = new List<FlockAgent>();

        var box = Box.Unset;
        brep.GetBoundingBox(Plane.WorldXY, out box);
        var min = box.PointAt(0,0,0);
        var max = box.PointAt(1, 1, 1);

        BBox = box;
        this.Min = min;
        this.Max = max;

      //for(int i =0;i<agentCount;i++)
        Parallel.For(0, agentCount, (i, loopState) =>
        {
            //var randPt = Util.GetRandomPoint(min.X, max.Y, min.Z, max.X, min.Y, max.Z);
            var randPt = box.PointAt(random.NextDouble(), random.NextDouble(), random.NextDouble());


            if (Brep.IsPointInside(randPt, 0.01, false))
            {
                FlockAgent agent = new FlockAgent(
                randPt,
                Util.GetRandomUnitVector() * 4.0);
                agent.FlockSystem = this;
                Agents.Add(agent);
            }
            if (Agents.Count == agentCount)
            {
                loopState.Break();
            }
        });
    }

thanks a lot :wink:

Posts: 12

Participants: 3

Read full topic

To select panels in gradiating order.. from zero to to solid.. pixelated fade if that makes sense

$
0
0

@ajmal.majeed.v wrote:

I have been trying to find a script of tutorial to cull the panels on a surface with a incremental/ Gradiating effect.
Been stuck on this for 3 days… any help would be wonderful!

Posts: 5

Participants: 2

Read full topic

Cluster containing self updating component doesn't update itself


I broke the NumberSlider

Decimal "too small" or "too large"?

How to put a icon in this place?

$
0
0

@andrealu2012 wrote:

image
Hello everyone,i am doing a custom component tool box,but how can i change the icon which default is character,which method can be use in gh API?
thank you!

Posts: 3

Participants: 2

Read full topic

Sorting and Combining Lists

$
0
0

@rmjohnston wrote:

I’m going to try to state this as simple as possible but I’ve been thinking about this for a while so I might ramble…

I have two lists and I need to sort the lists. List A holds values and I need to sort them by List B.

To demonstrate this better imagine I have a surface assigned to Item 1 of List A and it corresponds to Item 1 of List B (and this continues for all 400+ list items). I need to filter the list by list B.

In the picture you’ll see that items 0 and 1 need to be filtered into a ‘Midrise 1’ list. Items 2, 3, and 4 need to be filtered into a ‘Midrise 2’ list. From there I need to isolate the items in the ‘Midrise 1’ list and the items in ‘Midrise 2’ List.

Does anyone have any idea how to filter/sort these?

Posts: 10

Participants: 2

Read full topic

Custom door with VisualArq and Grasshopper

Viewing all 3639 articles
Browse latest View live


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