Grasshopper

algorithmic modeling for Rhino

hi all,am a beginner of vb coding in grasshopper,recently im focusing on how to use the VB compenent,but something i cant understand stopped me .

the files of rhino and gh i uploaded contains 2 VB componets. the 1st is recursion i practice which a line rotate and scale until its length reach some certain unmber i setted.

the export side is a list (of online), which contains every scaled line(i thought it should be!!!!0,but the truth is that it export some same lines,everyone of them is the last line scaled and rotated at the recursion stopping condition!!!

i cant explain how it happen ,so i try another VB  component ,which export list that due to the recursion ,but its not the same as the first one.it sucsessfully exported a list contaned different numbers.

could someone tell me why this happen? 2 VB i used the same structure ,but they exported different!!

thank you !!!

sorry for my poor englinsh!~

Views: 386

Attachments:

Replies to This Discussion

is there someone could explain this to me ?~

OnLine is a reference type, if you add() this to a list, only a reference to the current instance will be saved in the list. You modify the ScaledLine object in the loop but the object instance  will be the same every time you add it to the list. The modification will be applied in every loop.

A number is a value type. Value types will be copied directly to the list. This is why the second script works as you expected.

To add a unique Instance of the line to your list in every loop, you need to create a copy and add the copy:

      lines.add(New OnLine(scaledline))

thank you hannes!

as you said ,i guess all onxxxx type such as on3dpoint oncurve etc is all this type ,ill try this today!

best regards!

Y.tian

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service