Grasshopper

algorithmic modeling for Rhino

Hello everyone, 

I am currently scripting using the Rhino.Geometry library in ghPython.
I encounter often the same problem:

I want to use the original data (let's say a vector), which has been transformed (by unitizing it), after the transformation.

print V

UnitizedV = rg.Vector3d.Unitize(V)
print V

V is different before and after the transformation, and UnitizedV is just a boolean.
Then I can't use the original V later in the script. 
The problem is the same, each time I want to deal with any type of tranformations (plane translations, scaling objects, etc...)

I tried to rename the variables, append them in lists, I didn't figure out. Then I decided to use rhinoscriptsyntax because you don't get this type of problem but I hate using it because of all the GUID problems.


I hope I was clear enough.

Attached you will find the GH example.

Best, 

Roger

Views: 1866

Replies to This Discussion

Hi Roger,

You are experiencing a transformation in place - while rhinoscriptsyntax function would create a new instance of your initial "V" vector and unitize it, RhinoCommon method would edit the present one. Vector3d.Unitize method returns either True or False informing the user if vector has been unitized or not.

Putting it in a new list or variable, would not help, because python will always reference the same vector.

To use the initial "V" vector, create a new instance before unitizing it:

print V
unitizedV = rg.Vector3d(V)
rg.Vector3d.Unitize(unitizedV)
print unitizedV

Attachments:

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