Client Graphics

Client Graphics

GeorgK
Advisor Advisor
1,427 Views
10 Replies
Message 1 of 11

Client Graphics

GeorgK
Advisor
Advisor

Hello together,

 

how could I colorize my userdefined workaxis with client graphics?

 

Clientgraphics.png

 

Thank you

 

Georg

0 Likes
Accepted solutions (2)
1,428 Views
10 Replies
Replies (10)
Message 2 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @GeorgK,

 

Try the following VBA code to create client graphics for workaxis.

 

Currently, code works for Assembly document.

 

Sub Main()
    
    Dim doc As AssemblyDocument
    Set doc = ThisApplication.ActiveDocument
    
    Dim compDef As AssemblyComponentDefinition
    Set compDef = doc.ComponentDefinition
    
    Dim wa As WorkAxis
    Set wa = ThisApplication.CommandManager.Pick(kWorkAxisFilter, "Select a work axis to draw client graphics")
    
    Dim oClientGraphics As ClientGraphics
    Dim oDataSets As GraphicsDataSets
    
    On Error Resume Next
    
    Set oClientGraphics = compDef.ClientGraphicsCollection.Item("TestGraphicsID")
    Set oDataSets = doc.GraphicsDataSetsCollection.Item("TestID")
    
    If Err.Number = 1 Then
    On Error GoTo 0
        ' An existing client graphics object was successfully obtained so clean up.
        Set oClientGraphics = compDef.ClientGraphicsCollection.Add("TestGraphicsID")
        Set oDataSets = doc.GraphicsDataSetsCollection.Add("TestID")
        ' update the display to see the results.
        ThisApplication.ActiveView.Update
        
    Else
    
        Call oClientGraphics.Delete
        Call oDataSets.Delete
        Set oClientGraphics = compDef.ClientGraphicsCollection.Add("TestGraphicsID")
        Set oDataSets = doc.GraphicsDataSetsCollection.Add("TestID")
        
    End If
    
    ' Create a new graphics node within the client graphics objects.
    Dim oSurfacesNode As GraphicsNode
    Set oSurfacesNode = oClientGraphics.AddNode(1)
        
    Dim coordSet As GraphicsCoordinateSet
    Set coordSet = oDataSets.CreateCoordinateSet(1)
    
    Dim oColorSet As GraphicsColorSet
    Set oColorSet = oDataSets.CreateColorSet(1)
    
    
    'Call oColorSet.Add(1, 255, 0, 0) ' For red

    Call oColorSet.Add(1, 0, 255, 0) 'For Green
        
    Dim oPointCoords(5) As Double
    If wa.Line.Direction.X > 0 Then
        oPointCoords(0) = wa.Line.RootPoint.X + 6
    Else
        oPointCoords(0) = wa.Line.RootPoint.X
    End If
    If wa.Line.Direction.Y > 0 Then
        oPointCoords(1) = wa.Line.RootPoint.Y + 6
    Else
        oPointCoords(1) = wa.Line.RootPoint.Y
    End If
    If wa.Line.Direction.Z > 0 Then
        oPointCoords(2) = wa.Line.RootPoint.Z + 6
    Else
        oPointCoords(2) = wa.Line.RootPoint.Z
    End If
    
    oPointCoords(3) = wa.Line.RootPoint.X
    oPointCoords(4) = wa.Line.RootPoint.Y
    oPointCoords(5) = wa.Line.RootPoint.Z
    
    Call coordSet.PutCoordinates(oPointCoords)
    
    Dim oLine As LineGraphics
    Set oLine = oSurfacesNode.AddLineGraphics
            
    oLine.CoordinateSet = coordSet
    oLine.ColorSet = oColorSet
    oLine.LineWeight = 2
    
    ThisApplication.ActiveView.Update
        
    
End Sub

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 11

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

thank you very much. Your code is working for the main axis but not for userdefined axis. The client graphic is somewhere in space 🙂

 

Georg

0 Likes
Message 4 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @GeorgK

 

In the following screencast, demonstrated about creating client graphics to custom workaxis using VBA.

 

If there is any change, upload a screencast. I will look into it.

 

 
Please feel free to contact if there is any doubt.
 
