[SOLVED] Draw vectors directly to 3D view using pivy + python
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
[SOLVED] Draw vectors directly to 3D view using pivy + python
Hi,
i need to know how to draw vectors (complete arrow from a 3D Point to another, with color) directly to 3D view by python, also how to delete them later.
Does someone have a small sample ?
Thanks in advance.
i need to know how to draw vectors (complete arrow from a 3D Point to another, with color) directly to 3D view by python, also how to delete them later.
Does someone have a small sample ?
Thanks in advance.
Last edited by kbwbe on Wed Dec 02, 2020 4:43 pm, edited 1 time in total.
KBWBE
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
Re: Draw vectors directly to 3D view using pivy + python
This sounds like something @joel_graffs pivy-trackers project can do.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Re: Draw vectors directly to 3D view using pivy + python
This sounds like something @joel_graffs pivy-trackers project can do.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
- HakanSeven12
- Veteran
- Posts: 1481
- Joined: Wed Feb 06, 2019 10:30 pm
Re: Draw vectors directly to 3D view using pivy + python
You can build an arrow by using lines. Here is my code to create lines.
Then
Then
Finally
Code: Select all
# Contour features.
cont_color = coin.SoBaseColor()
cont_color.rgb = (1, 1, 0)
cont_coords = coin.SoCoordinate3()
cont_lines = coin.SoLineSet()
Code: Select all
cont_coords.point.values = pointlist
Code: Select all
# Contour root.
contours = coin.SoSeparator()
contours.addChild(cont_color)
contours.addChild(cont_coords)
contours.addChild(cont_lines)
Code: Select all
sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(contours)
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Re: Draw vectors directly to 3D view using pivy + python
Thank you very much, will try that.
KBWBE
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
- HakanSeven12
- Veteran
- Posts: 1481
- Joined: Wed Feb 06, 2019 10:30 pm
Re: Draw vectors directly to 3D view using pivy + python
You are welcome. If you want to easily manage this view objects, I recommend you to create a feature python object.
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Re: Draw vectors directly to 3D view using pivy + python
Thanks again. Your code helped very much.
I got it running, final script was:
Code: Select all
import FreeCADGui
import FreeCAD
from PySide import QtGui
from PySide import QtCore
from pivy import coin
#setup the contour
color = coin.SoBaseColor()
color.rgb = (1, 0, 0)
points=coin.SoCoordinate3()
lines=coin.SoLineSet()
points.point.values = ( (0,0,0),(10,10,10),(10,10,0) )
#feed data to separator
sep=coin.SoSeparator()
sep.addChild(points)
sep.addChild(color)
sep.addChild(lines)
#add separator to sceneGraph
sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(sep)
I just want to avoid setting up feature python objects, as i need the lines for graphical debugging of my A2plus solver. Running the solver will probably generate a very big number of vectors, which could be to heavy for the FC document.HakanSeven12 wrote: ↑Wed Dec 02, 2020 4:22 pm If you want to easily manage this view objects, I recommend you to create a feature python object.
KBWBE
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
- HakanSeven12
- Veteran
- Posts: 1481
- Joined: Wed Feb 06, 2019 10:30 pm
Re: [SOLVED] Draw vectors directly to 3D view using pivy + python
You can draw them under one fpo but that is your decision also you can change line width. Add it separator before lineset.
Code: Select all
# Line style.
line_style = coin.SoDrawStyle()
line_style.style = coin.SoDrawStyle.LINES
line_style.lineWidth = 2
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Re: [SOLVED] Draw vectors directly to 3D view using pivy + python
Setting lineStype was a very good hint. Lines with width 1 are hard to see on a highres screen. Thanks
KBWBE
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
- HakanSeven12
- Veteran
- Posts: 1481
- Joined: Wed Feb 06, 2019 10:30 pm
Re: [SOLVED] Draw vectors directly to 3D view using pivy + python
You are welcome
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum