RhinoCommon - SaveAs

Hi,

As the forum moved here since the 4th of july I’ve added all the thread below this message…

Is there no way to pass (maybe temporary) some predefined parameters to the Acad Export plugin, then WriteFile could have all its sub commands questions already filled before running it?

Is there another method than “RunScript” to execute a command? Actually, if a put RunScript within an event, nothing append (by the way the scripted command works if I put it directly within the override RunCommand function).

Thanks,


Hi Martin,

If you want to save in any file format other than 3dm, you will need to
script the Save or SaveAs commands - sorry.


Dale Fugier
Rhinoceros Development
Robert McNeel & Associates


Thanks Dale,

I tried this to save selected objects to DWG. The only problem is that it
stucks on “Write the file using scheme “Scheme Name” (Scheme):”.

Rhino.FileIO.FileWriteOptions options = new Rhino.FileIO.FileWriteOptions();
options.SuppressDialogBoxes = true;
options.WriteSelectedObjectsOnly = true;

options.IncludeRenderMeshes = true; // Save Small
options.WriteGeometryOnly = false; // Geometry Only
options.IncludeBitmapTable = false; // Save Texture

bool result = RhinoDoc.ActiveDoc.WriteFile(“C:\test.dwg”, options);
RhinoApp.WriteLine(“Export selected: {0}”, result);

Thanks


Hi,

Use RhinoDoc.WriteFile.


Dale Fugier
Rhinoceros Development
Robert McNeel & Associates


Is there a method within RhinoCommon where I could directly save selected
objects to a file without using the command (RunScript).

The fact, is I need to save objects to file after receiving a message from
a TCP Client. Calling runscript within a event do not seems to be possible
as far as I know.

Thanks,

Martin

You should be able to do whatever you can when running the “dashed” version of a command from the command line

If I type

-_SaveAs abcd.dwg

on the command line, Rhino next asks for which Scheme I want to use. So I could enter something like “2004 Lines”

-_SaveAs abcd.dwg Scheme “2004 Lines” Enter

This is what you would pass to the RunScript function

If you are only interested in saving selected objects, then use the Export command which is identical to SaveAs except it only uses selected objects.

Hi Steve,

But can I use RunScript within an event?

I would think so. What type of “event” are you referring to here?

I’ve coded a little server that I would like to use to “control” many running instances of rhino at once. So in rhino as my plugin act as a client which listen the instruction of the server, the plugin is waiting for specific instructions by using AsyncCallback.

Actually my server works, the client also, I can print the message received using RhinoApp.WriteLine() within the “Message Receive” even, but if I put RhinoApp.Runscript(), that function seems to do nothing… In fact RhinoApp.Runscript() always return FALSE. I tried this simple line RhinoApp.RunScript("-_Line 0,0,0 10,10,10", false);

Thanks again

Is the code that calls RhinoApp.RunScript running on the main Rhino thread? If it isn’t, try RhinoApp.Invoke which makes your function execute on the main thread.

Do you have a sample of how to use RhinoApp.Invoke? I did not found any method named “Invoke” inside RhinoApp. The only Invoke I found is within RhinoWindow Class. But actually I don’t figure out how to use it…

Thanks

Sorry, yes the function is on RhinoWindow


static void RunScriptOnMainThread()
{
  RhinoApp.RunScript("-_Line 0,0,0 1,1,1", false);
}


RhinoApp.MainApplicationWindow.Invoke(new Action(RunScriptOnMainThread));

Good, the invoke method is working, now I just have to figure out how to pass parameter and return value…
Thanks

static bool CreateLine(int length)  
{
  return RhinoApp.RunScript("-_Line 0,0,0 "+length.toString()+",0,0", false);
}

Any cue on how can to call this function “CreateLine” instead of “RunScriptOnMainThread” by passing a length parameter et return the runscript result?

Thanks

The invoked method runs on a different thread so you can’t really just wait for the function to complete and get a return value. You’ll need to set up a lock to block execution of your server thread while the main thread command executes.

Hi guys,

your discussion was very helpful because I have a similar Problem. Now I want to pass a Surface as a Parameter to the Invoke-method, but I’m totally stuck.

Do you have an idea what I have to do?
Thanks in advance!!
fred

here is a snippet of my script:

    //Parameter
    Surface ExportA;

//defining a new Action<T>-Delagate
 Action<Surface> action = new Action<Surface>(ExportDialog);

//puting the method in the main thread
 RhinoApp.MainApplicationWindow.Invoke(action(ExportA));


//Method to Export the Geometry in .sat
public static void ExportDialog(Surface ExportA)
  {
    //-------------------------------
    //Export Surface in .sat-format
    string filePathSat = "M:\\...";

Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
att.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
att.ObjectColor = Color.Blue;

att.LayerIndex = Rhino.RhinoDoc.ActiveDoc.Layers.Find("myLayer", false);
Rhino.RhinoDoc.ActiveDoc.Objects.AddSurface(ExportA, att);
string xy = "Default";
Rhino.DocObjects.RhinoObject[] rhobjs = Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(xy);
for (int l = 0; l < rhobjs.Length; l++)
  rhobjs[l].Select(true);

string savedLocationSat = filePathSat;

Rhino.RhinoApp.RunScript("-_Export \n\"" + savedLocationSat + "\"\n _Enter", true);

System.Threading.Thread.Sleep(1000);

//Delete Baked Geometry
for(int l = 0; l < rhobjs.Length; l++)
{
  Rhino.RhinoDoc.ActiveDoc.Objects.Delete(rhobjs[l], false);
}

}

1 Like