Importing file. How to reference?

Hi I’m importing a file and asked myself how too get the object Guids.

Dim O As New Rhino.FileIO.FileReadOptions
O.ImportMode = True
Rhino.RhinoDoc.ReadFile(Location, O)

And btw:

Dim NewObject As Guid = doc.Objects.MostRecentObject.Id

isnt working

Have you considered making a file import plug-in? That is the advised way of reading files into rhino.

No I havn’t. I also have no idea where to start.
Any tips?

I’m now checking which objects Guid’s I have then import the file (1 or 2 objects) then check again and see which are new.

Oh, sorry… Importing a 3dm file is what you are doing. I thought for a minute that you were importing some other file format. My bad…

You might be able to use this method
http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_DocObjects_Tables_ObjectTable_AllObjectsSince.htm

Start by getting the runtime serial number (NOT the Id!!) from the most recent object, then import the file, and then use the method above.

@menno You’ve talked about an import plugin last week. I’m trying to import a STL file with 1 geometry in it. I’ve tried the same as the 3DM but I always get a popup where it asks rotation/scale etc. Is there a way to supress that?

Code:

 Public Sub ImportSTL(ByVal Location As String)

        Dim O As New Rhino.FileIO.FileReadOptions
        O.ImportMode = True
        Rhino.RhinoDoc.ReadFile(Location, O)

End Sub 

I´ve tried to set ScaleGeometry too False and BatchImport but then the dialog will be suppressed but I still need too press enter, because it´s in the command bar.

I would go like this

String stlFilename; // defined elsewhere

String ext = Path.GetExtension(stlFilename);
if (null == ext || !ext.ToLower().Equals(".stl", StringComparison.OrdinalIgnoreCase))
    return false;

String script = String.Format("_-Import \"{0}\" _Enter", stlFilename);
return RhinoApp.RunScript(script, false);

Hmm the RunScript. I know it is possible that way but I´m trying too avoid Runscript :stuck_out_tongue:
and need to add some chr(34) xD

Any reason why you want to avoid it? Why program something that can be scripted?

I’ve got a plugin where I scripted 90% of what I made. On some points it bugs on undo and redo because scripts are withing scripts etc. :stuck_out_tongue:

So when I program it it looks better and scripts wont run within scripts :slight_smile: and i think if somethings going to change with a command it will be with a scripted command and not with a programmed one :). programmed ones will work but with scripted you have to find the problem. No debugg options.

Hello,
I know its a very old post, but have you found out how to get guid?

Thanks

Well. How I do it now is first get all GUID that are currently in the file.
Import the file.
Compare the guids.

Great, thank you!

Hello Menno,

I know it’s a quite old topic but where can I find documentation how to make a file import plugin to import PDF into Rhino remotely? I’ve found the class but Rhinocommin doesn’t tell much how to use it.

Thanks for your help,

Cheers

I don’t know what you mean by “remotely”. Can you give more info?

Hi @Xavier_Ayme,

To create a file import plug-in in RhinoCommon, just set the plug-in type to “File Import” when running the project wizard.

pdf

Then, just implement the overridden members in the plug-in object created by the wizard.

– Dale

Thanks to both of you for your quick answer,

@menno By ‘remotely’ I mean that Rhino is controlled by another software via a COM Interface :I created a general plugin which sits inside Rhino, which is accessible via COM and which can call Rhinocommon methods, as exposed here : https://github.com/mcneel/rhinocommon/tree/master/examples/AutomationSample. Problem is that I cannot find any method inside Rhinocommon to import non 3dm files.

@dale ok I understand how to create a File Import Plug In, but what about using existing one (like ***Import.rhp)? Is that doable and allowed by the license agreement?

Hi @Xavier_Ayme,

You don’t need a special plug-in to do this. Just use the Command method on the Rhino application object to script the Import command. There is no API for doing this in any other way.

– Dale

Ok, then I’ll try to find a workaround. Would you have by any chance a hint on how to figure out that Rhino has triggered an error while attempting to load the file (as per screenshot below)?

At least, it will provide me with a basic feedback loop (success/failed.

Thanks for your time @dale

Hi @Xavier_Ayme,

Can you post the PDF file you’re trying to read?

– Dale

Hi @dale,

Sure, please find it below. But any non vectorial PDF will lead to that alert being displayed. And that’s expected, from my understanding of Rhino, it cannot import images that way.

Problem is that I have no control over the input file flow and actually no idea on how I could detect a non vectorial PDF before attempting to import it.

Thanks!

Fichier non vectorise.pdf (1.8 MB)