Anyway to highlight the assembly constraints?

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Anyway to highlight the assembly constraints?

Post by kbwbe »

Hi Koemi,

i also registered the problems with obscure constraints in assembly2. But i am not the developer of that workbench and not able to change that behavior.

I made a small macro which toggles the transparency of a whole assembly.
If the first part, the macro has found, is not transparent, the whole assembly changes to transparent mode. (and vice versa back on next run...)

Here is the makro-code:

Code: Select all


import FreeCADGui,FreeCAD

doc = FreeCAD.ActiveDocument

NONTRANSPARENT = 0
TRANSPARENT = 80

desiredTransparency = NONTRANSPARENT
# Get transparency of first visible object
for obj in doc.Objects:
    if hasattr(obj,'ViewObject'):
        if hasattr(obj.ViewObject,'Transparency'):
            if (obj.ViewObject.Transparency == NONTRANSPARENT):
                desiredTransparency = TRANSPARENT 
        break
# set transparency of objects...
for obj in doc.Objects:
    if hasattr(obj,'ViewObject'):
        if hasattr(obj.ViewObject,'Transparency'):
            obj.ViewObject.Transparency = desiredTransparency



For use copy the attached makro-file to your makro-folder and test it.

klaus
Attachments
toogleTransparency.FCMacro
(617 Bytes) Downloaded 58 times
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
Koemi
Posts: 150
Joined: Thu Dec 28, 2017 11:13 am
Location: The Netherlands

Re: Anyway to highlight the assembly constraints?

Post by Koemi »

Thanks kbwbe, works perfect! :D
tomerp
Posts: 14
Joined: Thu Jan 04, 2018 1:41 am

Re: Anyway to highlight the assembly constraints?

Post by tomerp »

Hi Klaus
thanks for your article it is great. I wonder - how can we make your code run as soon as a constraint is selected without having to press the "Show constraint" Button?
See my thread on this matter here:
https://forum.freecadweb.org/viewtopic.php?f=10&t=30175

Please let me know
Thanks
Tomer

kbwbe wrote: Wed Apr 18, 2018 4:28 pm Hello ceremcem,

i think it is simple to modify assembly2 by yourself.
I am already working with an modified version, which i did last time.

At short: You have to extend freecad a little bit. I created a new command with i copied to importpart.py, which is located in your mod-folder and there within the assembly2 folder.

here is the code for the command-extension:

Code: Select all

class ViewConnectionsCommand:
    def Activated(self):
        selection = [s for s in FreeCADGui.Selection.getSelection() if s.Document == FreeCAD.ActiveDocument ]
        if len(selection) == 0: return
        FreeCADGui.Selection.clearSelection()
        
        doc = FreeCAD.ActiveDocument
        connectionToView = selection[0]
        
        if not 'ConstraintInfo' in connectionToView.Content and not 'ConstraintNfo' in connectionToView.Content: 
            return # Selected Object is not a connection/constraint
        
        # Save Transparency of Objects and make all transparent
        transparencyList = []
        for obj in doc.Objects:
            if hasattr(obj,'ViewObject'):
                if hasattr(obj.ViewObject,'Transparency'):
                    transparencyList.append(obj.ViewObject.Transparency) 
                    obj.ViewObject.Transparency = 80 
        
        FreeCADGui.Selection.addSelection(
            doc.getObject(connectionToView.Object1),
            connectionToView.SubElement1
            )
        FreeCADGui.Selection.addSelection(
            doc.getObject(connectionToView.Object2),
            connectionToView.SubElement2
            )
        
        #FreeCADGui.SendMsgToActiveView("ViewSelection") # not good enough
        
        flags = QtGui.QMessageBox.StandardButton.Yes
        msg = "Close Connection ViewMode ?"
        response = QtGui.QMessageBox.information(QtGui.qApp.activeWindow(), "Highlighting ready", msg, flags )
        
        # restore transparency of objects...
        i=0
        for obj in doc.Objects:
            if hasattr(obj,'ViewObject'):
                if hasattr(obj.ViewObject,'Transparency'):
                    obj.ViewObject.Transparency = transparencyList[i]
                    i+=1
        
        FreeCADGui.Selection.clearSelection()
        FreeCADGui.Selection.addSelection(selection[0])

    def GetResources(self):
        return {
            'Pixmap'  : a3lib.pathOfModule()+'/icons/a3_viewConnection.svg',
            'MenuText': 'show connected elements',
            'ToolTip': 'show connected elements'
            }
        
