Duplicate Objects when more than one face selected

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
poserge
Posts: 58
Joined: Mon Apr 06, 2015 4:06 am

Duplicate Objects when more than one face selected

Postby poserge » Thu Jun 02, 2016 4:54 am

I'm using freecad to convert parts of the STP files to Iges.
I select parts by picking them in viewport. Then I export parts by Files -> Export.
Problem arises when I select two or more faces of one object - it gets exported several times and I get duplicate objects in IGES.

I checked the code and see that objects added to selection based on faces if selected from viewports. Is this a way it is supposed to be?
Is it possible to filter out duplicate objects from selection during exporting?

I kind of know some programming and I'm willing to help the project since I use it all the time. I found the places in code where I can filter selection, but I decided to ask first since there may be some logic in keeping object duplicates in selection for other operations.

Freecad info (I used freecad for couple of years now and have this problem ever since):
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.7518 (Git)
Build type: Release
Branch: master
Hash: d7d347b2d62ec685840e7db1c35863e659148981
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
C++ beginner, willing to help FC with coding. Using FC for converting/decomposing STEP models into iges.
poserge
Posts: 58
Joined: Mon Apr 06, 2015 4:06 am

Re: Duplicate Objects when more than one face selected

Postby poserge » Fri Jun 03, 2016 4:08 am

I've just found out that duplicate selection also affects copying and pasting of the objects. I post description of the problem here with hope that it attracts more attention.

Basically when faces of the objects are selected and object is copied and pasted you get copy of the object and empty grey objects in objects tree.

These are steps to reproduce the problem:

0.Create new document
1.Change workbench to Part
2.Create Cube
3.Select two or more faces of the cube with mouse via Ctrl+LeftClick
4.Copy and Paste
5.Observe copy of the Cube and gray objects in the objects tree.
freecad_1.jpg
freecad_1.jpg (84.79 KiB) Viewed 1273 times
C++ beginner, willing to help FC with coding. Using FC for converting/decomposing STEP models into iges.
poserge
Posts: 58
Joined: Mon Apr 06, 2015 4:06 am

Re: Duplicate Objects when more than one face selected

Postby poserge » Mon Jun 06, 2016 1:09 am

Hi guys,

I filled the bug report on this issue - http://www.freecadweb.org/tracker/view.php?id=2578

I'm sorry no one pays attention to this bug which means people cope with it somehow, or I'm doing something wrong. I don't think it is hard to fix and I'm ready to fix it. The only thing I need is to be sure this is actual a bug.

Thanks and sorry if I annoy you guys with this post.
C++ beginner, willing to help FC with coding. Using FC for converting/decomposing STEP models into iges.
User avatar
bejant
Posts: 5803
Joined: Thu Jul 11, 2013 3:06 pm

Re: Duplicate Objects when more than one face selected

Postby bejant » Mon Jun 06, 2016 2:01 am

poserge wrote:I'm sorry no one pays attention to this bug which means people cope with it somehow, or I'm doing something wrong.
I don't think nobody is paying attention, instead I suspect that people aren't quite sure of your problem.

So let's go back a bit:
poserge wrote:Basically when faces of the objects are selected and object is copied and pasted you get copy of the object and empty grey objects in objects tree.

These are steps to reproduce the problem:

0.Create new document
1.Change workbench to Part
2.Create Cube
3.Select two or more faces of the cube with mouse via Ctrl+LeftClick
4.Copy and Paste
5.Observe copy of the Cube and gray objects in the objects tree.
First, when you select only one face of the original Cube, you're actually selecting the entire Cube. If you look in the hierarchy tree after selecting a face you'll see that Cube is selected. So selecting one face of Cube, then doing Copy (or Ctrl + C) and Paste (or Ctrl + V) creates a new Cube001 just as expected. Cube001 is also located in exactly the same 3D space and is exactly the same size as Cube, which is also as expected.

The oddity (to me) seems to happen when selecting two or more faces of Cube, then doing a Copy and Paste. When selecting two faces, I see that Box001 is also created (in addition to Cube001) but Box001 can never be made visible until Macro ForceRecompute is invoked.

Selecting three faces of Cube and doing a Copy and Paste creates another Box ("Box002"), which also can't be made visible until Macro ForceRecompute is run.

Yes, this seems to be a bug and I suspect that it is somewhat obscure because Box was renamed to Cube a probably few years ago, so thanks for reporting it.

If you want to Copy only Faces (instead of the whole object), you'll have to use the Draft WB > Downgrade tool (blue arrow pointing downwards) to Downgrade your solid into Faces, and then Copy and Paste the Faces you'd like to duplicate. The new Faces will be exactly the same and in the same location as the originals. You can also make a Copy of your original object, then Draft > Downgrade the Copy instead, so you still have the original solid in your FreeCAD document.
poserge
Posts: 58
Joined: Mon Apr 06, 2015 4:06 am

Re: Duplicate Objects when more than one face selected

Postby poserge » Mon Jun 06, 2016 3:32 am

Thanks for reply bejant,

