algorithmic modeling for Rhino
In the discussion,
David has written a piece of code to select the last created element.
{
//If the script was successfully run, search for the most recently added object
Rhino.DocObjects.RhinoObject obj = doc.Objects.MostRecentObject();
A = obj.Geometry.Duplicate();
doc.Objects.Delete(obj, true);
}
I would like to convert it into a VB.Net component Gh
Thansk for all.
Tags:
There's also the AllObjectsSince() method to get all objects that were created since some predefined event. Also, when do you want to update this component? It seems like a very bad idea to do so automatically whenever a new object is created as that may happen a lot for temporary objects.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
David,
Thanks for your reply.
I used a VBScript for use a pluggin to rhino.
'Add the objects to Rhino
Dim mesh_id As Guid = doc.Objects.AddMesh(MeshA)
Dim meshB_id As Guid = doc.Objects.AddMesh(MeshB)
'Dim mesh_id As Guid = doc.Objects.AddMesh(Mesh)'Create the command macro
Dim macro As String = String.Format( _
"!_-RtBooleanObjectsDifference _SelID ""{0}"" _Enter _SelID ""{1}"" _Enter", _
mesh_id, meshB_id)'Run the macro
Rhino.RhinoApp.RunScript(macro, True)'Harvest the deformed Brep from the Rhino document
Dim ref As New DocObjects.ObjRef(mesh_id)
Mesh = ref.Mesh()'Delete the objects from Rhino
doc.Objects.Delete(mesh_id, True)
doc.Objects.Delete(meshB_id, True)
The plugin id to create a new object. It is this one I can not recover.
Do you understand?
thansk
The command reslut in rhino:
Commande: _-RtBooleanObjectsDifference
Select First set of objects: meshes, surfaces, extrusions ( JoinResult=No KeepInput=No ): _Joinresult=Yes
Select First set of objects: meshes, surfaces, extrusions ( JoinResult=Yes KeepInput=No ): _KeepInput=No
Select First set of objects: meshes, surfaces, extrusions ( JoinResult=Yes KeepInput=No ): _SelID
Identification de l'objet à sélectionner: "7d6ec745-9cc2-46ca-ae07-c5ebd89a2917"
1 maillage ajouté à la sélection.
Select First set of objects: meshes, surfaces, extrusions. Appuyer sur Entrée une fois terminé ( JoinResult=Yes KeepInput=No ): _Enter
Select First set of objects: meshes, surfaces, extrusions. Appuyer sur Entrée une fois terminé ( JoinResult=Yes KeepInput=No ):
Select Second Set of objects:meshes, surfaces, extrusions: _SelID
Identification de l'objet à sélectionner: "7ed19c3f-9fac-4916-a352-141e36d77a1e"
1 maillage ajouté à la sélection.
Select Second Set of objects:meshes, surfaces, extrusions. Appuyer sur Entrée une fois terminé: _Enter
Select Second Set of objects:meshes, surfaces, extrusions. Appuyer sur Entrée une fois terminé:
Boolean difference time 225.730838 ms
Volume: 1843310.718248
The order went well, we get good results, but the geometry was not added to the output mesh.
Mesh = ref.Mesh()
This may be the problem. I think you need to duplicate the mesh because you're deleting the original on the next line.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Yes, I wantselected the mesh in grasshopper and delete in rhino.
Without the line:
'Add the objects to Rhino
Dim meshA_id As Guid = doc.Objects.AddMesh(MeshA)
Dim meshB_id As Guid = doc.Objects.AddMesh(MeshB)
Dim mesh_id As Guid = doc.Objects.AddMesh(Mesh)'Create the command macro
Dim macro As String = String.Format( _
"!_-RtBooleanObjectsDifference _Joinresult=Yes _KeepInput=No _SelID ""{0}"" _Enter _SelID ""{1}"" _Enter", _
meshA_id, meshB_id)'Run the macro
Rhino.RhinoApp.RunScript(macro, True)'Harvest the deformed Brep from the Rhino document
Dim ref As New DocObjects.ObjRef(mesh_id)
Mesh = ref.Mesh()
This works in rhino but the geometry is still not selected grasshopper:
If you do not copy the mesh (i.e. call DuplicateMesh()) then your mesh in Grasshopper will refer to the deleted mesh, which is not what you want. Here's a version of the code that works for me, using the MeshBooleanDifference command:
Private Sub RunScript(ByVal x As Mesh, ByVal y As Mesh, ByRef A As Object)
'Add the objects to Rhino
Dim idMeshA As Guid = doc.Objects.AddMesh(x)
Dim idMeshB As Guid = doc.Objects.AddMesh(y)
Dim runtimeEvent As UInteger = New Rhino.DocObjects.ObjRef(idMeshB).RuntimeSerialNumber'Create the command macro
Dim command As String = "MeshBooleanDifference"
Dim macro As String = String.Format("!_-{0} _SelID ""{1}"" _Enter _SelID ""{2}"" _Enter", command, idMeshA, idMeshB)'Run the macro
Rhino.RhinoApp.RunScript("_SelNone", False)
Rhino.RhinoApp.RunScript(macro, True)'Harvest new meshes
Dim objs As Rhino.DocObjects.RhinoObject() = doc.Objects.AllObjectsSince(runtimeEvent)
Dim rc As New List(Of Mesh)
For Each obj As Rhino.DocObjects.RhinoObject In objs
Dim m As Mesh = Nothing
GH_Convert.ToMesh(obj.Geometry, m, GH_Conversion.Both)If (m Is Nothing) Then Continue For
rc.Add(m.DuplicateMesh())doc.Objects.Delete(obj.Id, True)
NextA = rc
End Sub
--
David Rutten
david@mcneel.com
Poprad, Slovakia
I thought this line again retrieve the last created element:
Dim ref As New DocObjects.ObjRef(mesh_id)
Mesh = ref.Mesh()
i don't understand
In case the object is unchanged iD I recovers well are two geometry.
But if the resulting object is new, I can not do it.
Have you any idea?
Code to unchanged iD:
'Add the objects to Rhino
Dim meshA_id As Guid = doc.Objects.AddMesh(MeshA)
Dim meshB_id As Guid = doc.Objects.AddMesh(MeshB)'Create the command macro
Dim macro As String = String.Format( _
"!_-RtBooleanObjectsDifference _Joinresult=No _KeepInput=No _SelID ""{0}"" _Enter _SelID ""{1}"" _Enter", _
meshA_id, meshB_id)'Run the macro
Rhino.RhinoApp.RunScript(macro, True)'Harvest the deformed Brep from the Rhino document
Dim ref1 As New DocObjects.ObjRef(meshA_id)
Dim ref2 As New DocObjects.ObjRef(meshB_id)
MeshDA = ref1.Mesh()
MeshDB = ref2.Mesh()'Delete the objects from Rhino
doc.Objects.Delete(MeshA_id, True)
doc.Objects.Delete(MeshB_id, True)
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by