Split a window - createViewer(2)

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Chri1
Posts: 86
Joined: Wed Oct 17, 2018 9:00 am

Split a window - createViewer(2)

Post by Chri1 »

Hi
For example: I have two cubes (grey, red) and want to draw a line(red) from an vertex of the first cube to a vertex of the second cube.
To do this, I want to split the view into two parts, in the left part should be shown the first cube, in the right part the second cube.
The start of the line should be picked in in the left part, the end of the line in the right part.
split1.JPG
split1.JPG (10.8 KiB) Viewed 574 times
Till now I succeeded in creating the two parts:

Code: Select all

import FreeCADGui 
from pivy import coin 
from PySide import QtCore,QtGui 
import os,re
sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
v = FreeCADGui.createViewer(2, "NEU")
vv0 = v.getViewer(0)
vv1 = v.getViewer(1)
vv0.setSceneGraph(sg)
vv1.setSceneGraph(sg)
Now I can zoom by the mouse-wheel,and - different to the original window - move/rotate the view by right mouse with Shift/Strg
But when I try to draw the line (from left-window to right-window), the line is drawn somewhere and the snaps of the cubes do not work

Also it would be nice, if while drawing, a line is shown over both parts from starpoint to Cursor (see green line)
split2.jpg
split2.jpg (16.95 KiB) Viewed 574 times
Thanks
Chri1
edi
Posts: 482
Joined: Fri Jan 17, 2020 1:32 pm

Re: Split a window - createViewer(2)

Post by edi »

Hello Chri1

I think your problem is the following: In FreeCAD each object exists twice, as App.ActiveDocument and as Gui.ActiveDocument.

Your macro creates a new Gui object, which is not or not correct connected to the App object.

When starting the macro the new splited window "NEU" opens, and shows the object.

The old window of the object keeps existing. If you close the old window, the object in window "NEU" disappears.

I think the solution of your problem is to connect the Gui.ActiveDocument to the new opened split window.
Post Reply