I sadly cannot run this Prog as plugin in rhino.
In other systems (i.e. inventor) I use the following steps to get the existing application. Is there something equal for Rhino? Would be perfect.
Public Function InventorApp() As Inventor.Application
Try
InventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Catch Error As Exception
InventorApp = Nothing
End Try
End Function
I think you’re looking for something similar to this
In this example, a new instance of Rhino is started. It should (?) also be possible to hook into a running instance of Rhino in a similar way that you posted.
// Try creating an instance of Rhino
dynamic rhino = null;
try
{
// string rhinoId = "Rhino5.Application";
string rhinoId = "Rhino5x64.Application";
System.Type type = System.Type.GetTypeFromProgID(rhinoId);
rhino = System.Activator.CreateInstance(type);
}
catch
{
}
if (null == rhino)
{
Console.WriteLine("Failed to create Rhino application");
return;
}
Hi, and first of all, thanks for your very quick reply.
It’s my first attempt with the Rhino programming.
With your advice, I got a running instance of Rhino, perfect so far, but there I stopped, because I don’t know, how I can use it.
Public Function RhinoAPP() As Object
Dim rhino As Object = Nothing
Try
Dim rhinoId As String = "Rhino5x64.Application"
Dim type As System.Type = System.Type.GetTypeFromProgID(rhinoId)
rhino = System.Activator.CreateInstance(type)
Catch
End Try
RhinoAPP = rhino
End Function
In my case you’ll see, I have an object of the running instance. But it should be something like “Rhino.Application”. Instead of “RhinoAPP() As Object”.
I have no idea in the moment, what kind of object the result is. Sorry, but I think, there’s only a small step on to the right side But I standing behind a wall in the moment and cannot see the way
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rh As Object = RhinoAPP()
If rh IsNot Nothing Then
rh.RunScript("_Line 0,0,0 100,0,0 -_SaveAs C:\Test.3dm _enterEnd", 0)
End If
End Sub
Public Function RhinoAPP() As Object
Dim rhino As Object = Nothing
Try
Dim rhinoId As String = "Rhino5.Application"
Dim type As System.Type = System.Type.GetTypeFromProgID(rhinoId)
rhino = System.Activator.CreateInstance(type)
Catch
End Try
Return rhino
End Function
It will create a Rhino5 32Bit instance, draws a line, SaveAs on C:\test.3dm and this works.
Hi, thanks for the reply, but I think, my brain is not able to understand it in the moment.
What do I want to achieve in the moment:
I have against list of informations and want to visualize them in Rhino.
For making it simple let’s say, I want to draw points. That’s easy. But now, I want to change the colors of the objects. My plan was: Changing the Layer to the one, I want to use and then create the point. Then check if I have to change the color again and create the next point and so on.
In the moment I have 3 problems:
I have no idea of how to get the running instance of Rhino in the moment. So I’ll have to start a new instance each time… But that’s not so worse
If I use the _-properties script, I’ll have to select the element I created before… (Would be easier to change the layer before, create element and then continue)
My Brain is to weak
Any ideas??
EDIT:
I’m so dumb from time to time, point 1 is solved I don’t see the running instance point
The second and third (mainly the third are still existing)
Public Function RhinoAPP() As Object
Dim rhino As Object = Nothing
Try
'Dim rhinoId As String = "Rhino5x64.Application"
'Dim type As System.Type = System.Type.GetTypeFromProgID(rhinoId)
'rhino = System.Activator.CreateInstance(type)
rhino = CreateObject("Rhino5x64.Interface")
Catch
End Try
RhinoAPP = rhino
End Function
Every method on the RhinoScript object - all 1000+ methods - are callable from an externally running application. So see what is available in RhinoScript, select Help -> Plug-ins -> RhinoScript.
To see how to get the RhinoScript object, from the Rhino object, see the following example.
Pay attention to the code in MainModule.vb in and around line 42.