[InteractionGraphics] Unable to colour ComponentGraphics

[InteractionGraphics] Unable to colour ComponentGraphics

_dscholtes_
Advocate Advocate
756 Views
4 Replies
Message 1 of 5

[InteractionGraphics] Unable to colour ComponentGraphics

_dscholtes_
Advocate
Advocate

I have created a macro with a preview function. It lets the user select an occurrence in an assembly and then displays a form to get some user input. Based on this input, some preview graphics are shown. The preview function uses "normal" ClientGraphics. It adds a few GraphicNodes, adds ComponentGraphics to them, and positions and colors each node. It works, but the adding and positioning of the nodes fills up the undo stack, which I don't want.

So I rewrote the function to use InteractionGraphics. It works with one exception: the nodes are not being colored.

Please find below an excerpt of the code, which adds the nodes, graphics and should set the color.
The only changes between my old and new code are the declaration and assigning of oIE, oIG and oClientGraphics.

 

Does anyone have a solution?

 

    '-=- Add Preview Items ------------------------------------------------

    'Check if the InteractionEvents object was already running. If so, stop and clear it.
    If Not oIE Is Nothing Then
        oIE.Stop
        Set oIE = Nothing
    End If

    'Set reference to the InteractionEvents object (object has been globally declared)
    Set oIE = ThisApplication.CommandManager.CreateInteractionEvents
    oIE.Start
    
    'Set reference to the InteractionGraphics object (obtained from InteractionEvents object)
    Dim oIG As InteractionGraphics
    Set oIG = oIE.InteractionGraphics
    
    'Create new client graphics object from the graphics owner (InteractionGraphics object)
    Dim oClientGraphics As ClientGraphics
    Set oClientGraphics = oIG.OverlayClientGraphics

    'Set reference to componentdefinition of to-be-previewed item
    Dim oDef As ComponentDefinition
    Set oDef = oSourceOcc.Definition
    
    'Create the preview item color
    Dim oColor As Color
    Set oColor = ThisApplication.TransientObjects.CreateColor(255, 128, 0)
    oColor.Opacity = 0.2


    'Declarations
    Dim oNode  As GraphicsNode
    Dim oComponentGraphics As ComponentGraphics

    'Add the preview items
    For i = 1 To 3
    
        'Add a graphics node to the client graphics object
        Set oNode = oClientGraphics.AddNode(i)
    
        'Set node properties
        oNode.Selectable = False
        oNode.Visible = True
    
        'Add graphic primitives (component graphics) to the node based on referenced componentdefinition
        Set oComponentGraphics = oNode.AddComponentGraphics(oDef)
    
        'Set the graphic primitives / component graphic color
        oComponentGraphics.Color = oColor
    Next i
    
    '-=- End of Add Preview Items -----------------------------------------

   <Some code positioning the nodes>

    'Update the display
    oIG.UpdateOverlayGraphics ThisApplication.ActiveView

 

0 Likes
Accepted solutions (1)
757 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

Hi i did not find a way to color the InteractionGraphics. But you wrote: "It works, but the adding and positioning of the nodes fills up the undo stack, which I don't want." If the undo stack is the problem then you could have a look at the transaction manager. It's there to pack multiple actions in to 1 undo point. As a side effect it can alos make your code faster. Have a look at the last chapter of this blog post. Or have a look at the help page.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

_dscholtes_
Advocate
Advocate

Hi @JelteDeJong

I already use the TransactionManager to wrap all the modifications the macro makes into one transaction. I did not consider adding the preview function to that transaction as well, because I see them as two separate processes. I do not prefer this solution, but I will look into it because it should work. A related idea would be to give the preview function its own transaction and deliberately abort it.


As far as I'm concerned, Inventor may forget it ever drew those preview graphics.

According to the help file, InteractionGraphics are faster than ClientGraphics. And in my macro, it shows.
But now I have to choose between speed and clearity by color usage.

0 Likes
Message 4 of 5

etaCAD
Advocate
Advocate
Accepted solution

InteractionGraphics is the correct way and for me it works fine to set a specific color. I use PreviewGraphics. Below are some snippets of a VB.NET code:

 

Private mGraphics As InteractionGraphics = Nothing
Private mPreviewGraphics As ClientGraphics = Nothing

Private mSelectedOccColor As Inventor.Color

 

Dim trObj As TransientObjects = Globals.InventorApplication.TransientObjects
mSelectedOccColor = trObj.CreateColor(20, 255, 20)

 

mGraphics = m_InteractionEvents.InteractionGraphics
mPreviewGraphics = mGraphics.PreviewClientGraphics

 

Dim grNode As GraphicsNode = mPreviewGraphics.AddNode(mPreviewGraphics.Count + 1)

 

add graphis to node and set color...

 

 

Andreas
etaCAD

0 Likes
Message 5 of 5

_dscholtes_
Advocate
Advocate

@etaCAD 

Switching from OverlayClientGraphics to PreviewClientGraphics did the trick, thank you. Will mark as solution.

I saw the option in the Object Browser, but decided not to use / try it because I based my macro on the online help example (which uses OverlayClientGraphics) and the fact that the help file states these graphics could be updated independently (which seems better / faster to me).

0 Likes