I understand the oddity of selecting one object by selecting several faces but in my case this happens all the time. I'm working with complex stp files with many (tens to hundreds) overlapping objects. I need to select only some of them, so I pick faces in viewport and it's not always clear if I picked faces of different objects or several faces of one object.

If you check the first post in this topic, I started with problem of exporting duplicate objects. If I select several faces of one object (cube) after export I end up with several duplicate of one objects. And this is the biggest problem for me.

As for copy/paste operation, I just checked if this command has the same problem, since this is far more popular and people may come across the same problem.
C++ beginner, willing to help FC with coding. Using FC for converting/decomposing STEP models into iges.
User avatar
bejant
Posts: 5803
Joined: Thu Jul 11, 2013 3:06 pm

Re: Duplicate Objects when more than one face selected

Postby bejant » Mon Jun 06, 2016 1:09 pm

poserge wrote:I'm working with complex stp files with many (tens to hundreds) overlapping objects. I need to select only some of them, so I pick faces in viewport and it's not always clear if I picked faces of different objects or several faces of one object.
Looking at the Model tab in the Combo View (by default on the left side of the FreeCAD window) as you select each Face could help you see if a new object gets selected or not as you select another face, but with tens of objects in your model this would be tedious and with hundreds of objects it would be a nightmare and also unpractical.

Tools > Dependency Graph (you can get it from www.graphviz.org) could help you see the number of different objects in your model, if you didn't already know.

But I agree that if a user wants to Export different things from one FreeCAD file there doesn't seem to be any good reason (that I can think of anyway) why an object should be Exported multiple times in exactly the same place in the 3D space. The redundancy isn't needed.
wandererfan
Posts: 2882
Joined: Tue Nov 06, 2012 5:42 pm

Re: Duplicate Objects when more than one face selected

Postby wandererfan » Mon Jun 06, 2016 1:31 pm

This should do what you want. Faces are copies. Source object is hidden.

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# snippet for creating Face features from multiple selection
import FreeCAD
import Part
import Draft

#select your faces, then run this macro
s = FreeCADGui.Selection.getSelectionEx()
s[0].Object.ViewObject.hide()
for o in s:
   for obj in o.SubObjects:
      newobj = FreeCAD.ActiveDocument.addObject("Part::Feature","Face")
      newobj.Shape = obj.copy()
wf
wandererfan
Posts: 2882
Joined: Tue Nov 06, 2012 5:42 pm

Re: Duplicate Objects when more than one face selected

Postby wandererfan » Mon Jun 06, 2016 1:34 pm

MultiFaceSelect.png
MultiFaceSelect.png (4.23 KiB) Viewed 1204 times
mario52
Posts: 2646
Joined: Wed May 16, 2012 2:13 pm

Re: Duplicate Objects when more than one face selected

Postby mario52 » Mon Jun 06, 2016 4:13 pm

hi
this other macro stay resident and display in the Repport View HELP Box duplicate selection if the object is selected



how to change the mouse cursor if the object is selected ?
EDIT: trouvé (one moment)

Code: Select all

    def setPreselection(self, doc, object, sub):
        print "TYTY"
EDIT: 21:52 Paris Time :delete the old code
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
mario52
Posts: 2646
Joined: Wed May 16, 2012 2:13 pm

Re: Duplicate Objects when more than one face selected

Postby mario52 » Mon Jun 06, 2016 7:55 pm

Hi
new code
Start the macro select the object IN THE 3D VIEW the "ForbiddenCursor" stay if the or one selection is duplicate
the macro stay resident

Code: Select all

# -*- coding: utf-8 -*-
import FreeCADGui
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *

__title__   = "Macro_Duplicate_Selection"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.00"
__date__    = "06/06/2016"

__Help__    = "Start the macro select the object IN THE 3D VIEW the ForbiddenCursor stay if the selection is duplicate"

def selectionObject():
    sel = FreeCADGui.Selection.getSelection() 
    x  = []
    del x[:]
    for a in range(len(sel)):
       x.append(sel[a].Name)
    doublet = 0
    for i in range(len(sel)):
        for ii in range((i+1),len(sel)):
            if x[i] == x[ii]:
                doublet = 1
                break
    if doublet == 1:
        QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ForbiddenCursor))
#        FreeCAD.Console.PrintError("HELP "+sel[-1].Name+" duplicate selection"+"\n")
    else:
        QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

class SelObserver:
    def addSelection(self,doc,obj,sub,pnt):   # Selection
        selectionObject()
    def removeSelection(self,doc,obj,sub):    # Effacer l'objet salectionne
        selectionObject()
    def setPreselection(self, doc, obj, sub):
        selectionObject()
    def clearSelection(self,doc):             # Si clic sur l'ecran, effacer la selection
        selectionObject()
#    def setSelection(self,doc):               # Selection dans Combo View pour quitter la fonction
#        App.Console.PrintMessage("Fin Macro_Duplicate"+"\n")
#        QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
#        FreeCADGui.Selection.removeObserver(s)# desinstalle la fonction residente

s=SelObserver()
FreeCADGui.Selection.addObserver(s)    # installe la fonction en mode resident

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.