If solves problem, click on "Accept as solution" / give a "Kudo".
 
Thanks and regards,

CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 11

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

I have 2 different models. In the first one your code is not working and in the second one it works. Maybe the first model is corrupt. I use Inventor 2017.4.1.

 

Platten_schlecht.png

Platten_gut.png

 

With new models your code is working. Thank you very much.

 

Georg

 

0 Likes
Message 6 of 11

GeorgK
Advisor
Advisor

I did some more testing. The problem appears in different models. Also in new ones. Is this a bug?

0 Likes
Message 7 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @GeorgK,

 

Is it possible to share the model (Non confidential one)?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 11

GeorgK
Advisor
Advisor

@chandra.shekar.g

The model where the axis are in the wrong orientation.

0 Likes
Message 9 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @GeorgK,

 

Check the following VBA code

 

Sub Main()
    
    Dim doc As AssemblyDocument
    Set doc = ThisApplication.ActiveDocument
    
    Dim compDef As AssemblyComponentDefinition
    Set compDef = doc.ComponentDefinition
    
    Dim wa As WorkAxis
    Set wa = ThisApplication.CommandManager.Pick(kWorkAxisFilter, "Select a work axis to draw client graphics")
    
    Dim oClientGraphics As ClientGraphics
    Dim oDataSets As GraphicsDataSets
    
    On Error Resume Next
    
    Set oClientGraphics = compDef.ClientGraphicsCollection.Item("TestGraphicsID")
    Set oDataSets = doc.GraphicsDataSetsCollection.Item("TestID")
    
    If Err.Number = 1 Then
    On Error GoTo 0
        ' An existing client graphics object was successfully obtained so clean up.
        Set oClientGraphics = compDef.ClientGraphicsCollection.Add("TestGraphicsID")
        Set oDataSets = doc.GraphicsDataSetsCollection.Add("TestID")
        ' update the display to see the results.
        ThisApplication.ActiveView.Update
        
    Else
    
        Call oClientGraphics.Delete
        Call oDataSets.Delete
        Set oClientGraphics = compDef.ClientGraphicsCollection.Add("TestGraphicsID")
        Set oDataSets = doc.GraphicsDataSetsCollection.Add("TestID")
        
    End If
    
    ' Create a new graphics node within the client graphics objects.
    Dim oSurfacesNode As GraphicsNode
    Set oSurfacesNode = oClientGraphics.AddNode(1)
        
    Dim coordSet As GraphicsCoordinateSet
    Set coordSet = oDataSets.CreateCoordinateSet(1)
    
    Dim oColorSet As GraphicsColorSet
    Set oColorSet = oDataSets.CreateColorSet(1)
    
    
    Call oColorSet.Add(1, 255, 0, 0) ' For red

    'Call oColorSet.Add(1, 0, 255, 0) 'For Green
        
    Dim oPointCoords(5) As Double
    If wa.Line.Direction.X = 1 Or wa.Line.Direction.Y = 1 Or wa.Line.Direction.Z = 1 Then
        If wa.Line.Direction.X = 0 Then
            oPointCoords(0) = wa.Line.RootPoint.X
        ElseIf wa.Line.Direction.X > 0 Then
            oPointCoords(0) = wa.Line.RootPoint.X + 6
        End If
        If wa.Line.Direction.Y = 0 Then
            oPointCoords(1) = wa.Line.RootPoint.Y
        ElseIf wa.Line.Direction.Y > 0 Then
            oPointCoords(1) = wa.Line.RootPoint.Y + 6
        End If
        If wa.Line.Direction.Z = 0 Then
            oPointCoords(2) = wa.Line.RootPoint.Z
        ElseIf wa.Line.Direction.Z > 0 Then
           oPointCoords(2) = wa.Line.RootPoint.Z + 6
        End If
    
    Else
    
        oPointCoords(0) = wa.Line.RootPoint.X - 6
    
        oPointCoords(1) = wa.Line.RootPoint.Y - 6
    
        oPointCoords(2) = wa.Line.RootPoint.Z - 6
    
    End If
    
    oPointCoords(3) = wa.Line.RootPoint.X
    oPointCoords(4) = wa.Line.RootPoint.Y
    oPointCoords(5) = wa.Line.RootPoint.Z
    
    Call coordSet.PutCoordinates(oPointCoords)
    
    Dim oLine As LineGraphics
    Set oLine = oSurfacesNode.AddLineGraphics
            
    oLine.CoordinateSet = coordSet
    oLine.ColorSet = oColorSet
    oLine.LineWeight = 2
    
    Dim oTransform As Matrix
    Set oTransform = ThisApplication.TransientGeometry.CreateMatrix
    
    Call oTransform.SetCoordinateSystem(wa.Line.RootPoint, wa.Line.Direction.AsVector, wa.Line.Direction.AsVector, wa.Line.Direction.AsVector)
    
    If wa.Line.Direction.X < 0 Or wa.Line.Direction.Y < 0 Or wa.Line.Direction.Z < 0 Then
        oSurfacesNode.Transformation = oTransform
    End If
    
    ThisApplication.ActiveView.Update
    
