Create temp document for test purpose

Hi everyone,

I have some preferences for both RhinoDoc and RhinoObjects for plugin details. In order to test them, I simply want to create this scenario;

(At the beginning of test plugin)

  1. Open temporary RhinoDoc
  2. Create plugin object into temporary RhinoDoc
  3. Save into temp file in the system
  4. Open it again for test purpose to check saved values are true
// at the beginning of test project
RhinoDoc tempDoc = RhinoDoc.Create("docForTestPurpose");
string tempPath = System.IO.Path.GetTempPath();
// ..
// creating some plugin objects there into tempDoc
// ..
var fileWriteOptions = new FileWriteOptions();
bool res = tempDoc.Write3dmFile(tempPath, fileWriteOptions);

I simply tried this, but Write3dmFile method returned false.
Do you have any insight?

Best,
-Oğuzhan

Additively: As I understand after couple of debuggings, SaveAs method is available for v7. When I upgrade Rhinocommon from NuGet, of course I cannot run this functionality in 6.31.20315.17001. Is it possible for similar functionality for v6?

@dale is it someting that you can help?

Hi @oguzhankoral,

Creating a temporary RhinoDoc should be done in Rhino 7.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  var filename = Path.Combine(path, "TestOguzhankoral.3dm");

  using (var rh_doc = RhinoDoc.CreateHeadless(null))
  {
    var offset = 20.0;
    var p0 = new Point3d(0.0, 0.0, 0.0);
    var p1 = new Point3d(offset, 0.0, 0.0);
    var p2 = new Point3d(offset, offset * 0.5, 0.00);
    var p3 = new Point3d(0.0, offset * 0.5, 0.0);

    rh_doc.Objects.AddCurve(new LineCurve(p0, p1));
    rh_doc.Objects.AddCurve(new LineCurve(p1, p2));
    rh_doc.Objects.AddCurve(new LineCurve(p2, p3));
    rh_doc.Objects.AddCurve(new LineCurve(p3, p0));

    rh_doc.SaveAs(filename);
  }

  return Result.Success;
}

If you stuck in Rhino 6, just use a File3dm object.

– Dale