Grasshopper

algorithmic modeling for Rhino

This does'nt works

 

List < Curve > curvas = new List<Curve>();  // a list of curves

List < Curve > cdup = new List<Curve>();  // to store duplicates

    for( int i = 0; i < curvas.Count; i++)    

     {      

        cdup = curvas[i].DuplicateCurve(); // just a copy ( I tryed too with Duplicate)

     }

 

the out saids

            {0} 0. Error: No se puede convertir implícitamente el tipo 'Rhino.Geometry.Curve' a 'System.Collections.Generic.List<Rhino.Geometry.Curve>' (line 95)

 

I need a CurveList to duplicate a curve?

Views: 335

Replies to This Discussion

Two problems I see:

  1. curvas doesn't contain any items, it's an empty list.
  2. cdup = curves[i].DuplicateCurve(); cannot be compiled because you're trying to assign a Curve to the cdup variable, which is a List<Curve>. You want to use the Add() function: cdup.Add(curvas[i].DuplicateCurve());

--

David Rutten

david@mcneel.com

Poprad, Slovakia

1.- yes. pretty accurate :) curvas has a feed from outsde as a list. im just trying to isolate the problem. sorry

2.- I understand. Duplicate is a method of the curve class  ( donkey) then .. there is a method to duplicate a list ?

"there is a method to duplicate a list?"


No. The C++ language has instance duplication almost build in, but no such agreement exists for .NET. In fact there are loads of classes that cannot be easily duplicates or indeed duplicated at all.


In RhinoCommon we recognize that this is an important feature though which is why we supply all those DuplicateXXXX() methods. If you want to duplicate a list and the items inside the list, you'll need to do something like:


List<whatever> dupList = new List<whatever>();

foreach (whatever item in oldList)

{

  dupList.Add(item.Duplicate());

}

If you want to duplicate a list without also duplicating the items, then it's a bit easier:

List<whatever> dupList = new List<whatever>(oldList);

At this point dupList can be changed (items removed, items added, items re-ordered) and it won't affect oldList. But since both oldList and dupList point to the same items, you cannot change the instances without it affecting both of them.

These kinds of operarations are probably easier if you're using Linq, but if you're starting out with C# or VB I recommend staying away from Linq methods for the time being.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

understood.

then same with trees?.. with arrays...

could be possible , for example , to use stack data to copy paths ( using path as a list)?

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service