End Sub

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 10 of 11

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

thank you very much. Now are the axis aligned. But the lenght and the orientation are different. Is there any possibility to get the same lengt as the workaxis? How could I get the start and endpoint of the workaxis (WorkAxis.GetSize)?

 

Achse.png

 

Georg

0 Likes
Message 11 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @GeorgK,

 

Yes, WorkAxis.GetAxis() is good API to create LineGraphics of same length and orientation.

 

Try the following modified VBA code.

 

Sub Main()
    
    Dim doc As AssemblyDocument
    Set doc = ThisApplication.ActiveDocument
    
    Dim compDef As AssemblyComponentDefinition
    Set compDef = doc.ComponentDefinition
    
    Dim wa As WorkAxis
    Set wa = ThisApplication.CommandManager.Pick(kWorkAxisFilter, "Select a work axis to draw client graphics")
    
    Dim oClientGraphics As ClientGraphics
    Dim oDataSets As GraphicsDataSets
    
    On Error Resume Next
    
    Set oClientGraphics = compDef.ClientGraphicsCollection.Item("TestGraphicsID")
    Set oDataSets = doc.GraphicsDataSetsCollection.Item("TestID")
    
    If Err.Number = 1 Then
    On Error GoTo 0
        ' An existing client graphics object was successfully obtained so clean up.
        Set oClientGraphics = compDef.ClientGraphicsCollection.Add("TestGraphicsID")
        Set oDataSets = doc.GraphicsDataSetsCollection.Add("TestID")
        ' update the display to see the results.
        ThisApplication.ActiveView.Update
        
    Else
    
        Call oClientGraphics.Delete
        Call oDataSets.Delete
        Set oClientGraphics = compDef.ClientGraphicsCollection.Add("TestGraphicsID")
        Set oDataSets = doc.GraphicsDataSetsCollection.Add("TestID")
        
    End If
    
    ' Create a new graphics node within the client graphics objects.
    Dim oSurfacesNode As GraphicsNode
    Set oSurfacesNode = oClientGraphics.AddNode(1)
        
    Dim coordSet As GraphicsCoordinateSet
    Set coordSet = oDataSets.CreateCoordinateSet(1)
    
    Dim oColorSet As GraphicsColorSet
    Set oColorSet = oDataSets.CreateColorSet(1)
    
    
    Call oColorSet.Add(1, 255, 0, 0) ' For red

    'Call oColorSet.Add(1, 0, 255, 0) 'For Green
        
    Dim startPnt As Point
    Dim endPnt As Point
    Call wa.GetSize(startPnt, endPnt)
    
    Dim oPointCoords(5) As Double
    oPointCoords(0) = startPnt.X
    oPointCoords(1) = startPnt.Y
    oPointCoords(2) = startPnt.Z
    oPointCoords(3) = endPnt.X
    oPointCoords(4) = endPnt.Y
    oPointCoords(5) = endPnt.Z

    
    Call coordSet.PutCoordinates(oPointCoords)
    
    Dim oLine As LineGraphics
    Set oLine = oSurfacesNode.AddLineGraphics
            
    oLine.CoordinateSet = coordSet
    oLine.ColorSet = oColorSet
    oLine.LineWeight = 2
    
    ThisApplication.ActiveView.Update
    
End Sub

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network