About archiving a file

hi everyone
i am try to save a archive in one step without enter a dialog.
i try the " Archiving Curves to a File" on web but its not create a new file and fail

i use SDK c++ this is my code

CRhinoGetObject go;
		go.SetCommandPrompt(L"Select curve ");
		go.GetObjects(1, 1);
		if (go.CommandResult() != success)
		return go.CommandResult();
		const ON_Curve* curve = go.Object(0).Curve();
		if (0 == curve)
			return failure;

		bool rc = false;
			const wchar_t  * filename = L"Rwrite.jpg";
			//const wchar_t  * filemode = L"wb";

		FILE* fp = ON::OpenFile(filename, L"w");
		if (fp)
			rc = WriteCurveFile(fp, curve);

		if (rc)
			RhinoApp().Print(L"Successfully wrote %s.\n", filename);
			RhinoApp().Print(L"Errors while writing %s.\n", filename);
	return success;

this code is on web and that can build a command but always stop at " FILE* fp = ON::OpenFile(filename, L"w");" this line.

You should specify the full file name, including the directory. Otherwise, it tries to write into the working directory which is the install directory of Rhino. Usually, this is C:\Program Files\Rhino 6\System and that is write protected, so opening the file there will lead to failure.

Hi @tll4568523,

Here a working sample you can try:


– Dale

@menno @dale thank you both very much. it’s helpful.
Have a good day.

Hi and excuse me. For the same topic
After i creating a picture file(maybe a .jpg file)
How can i put my object at rhino into there.
i do not find the code to change a curve or other thing into a picture.

The second question is that is there the c++ code can’t be used in rhino function?
Like we have to use “ON::OpenFile” instead of “fopen”

Hi I don’t understand the first question. Do you want to use your jpg file as a background image with you Rhino object in the foreground?
On the second if I understand correctly you are asking whether you can mix Rhinoscript with cpp. I don’t think this is possible : you have lots of different scripting languages available but you can’t mix them except for calling rhino commands from the other languages.

to @Dancergraham ,yes,but the jpg file doesn’t have anything before this work. In easy way to say is that I want to save my Rhino painting to a jpg file just in only one command without enter the dialog which is appear as we take the “Save” features.So i trying to create a empty file and throw something in. but now I don’t know what’s the code I needed to transform objects or the format my objects in painting need to transform to.

And thanks a lot for the second answer!

So you are trying to save a screenshot?

Yes, it’s my direction and if it can save only the object which i selected that will be better.
The background will be complex, include coordinate、gray_mesh background.etc,if save the screenshot. But now I even can not save the screenshot. lol…

Hi @tll4568523,

Keep in mind that the sample I provided (above) does not write (nor read) a Rhino 3dm file. Rather, it simply demonstrates how to write some geometry (a curve in this case) to a binary file.

If all you want to to is write a a bitmap to this binary file, in addition to a curve, then I suggest looking at the ON_WindowsBitmap class, as it can serialized just like an ON_Curve. In Rhino, you can use the CRhinoDib helper class to assist in creating bitmaps.

If you are trying to save a thumbnail image, something that you can view from Explorer, then that is a much different issue.

– Dale

To @dale
Ok,I will look for given information to try.thanks a lot!