Hello
I’m a beginner in python, C# and scripting. Grasshopper mediate. I am fiddling around with the script editor to make a plugin.
I have a python script that moves an object with a mouse click. It reads the distance from a text file (distance.txt) every time it’s executed. The text file only includes the distance, 2 numbers.
#! python 3
import rhinoscriptsyntax as rs
import Rhino
path = “/Users/mko/OneDrive/Work/RhinoStuff/Scripts/distance.txt”
with open(path, “r”) as content:
dist = content.readline()
def MoveDist(dist,dY,dZ):
obj_ids=rs.GetObjects(“Select objects to move”,preselect=True)
if obj_ids:
rs.MoveObjects(obj_ids,Rhino.Geometry.Vector3d(dist,dY,dZ))
MoveDist(0,0,-(int(dist)))
If I would have this script in a plugin, then the path will not work.
To implement the correct path it’s adviced to use the PathfromID comment…which is in C#
// #! csharp
using System;
using System.IO;
using Rhino;
var id = new Guid(“0EDD317A-AF96-4ACB-A282-93DA1FED1940”);
string pluginFile = Rhino.PlugIns.PlugIn.PathFromId(id);
string pluginPath = Path.GetDirectoryName(pluginFile);
string dataFile = Path.Combine(pluginPath, “shared”, “distance.txt”);
Console.WriteLine(dataFile);
Console.WriteLine(File.Exists(dataFile));
How can I combine those two scripts so the path to distance.txt, which will be in the “shared” folder of the plugin, will always be correct, for instance if I send the plugin to colleagues.
regards
Marc
4 posts - 2 participants