I’m developing a plugin using RhinoCommon, and I need to determine whether a pasted object was copied from another .3dm file. Are there any APIs I can use for this?
I tried using RhinoDoc.AddRhinoObject += RhinoDoc_AddRhinoObject;
in the plugin.cs
file, but I couldn’t find the relevant method in RhinoObjectEventArgs
.
did you see / find this:
https://developer.rhino3d.com/api/rhinocommon/rhino.documentopeneventargs/merge#
This event is raised when the document open operation begins. NOTE: On Windows, this event will be fired when a clipboard paste operation occurs
https://developer.rhino3d.com/api/rhinocommon/rhino.rhinodoc/beginopendocument
I guess a copy-paste of objects created in the document would cause a “false positive” in his scenario though.
I guess you can run through the objects in another file and examine them all, but that would require that you know what file the object was copied from though.
Can you describe a scenario that would cover your needs and hurdles?
Currently, geometry copied from another file in Rhino will be pasted at the same coordinates as in the source file. I want to develop a plugin that allows users to specify the paste location by clicking with the mouse. To achieve this, I believe the first step is to determine whether the pasted object is from another file. Additionally, I would like to know if there is a specific event triggered during the paste action.
Thank you, I will give it a try
Insert does this with blocks, so I guess you want some of the same functionality.
So if you want to specify the location that would require an insert point. That can be solved by using the bounding box center, bottom center, picking a location or using world or cplane origin.
(We use blocks and inserted files all the time so we don’t need to save unessesary data, and it gives us the posibility to check if the objects have accidentally been moved since blocks can show their insert points)
One thing to consider is if this should work on copy-pasted objects within the file too.
Here’s a simple sketched up workflow of a script to paste and start the move command.
It pastes the objects and asks for an insertpoint or if ignored uses the boundingbox bottom center.
Does that give you something to work with?
import rhinoscriptsyntax as rs
rs.Command("!NoEcho Paste", False)
pasted_objects = rs.LastCreatedObjects()
if pasted_objects:
### Activate select object to work around pasted images
rs.SelectObjects(pasted_objects)
### Get point to move from or use base center
insertpoint = rs.GetPoint("Select point to move from")
if not insertpoint:
bbox = rs.BoundingBox(pasted_objects)
insertpoint = (bbox[0]+bbox[2])/2
### Move object
moveresult = (rs.Command("!NoEcho Move "+str(insertpoint)+ " pause Enter", False))
### If move was canceled delete pasted object(s)
if moveresult == False:
rs.DeleteObject(pasted_objects)
Thank you for your response. However, your method requires executing a command after pasting. What I want to achieve is a method where the user can perform a displaced paste simply by entering a command. I’ve now changed my approach: I will no longer differentiate whether the pasted geometry comes from another file. As long as the user pastes geometry, the endCommand
method in plugin.cs
will display a preview model that can move with the mouse, allowing the user to click to generate new geometry.