Hi @michael17,
Here are some sample commands the export and save geometry:
If these samples are not helpful, then we’ll need to have some sample code that we can run here.
– Dale
Hi @michael17,
Here are some sample commands the export and save geometry:
If these samples are not helpful, then we’ll need to have some sample code that we can run here.
– Dale
Dale
See code for plugin :-
Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result
' TODO: start here modifying the behaviour of your command.
'
' get filename for .igs
Dim str_docfile As String = doc.Path.Replace(".3dm", ".igs")
'
' Build script string, use double quote chars in case of spaces within file path string
Dim str_script As String = $"_-Export " & Chr(34) & str_docfile & Chr(34)
'
'
Dim bval As Boolean = True
Dim exp_result As Boolean = False
'
' Write script string to app info
RhinoApp.WriteLine(str_script, EnglishName)
' execute script
exp_result = RhinoApp.RunScript(str_script, True)
' check if .igs file exists
Dim b_exists As Boolean = File.Exists(str_docfile)
MsgBox("Script returned result :- " & exp_result.ToString & vbCrLf _
& "Does .igs exist :- " & b_exists)
'
'
'
Return Result.Success
End Function
See below screen clipping of Rhino screen after execution of the code RhinoApp.RunScript :-

As you can see the contents of the string ‘str_script’ have been echoed to the info line above the command line.
The dialogue box shows that the return result value of the call to RhinoApp.RunScript is False.
Also, even though the 2nd argument of the call was set to True, the command text was not echoed to the Command Line entry.
Further, if I cut/paste the contents of the string in the info line into the Command Line an ‘Export’ operation is initiated although the 2nd part of the script string (i.e. the filename) is rejected as an ‘Unknown command’, see screen snippet :-

If I then proceed and select the model from one of the screens, followed by selecting ‘Enter’ to proceed followed by selecting ‘Browse’ I am then able to save the .igs file.
I think the script string I am passing is being rejected by the RunScript method.
Also, I attach a copy of the VS2017 project folder if you wish to run in debug mode (I am using Rhino 6).
Within the project you will find a defined Class ‘Dolphin Choices’, this is not being used at the moment as I wanted to get the basics working before adding options etc.
We have got a number of CNC applications ready for integration if I can get this basic plugin to execute.
Thanks for all assistance.
Michael
DolphinExport_04Aug2021.zip (726 KB)
Hi @michael17,
There is a difference between SaveAs and Export.
SaveAs will archive the current document to another file. This can be another 3dm file or something else like STEP or IGES.
Export will archive selected objects to a to another file. Again, this can be another 3dm file or something else like STEP or IGES.
With this, make sure you want to use Export over SaveAs.
Also, RhinoDoc.Path will return null on newly created documents that have never been saved. Your code should take this into account.
Again, please refer to the samples I provided (above).
Thanks,
– Dale
Hi @dale , Literally no clue what you are talking about. But if exportselected and saveas create new documents, how would you avoid rhinodoc.path not returning null? would you need to overwrite files? or is null a good thing and should be in the code to reflect this? Just totally curious
@zale_orcid - Please review this line of code provided by @michael17:
Dim str_docfile As String = doc.Path.Replace(".3dm", ".igs")
If doc.Path return null, the code will throw a NullReferenceException.
– Dale
I must be missing something but I cannot see what it is, I am attemptin to use SaveAs and as far as I can see the contents of my script string are the same as in your examples. I have tried with " _Enter" tagged onto the end of the script and without it.
If I enter the script manually into the command line the SaveAs operation is executed as expected, but if I try from .RunScript I get no response.
I am also writing the script to the app info line and as can be seen in the screen snippet below it is being passed as expected -
(note that the previous command is shown as being “_-SaveAs” but that the filename has been discarded. Is this significant ?)

I also show the script and result immediately after calling RunScript -

