Exporting data for Cam (CNC) purposes

I am new to Rhino and am interested in producing a Macro/Script/Addin for the export of a complete model or individually selected sketches to a 3rd party Cam product for the production of cnc (G-Code) programs. Ideally it would be preferable to pass filenames (.STEP type for 3d model and .xml type for sketches) as command line parameters to the Cam software but if this is not possible the files could be written to a central location for reading by Cam on launch. I am a programmer of 40+ years experience and feel confident in use of scripting or API tools.

Any hints or pointers on the easiest/smartest method of achieving the above would be appreciated.

Thanks

Michael

thats your starting-point:

i recommend c# plug-in for the workflow you describe.
note that not all file formats can be exported by pure API-Commands.
but you can do everything that is possible in the rhino-command-line (“macro”) by using a script-runner command…

and with version 7 export did improve
https://developer.rhino3d.com/wip/api/RhinoCommon/html/M_Rhino_RhinoDoc_ExportSelected.htm

Thanks Tom.

Not really sure what you want to do, but if you just want to export .step files and call an executable with a given set of parameters, you should also be able to to that in python using the pythonscripteditor in rhino.

pseudocode would be something like this

import rhinoscriptsyntax as rs
import os

objs = rs.GetObjects()

for obj in objs:
    name = rs.ObjectName(obj)
    rs.UnselectObjects(objs)
    rs.SelectObject(obj)
    rs.RunCommand("-export -name - further options etc")
    os.system("C:\LocationofCAM\cam.exe -command line parameters")

Hi Michael,

In addition to all resources suggested by others:
Do not hesitate to keep asking questions on this forum when you get stuck. This is a community generous with help.

-Willem

1 Like

Thanks to all for your contributions, I think I have got myself a starting point.

Initially my objective is to be able to select an object and export it as a Step/Iges file then pass the filename as a command line argument to our Cam package with a view to producing a CNC (G-Code) program for subsequent machining. In the longer term the aim is to extract 2D sectional contours in addition to full 3d models for subsequent machining.

Michael

I have been able to build a plugin and execute it from the Command prompt. Now I am look at writing the files for the model to be exported. I have found Rhino.FileIO.FileStp which I am guessing will write STEP files, is there an equivalent object which covers Iges files.

Michael

I’d love to see your workflow somehow and see what you are doing - if you could take screen shots or something… I’m curious if I could use what you’re doing in my practice. Thanks,

I am a partner in a small independent Cad Cam (mainly Cam) software company, I have been in the business since 1977 and a partner in Dolphin Cad Cam systems Ltd (www.dolphincadcam.com) since 1989, we are a small team and have worked together since 1980. We have many loyal Clients worldwide and focus on software for production of CNC (G-code) programs for machining purposes (Mill/Turn/EDM applications). For many years we have been asked to provide quick links from 3D Cad such as Rhino. Our two main Cam platforms can currently import Iges & STEP files with my current task being to develop a Rhino plugin which will export a file in the selected format and execute our Cam software while passing the name of the exported file as a execution command line argument. The plugin is now basically functional (see image below of dialogue box), what I now need to do as add the code which will export the file and execute the cam software when the Client selects the ‘Export Model’ button.
So far building the basic plugin (.Net with RhinoCommon) has been straightforward and my next step is to locate the methods for exporting the current model in the desired format.

I hope that explains my task.

image

Thanks

michael

dont forget you can just call the “export” command from a plugin

I am trying to invoke ‘RhinoDoc.Export(filepath)’ but it does not seem to be available.

The plugin platform is VB, Visual Studio 2017, Rhino 6.

I got it from ‘RhinoDoc Methods’ but have just noticed this is only available from Rhino 7, is there an alternative to achieve this in Rhino 6.

thanks

michael

check my first post - how to run a command - you basically use the rhino command line.
also check this forum for c# dxf export…

SampleCsExportDXF.cs

don t forget the script-runner attribute.

kind regards -tom

1 Like

Almost within touching distance, I think I am invoking the RhinoApp.RunScript(script,boolean) method but have got the following issues -

  1. If I set the boolean = True the command line flashes on screen but it is to fast to be able to read it.
  2. I cannot find any definitions of the script string format for VB, see snippet from screen where I am echoing the value of script string to the screen (using RhinoApp.WriteLine(script) -

image

Is there any documentation available showing examples of script string contents for vb.

vb code to invoke RunScript and echo script string to screen -

        exp_result = RhinoApp.RunScript(str_script, True)
        RhinoApp.WriteLine(str_script, EnglishName)

thanks

michael

Dale

The content of the string script being passed to RunScript is -

_-Export “C:\Users\Michael\Documents\1a1usr\Rhino\BaseAligner.igs”

The contents of script are being echoed to the screen via RhinoApp.Writeline -

image

See code of call to RunScript -

        '
        ' 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)
        '
        '

See results from plugin after execution -
(The result of plugin is false and .igs file is shown not to exist)
image

If I cut/paste the Script string into the command line the file name is rejected but the export op commences -
(see 'Unknown command message)

image

What I wish to do is to export the total current object as a .igs file (without User intervention by way of selection) and then invoke a 3rd program with the file name embedded in the command line.

Thanks

michael

oops, unknown command snippet -

image

Hi Michael.

The Export command is expecting selected objects to be exported. Before invoking the Export to igs command you should get some objects selected.

If you want everything exported to igs you could use the SaveAs command.

Does that make sense?

-Willem

1 Like

Willem

Ok, I'll try selecting the whole current doc prior to attempting the export command.

Also will try SaveAs, sounds simpler.

thanks

michael

I think I am missing something on the RunScript string being passed to the command line.

The contents of the script string is shown as -

_-SaveAs “C:\Users\Michael\Documents\1a1usr\Rhino\BaseAligner.igs”

Which is echoed to the screen via RhinoApp.WrtieLine.

If I Cut/Paste this string into the Rhino command line it is executed, I am asked for default parameters and then the .igs file is created.

If I attempt to execute via the following call to RunScript -

        exp_result = RhinoApp.RunScript(str_scriptsa, True)
  1. Even though the 2nd argument = True the command is not echoed to the command line.
  2. The contents of str_scriptsa are echoed to the screen via WriteLine.
  3. If this is copied to command line via Cut/Paste the command is executed.
  4. RunScript returns a result = False after execution.

I tried replacing “” characters within the file name with “\” but this made no difference.

I feel like I am missing something in the definition of my DolphinExportCommand class.

All contributions welcomed.

michael

I tried replacing “” characters within the file name with “\” but this made no difference.

should read -

I tried replacing \ characters within the file name with \\ but this made no difference.