Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello together,
how could I colorize my userdefined workaxis with client graphics?
Thank you
Georg
Solved! Go to Solution.
Hello together,
how could I colorize my userdefined workaxis with client graphics?
Thank you
Georg
Solved! Go to 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,
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
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.
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.
With new models your code is working. Thank you very much.
Georg
The model where the axis are in the wrong orientation.
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,
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)?
Georg
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,