Code snippet below shows building of str_script string -
'
' get filename for .igs
Dim str_docfile As String = doc.Path.Replace(".3dm", ".igs")
'
' Build script string, use double quote chars in case of spaces within file path string
Dim str_script As String = $"_-SaveAs " & Chr(34) & str_docfile & Chr(34) & " _Enter"
'
'
Dim bval As Boolean = True
Dim exp_result As Boolean = False
'
' Write script string to app info
RhinoApp.WriteLine(str_script, EnglishName)
' execute script
exp_result = RhinoApp.RunScript(str_script, True)
' check if .igs file exists
Dim b_exists As Boolean = File.Exists(str_docfile)
MsgBox("Script :-" & str_script & vbCrLf & "Returned result :- " & exp_result.ToString & vbCrLf _
& "Does .igs exist :- " & b_exists)
'
'
As far as I can see the script string format follows that used in your earlier examples.
Can you confirm that the above code executes at your end.
thanks
michael
I have also added Exception handling code (just in case) and there are no exceptions being thrown.
Michael
Don’t forget to add the ScriptRunner attribute to your command, per the document I referenced above.
''' <summary>
''' https://developer.rhino3d.com/guides/rhinocommon/run-rhino-command-from-plugin/
''' Commands that run other commands, using RhinoApp.RunScript, must be decorated with this attribute.
''' </summary>
<CommandStyle(Style.ScriptRunner)>
Public Class DolphinExportCommand
Inherits Command
– Dale
I see a comment in a historical post (2020) which mentions something about the caller command not being defined as ‘Rhino.Commands.Style.ScriptRunner’, could this be something I need to do and if so where should it be and in what format. Original post -
michael
Thanks to all contributors.
The ‘SaveAs’ command is now being invoked correctly (I think this suits my purpose better than ‘Export’).
I added the code <CommandStyle(Style.ScriptRunner)> i.e.
"
Namespace DolphinExport
<CommandStyle(Style.ScriptRunner)>
Public Class DolphinExportCommand
"
This was the missing piece of the jigsaw.
After being invoked the ‘SaveAs’ command generates two prompts -
![]()
After responding to these two prompts the Information/Message lines shows the result i.e.
"
Saved C:\Users\Michael\Documents\1a1usr\Rhino\BaseAligner.igs.
File successfully saved as C:\Users\Michael\Documents\1a1usr\Rhino\BaseAligner.igs.
"
Is there a Method by which I can either interrogate these lines of text or by any other means extract the filename that has been saved. I need to pass the full path filename to the Cam module being called as an argument in the calling command line.
thanks
michael
Append an “Enter” token to the end of your script string.
var script = $"_-SaveAs \"{path}\" _Enter";
RhinoApp.RunScript(script, false);
https://docs.mcneel.com/rhino/7/help/en-us/index.htm#information/rhinoscripting.htm
Dale
Plugin up and running, my thanks to yourself and all contributors for your help and patience.
I do have one question, at the moment after execution of the ‘Save As’ script generated by the plugin I need to access the name of the file that has been created (for passing to our Cam platform). At the moment I am getting this file name by getting the Command History Window text e.g.
Dim str_infotxt As String = RhinoApp.CommandHistoryWindowText
I then parse this text and obtain the file name from the latest line in the text body which contains the text “File successfully saved as”, the file name is then extracted from this line of text.
This code works but I feel it is a bit clunky, is there a RhinoApp method which I can access to obtain this file name ?
thanks
michael
Dolphin Cad Cam systems Ltd.
I’m confused - don’t you pass this file name as part of the string you pass to RhinoApp.RunScript?
– Dale
Yes, I obtain the file name after the ‘SaveAs’ operation, the file is selected by the Client.
The script string passed to RhinoApp is -
Dim str_script As String = $"_-SaveAs Browse Enter"
This triggers the SaveAs op from which the Client selects the export file target name & extension.
At the moment I get the filename by parsing the CommandHistoryWindowText string -
Dim str_infotxt As String = RhinoApp.CommandHistoryWindowText
I am using this technique as there were scripting issues when the file name included embedded spaces (even when the filename string was bracketed by double quote characters ie chr(34)).
As you pointed out, if I could construct a script in the correct format for .Runscript which would cope with a file name containing embedded spaces I would already know the file name.
But with the method being used I do not know what the Client has requested via the ‘SaveAs’ feature so I get it from the text history.
If I could nail down the script format for a file name with/without embedded spaces but in the absence of this I wondered if there was RhinoApp method from which I could obtain the file created by the SaveAs operation.
michael
Rather than have the SaveAs command prompt for the file name, do it yourself:
– Dale
Dale
Turns out our Product Team prefer using SaveAs in the current manner, they believe it gives the Client more flexibility in selecting which Cam project the model is exported to.
If there is an existing Method by which I can extract the newly created file name from that would be great but failing that the Plugin will extract it from the Command window history text.
Thanks for all your assistance.
michael
Thinking out loud:
Not very elegant but is the saved file name printed in the commandline?
If so you can grab the command history and filter the last lines to find the filename…
Hey @michael17,
I believe you misunderstood my suggestion. Run the attached sample Rhino command and see if this is helpful.
DolphinExportCommand.vb (3.2 KB)
– Dale
Willem
Thanks for the suggestion, that is what I am doing already, I capture the command window history text and then parse it for the file name. This works (as you say not very elegant) and I wondered if the was a RhinoApp method I could utilise.
michael