Create selectable and moveable transient graphics

Create selectable and moveable transient graphics

lharwoodWZKMU
Contributor Contributor
761 Views
7 Replies
Message 1 of 8

Create selectable and moveable transient graphics

lharwoodWZKMU
Contributor
Contributor

So I've been playing with adding ClientGraphics to a Factory Design Utilities layout through the Interaction Events InteractionGraphics and from what I've seen and read in another forum post those don't come with the ability to be moved by the user out of the box and I've haven't been able to make them selectable either. The forum post did mention it would be possible to handle the movement through listening to mouse events but that doesn't seem ideal. Are there any other options for adding selectable and moveable transient graphics? If not, does anyone know of any examples of getting the selection and movement to work for the ClientGraphics? Ultimately what I'm trying to do is allow the user define a point on a factory design utility asset instance by placing something on it visually.

0 Likes
762 Views
7 Replies
Replies (7)
Message 2 of 8

MjDeck
Autodesk
Autodesk

@lharwoodWZKMU , do you want to be able to save this data in the layout? Or is it just transient?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 8

lharwoodWZKMU
Contributor
Contributor

Saving the data(points) in the layout would probably be ideal but not required, but I don't think we'd want the graphics themselves to be saved as part of the layout.

0 Likes
Message 4 of 8

MjDeck
Autodesk
Autodesk

Can you provide more details about your workflow?

If I understand correctly, you want the user to be able to select a point on a Factory design asset instance.
While they're moving the mouse around to select a point, you want to show some custom temporary graphics that moves with the mouse cursor.
When they select a point, you will use it in a further workflow. You don't need to save the point itself in the layout.
Is there anything Factory-specific about this part of your overall workflow? Or can you imagine the same thing working in a plain Inventor assembly?
What kind of points (or positions) do you want to be able to select? Can you compare it to an existing Inventor command, such as adding a work point?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 8

lharwoodWZKMU
Contributor
Contributor

So we have an addin in Inventor that generates an svf and launches a forge viewer app that runs our process simulation animation. Part of this animation has parts/raw materials etc. flowing through the system and when these objects are being processed at a machine(factory asset instance) we need to know where that object should show visually on or in relation to that machine (the point could be outside the bounds of the asset) and so the plan is to have those points configurable by the user in Inventor. To do this we would have the user click a button in the ribbon that puts them in a mode to modify these points. When they first enter that mode we would draw these temporary shpere graphics for every asset instance we're interested in either in their default positions(top center of asset instance) or in the saved positions the user had previosly defined in this mode. To modify the positions of these shperes the user would just click and drag the graphics around. Once the user exits the mode we would hide or destroy all the graphics but save the points. Right now we are only dealing with factory asset instances. I'm not very familiar with Inventor so I don't know if there is anything similar being done anywhere. What I've been able to do so far is draw a client graphic in the default positions for each asset but haven't been able the make those graphics selectable and moveable by the user. Hopefully that answers all your questions and makes sense.

0 Likes
Message 6 of 8

MjDeck
Autodesk
Autodesk

I think this is possible. I'm looking at code in the Inventor Tolerance Analysis add-in that allows you to drag 3D annotation dimensions that are represented by ClientGraphics.
You might be able to do it all by handling the UserInputEvents.OnDrag event. If you're listening to that event, note that it's raised for all objects. When it gives you DragState equal to DragStateEnum.kDragStateDragHandlerSelection, you can look at the ActiveEditDocument.SelectSet, and see if it contains one of your entities. Maybe you only want to allow dragging one at a time. The entity you want will be of type ObjectTypeEnum.kGraphicsNodeObject. You can get the Parent of that and determine if its ClientId matches yours. Set the HandlingCode to kEventHandled to tell Inventor that you're handling the drag. Then respond to additional OnDrag events with different values of DragState. For instance, a DragState of DragStateEnum.kDragStateOnDrag will give you an updated position.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 7 of 8

lharwoodWZKMU
Contributor
Contributor

Thank you for your response. I'm giving it a try but have not been able to make the client graphics selectable. Found this post with someone having the same issue, but their solution doesn't seem to work for me. Any ideas on what I'm doing wrong?

private void ModifyEntitySpots(NameValueMap context)
{
	Addin.InventorApplication.CommandManager.UserInputEvents.OnDrag += UserInputEvents_OnDrag;

	if (_interActionEvents == null)
	{
		_interActionEvents = Addin.InventorApplication.CommandManager.CreateInteractionEvents();
	}

	var existingAssetInstances = Autodesk.Factory.PublicAPI.API.Instance.GetAssetInstances(Addin.InventorApplication.ActiveDocument);

	var clientGraphics = _interActionEvents.InteractionGraphics.OverlayClientGraphics;

	foreach (var instance in existingAssetInstances)
	{
		if (instance.NativeObject is ComponentOccurrence componentOccurrence)
		{
			var centerX = componentOccurrence.RangeBox.MaxPoint.X - ((componentOccurrence.RangeBox.MaxPoint.X - componentOccurrence.RangeBox.MinPoint.X) / 2);
			var centerY = componentOccurrence.RangeBox.MaxPoint.Y - ((componentOccurrence.RangeBox.MaxPoint.Y - componentOccurrence.RangeBox.MinPoint.Y) / 2);

			var document = Addin.InventorApplication.ActiveDocument;
			var transientGeometry = Addin.InventorApplication.TransientGeometry;

			var node = clientGraphics.AddNode(1);

			var transientBRep = Addin.InventorApplication.TransientBRep;

			var bottom = transientGeometry.CreatePoint(centerX, centerY, componentOccurrence.RangeBox.MaxPoint.Z);
			var top = bottom.Copy();
			top.Z = top.Z + 20;
			var body = transientBRep.CreateSolidCylinderCone(bottom, top, 5, 5, 0);

			node.AddSurfaceGraphics(body);
			node.Selectable = true;
		}
	}

	clientGraphics.Selectable = GraphicsSelectabilityEnum.kAllGraphicsSelectable;
	_interActionEvents.InteractionGraphics.UpdateOverlayGraphics(Addin.InventorApplication.ActiveView);	
}

 

0 Likes
Message 8 of 8

lharwoodWZKMU
Contributor
Contributor

We have now figured out how to make them selectable. Working on the dragging now.

0 Likes