FreeCADGui.addCommand('a3_ViewConnectionsCommand', ViewConnectionsCommand())
 
The command turns all parts of the assembly to transparency and highlights the components of an selected constraint.
I dont have much time at the moment and have to leave the house within a few minutes, shortly i will tell you more...

p.s.: PLEASE PROVIDE YOUR SYSTEMINFORMATION...

regards,
Klaus
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Anyway to highlight the assembly constraints?

Post by kbwbe »

tomerp wrote: Tue Aug 14, 2018 6:09 am Hi Klaus
thanks for your article it is great. I wonder - how can we make your code run as soon as a constraint is selected without having to press the "Show constraint" Button?
See my thread on this matter here:
https://forum.freecadweb.org/viewtopic.php?f=10&t=30175

Please let me know
Hi Tomer,
do not have much time at moment as development of my new assembly-WB A2plus is eating up all my free time.
You can have a look at the sourcecode of A2plus, especially a2p_importPart.py and a2plib. I think everything you need you will find there.

Behaviour of A2plus:
- select one Constraint
- hit button "viewConnections"
- once you entered "viewConnections" mode:
- assembly gets transparent
- the constraint is shown
- you can select other constraints, A2plus will show new selected constraints instantly
- and so on...

- if deselecting by click on 3D View background, viewConnections mode will be terminated.
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
User avatar
ceremcem
Posts: 226
Joined: Sun Jan 07, 2018 11:10 am

Re: Anyway to highlight the assembly constraints?

Post by ceremcem »

Hi,

I figured out that at the time of posting the topic, I didn't set "Notify me on reply" option explicitly, so I was not aware of the replies for a long time. When I saw, I was already dove into Assembly3, so I didn't give any feedback. Now I see the progress and I want to thank you for your help. I'm also glad to see it was useful for other users or I would feel remorse.
tomerp
Posts: 14
Joined: Thu Jan 04, 2018 1:41 am

Re: Anyway to highlight the assembly constraints?

Post by tomerp »

Hi Klaus
I wanted to thank you but i fear a2plus is pretty buggy for me. I am unable to continue my work using it since it keeps deleting parts from my assembly when i delete constraints, and other wierd behaviours. I will try to reproduce and help you fix. Unless you are aware of issues.
Meanwhile i will also try to continue working with assembly 2
thanks
Tomer
kbwbe wrote: Tue Aug 14, 2018 4:23 pm
tomerp wrote: Tue Aug 14, 2018 6:09 am Hi Klaus
thanks for your article it is great. I wonder - how can we make your code run as soon as a constraint is selected without having to press the "Show constraint" Button?
See my thread on this matter here:
https://forum.freecadweb.org/viewtopic.php?f=10&t=30175

Please let me know
Hi Tomer,
do not have much time at moment as development of my new assembly-WB A2plus is eating up all my free time.
You can have a look at the sourcecode of A2plus, especially a2p_importPart.py and a2plib. I think everything you need you will find there.

Behaviour of A2plus:
- select one Constraint
- hit button "viewConnections"
- once you entered "viewConnections" mode:
- assembly gets transparent
- the constraint is shown
- you can select other constraints, A2plus will show new selected constraints instantly
- and so on...

- if deselecting by click on 3D View background, viewConnections mode will be terminated.
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Anyway to highlight the assembly constraints?

Post by kbwbe »

tomerp wrote: Sun Oct 21, 2018 7:08 am Hi Klaus
I wanted to thank you but i fear a2plus is pretty buggy for me. I am unable to continue my work using it since it keeps deleting parts from my assembly when i delete constraints, and other wierd behaviours. I will try to reproduce and help you fix. Unless you are aware of issues.
Meanwhile i will also try to continue working with assembly 2
Hi Tomer,
i would be very interested in a detailed error description, as i do not register such bugs on here.
Please provide also your systeminformation.
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
herbk
Veteran
Posts: 2660
Joined: Mon Nov 03, 2014 3:45 pm
Location: Windsbach, Bavarya (Germany)

Re: Anyway to highlight the assembly constraints?

Post by herbk »

Hi Tomer,

i'm playing around a lot atm with A2plus and can't confirm that behavior.

Atm i'm at

OS: "openSUSE Leap 42.3"
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.14995 (Git) AppImage
Build type: Release
Branch: master
Hash: 7b866816785ac1ca9787b63d4bff12873bb3a593
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)

but also at the commits before i don't see that.
Gruß Herbert
Post Reply