Another approach to assembly solver (A2plus)

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Another approach to assembly solver (A2plus)

Post by wandererfan »

manuelkrause wrote: Mon Oct 29, 2018 1:49 pm But maybe this is due to my testing around @wandererfan's color improvements.
In a2plib.SetTransparency, there is no filtering done to determine if the current object should be processed or not.
SetTransparency is trying to get the length of DiffuseColor property of the ViewProvider of "X_Axis" in the hidden Body. This VP doesn't have a DiffuseColor property, so Python throws an exception.


The test for DiffuseColor (approx L109) should not be commented and the following code should be indented under this test:

Code: Select all

 
 if hasattr(obj.ViewObject,'DiffuseColor'):
     if ( len(obj.ViewObject.DiffuseColor) == 1 ) :
         DebugMsg(A2P_DEBUG_3,"a2p setTransparency:  ONE ShapeColor and Transparency detected:\n{}" \
                            .format(obj.ViewObject.DiffuseColor))
     else:
         DebugMsg(A2P_DEBUG_3,"a2p setTransparency: muxed assembly detected:\n{}" \
                           .format(obj.ViewObject.DiffuseColor))
     DebugMsg(A2P_DEBUG_3,"A2P setTransparency: Saving transparency!\n")
     SAVED_TRANSPARENCY.append(
                    (obj.Name, obj.ViewObject.Transparency, obj.ViewObject.DiffuseColor)
                    )
                       
Edit: missed the "SAVED_TRANSPARENCY" line.
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Post by manuelkrause »

wandererfan wrote: Mon Oct 29, 2018 3:21 pm
manuelkrause wrote: Mon Oct 29, 2018 1:49 pm But maybe this is due to my testing around @wandererfan's color improvements.
In a2plib.SetTransparency, there is no filtering done to determine if the current object should be processed or not.
SetTransparency is trying to get the length of DiffuseColor property of the ViewProvider of "X_Axis" in the hidden Body. This VP doesn't have a DiffuseColor property, so Python throws an exception.


The test for DiffuseColor (approx L109) should not be commented and the following code should be indented under this test:

Code: Select all

 
 if hasattr(obj.ViewObject,'DiffuseColor'):
     if ( len(obj.ViewObject.DiffuseColor) == 1 ) :
         DebugMsg(A2P_DEBUG_3,"a2p setTransparency:  ONE ShapeColor and Transparency detected:\n{}" \
                            .format(obj.ViewObject.DiffuseColor))
     else:
         DebugMsg(A2P_DEBUG_3,"a2p setTransparency: muxed assembly detected:\n{}" \
                           .format(obj.ViewObject.DiffuseColor))
     DebugMsg(A2P_DEBUG_3,"A2P setTransparency: Saving transparency!\n")
     SAVED_TRANSPARENCY.append(
                    (obj.Name, obj.ViewObject.Transparency, obj.ViewObject.DiffuseColor)
                    )
                       
Edit: missed the "SAVED_TRANSPARENCY" line.
Where should I insert what? That doesn't come over clearly.
TIA
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Another approach to assembly solver (A2plus)

Post by wandererfan »

manuelkrause wrote: Mon Oct 29, 2018 4:02 pm Where should I insert what? That doesn't come over clearly.
You don't have to insert anything. Just comment 1 line and indent the ones below it. Approximately Line 109 in function SetTransparency in file a2plib.py.
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Post by manuelkrause »

wandererfan wrote: Mon Oct 29, 2018 4:09 pm
manuelkrause wrote: Mon Oct 29, 2018 4:02 pm Where should I insert what? That doesn't come over clearly.
You don't have to insert anything. Just comment 1 line and indent the ones below it. Approximately Line 109 in function SetTransparency in file a2plib.py.
I know absolutely what you mean, but now I get:
"During initialization the error expected an indented block (a2plib.py, line 110) occurred in /home/manuel/.FreeCAD/Mod/A2plus/InitGui.py
Please look into the log file for further information"
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Post by manuelkrause »

DON'T ANSWER. I'VE MADE A BUG MYSEF ON HERE.
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Post by manuelkrause »

wandererfan wrote: Mon Oct 29, 2018 3:21 pm
manuelkrause wrote: Mon Oct 29, 2018 1:49 pm But maybe this is due to my testing around @wandererfan's color improvements.
In a2plib.SetTransparency, there is no filtering done to determine if the current object should be processed or not.
SetTransparency is trying to get the length of DiffuseColor property of the ViewProvider of "X_Axis" in the hidden Body. This VP doesn't have a DiffuseColor property, so Python throws an exception.


The test for DiffuseColor (approx L109) should not be commented and the following code should be indented under this test:

Code: Select all

 
 if hasattr(obj.ViewObject,'DiffuseColor'):
     if ( len(obj.ViewObject.DiffuseColor) == 1 ) :
         DebugMsg(A2P_DEBUG_3,"a2p setTransparency:  ONE ShapeColor and Transparency detected:\n{}" \
                            .format(obj.ViewObject.DiffuseColor))
     else:
         DebugMsg(A2P_DEBUG_3,"a2p setTransparency: muxed assembly detected:\n{}" \
                           .format(obj.ViewObject.DiffuseColor))
     DebugMsg(A2P_DEBUG_3,"A2P setTransparency: Saving transparency!\n")
     SAVED_TRANSPARENCY.append(
                    (obj.Name, obj.ViewObject.Transparency, obj.ViewObject.DiffuseColor)
                    )
                       
Edit: missed the "SAVED_TRANSPARENCY" line.
Editing and changing my code leads to the same issue for toggletransparency.
You need at least a mouse-over the shape to get an according change in the view.
Not working standalone from a click.
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

Hi Jee-Bee,
thank you very much for testing.
Your testobject is really good and i can confirm that i had some difficulties to assemble it.
Jee-Bee wrote: Mon Oct 29, 2018 11:25 am 1 The point/ vertexes are quite hard to select. Maybe this is a FC issue
As @manuelkrause already said in post before, increasing vertexsize within preferences/FD-Display helps a little bit. But vertexes are sometimes difficult to select within FC. I think it as generally problem, not one of A2plus.
Jee-Bee wrote: Mon Oct 29, 2018 11:25 am 2 i had some repetive set of constraints. but for some reason it fails sometimes during build.
i had the workflow [axis, plane point] but sometimes i was unable to add the plane step at once... so i had to do [axis1, axis2] so it position was around good. than remove axis 2 and add plane, and final add point.
I can confirm. Next time, when finishing partlist/BOM, i intend to work on solver again. When setting an axis, then plane, next a point, it was working for me. But this way was not intended. P.S: Setting plane at first mostly did not work for me..
Jee-Bee wrote: Mon Oct 29, 2018 11:25 am 3 i was missing axis on plane
This is already in the A2p wishlist. I will implement it next time working on solver.
Jee-Bee wrote: Mon Oct 29, 2018 11:25 am 4 I started with a model with 2 part design bodies. It looks like A2P is unable to handle this without conversion...
Leaving PartDesign bodies within the assembly is not the intended workflow. Best way is to import everything. Converting is also not the preferred way. Even all parametrics of the parts get lost. For my test, i separated the parts to single files and imported them again. This works without problems. (except some solving problems)
Jee-Bee wrote: Mon Oct 29, 2018 11:25 am Final: Thanks for all your work
Your are welcome. I hope this work contributes in some way to FC.
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
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Post by manuelkrause »

@wandererfan and @kbwbe:
I've worked a little with @Jee-Bee's corner case assembly to maybe improve the "toggle transparency" a little.
Advantage: All obj's are processed without failure and get displayed / restored properly regarding transparency. Also "show connected elements" (for a selected constraint) works as wanted.

See the changed code section in a2plib.py below.

Code: Select all

#------------------------------------------------------------------------------
def setTransparency():
    global SAVED_TRANSPARENCY
    # Save Transparency of Objects and make all transparent
    doc = FreeCAD.ActiveDocument

    if len(SAVED_TRANSPARENCY) > 0:
        # Transparency is already saved, no need to set transparency again
        return

    for obj in doc.Objects:
        if hasattr(obj,'ViewObject'):
            if hasattr(obj.ViewObject,'Transparency'):
                if hasattr(obj.ViewObject,'DiffuseColor'):
                    diffuseFlag = True
                    if ( len(obj.ViewObject.DiffuseColor) == 1 ) :
                        DebugMsg(A2P_DEBUG_3,"a2p setTransparency: one-shape DiffuseColor detected:\n{}\n" \
                            .format(obj.ViewObject.DiffuseColor))
                    else:
                        DebugMsg(A2P_DEBUG_3,"a2p setTransparency: muxed-shape DiffuseColor detected:\n{}\n" \
                            .format(obj.ViewObject.DiffuseColor))
                    DebugMsg(A2P_DEBUG_3,"a2p setTransparency: Saving transparency (DiffuseColor)\n")
                    SAVED_TRANSPARENCY.append(
                            (obj.Name, obj.ViewObject.Transparency, diffuseFlag, obj.ViewObject.DiffuseColor)
                        )
                else:
                    diffuseFlag = False
                    DebugMsg(A2P_DEBUG_3,"a2p setTransparency: Saving transparency (ShapeColor)\n")
                    SAVED_TRANSPARENCY.append(
                            (obj.Name, obj.ViewObject.Transparency, diffuseFlag, obj.ViewObject.ShapeColor)
                        )
                obj.ViewObject.Transparency = 80

#------------------------------------------------------------------------------
def restoreTransparency():
    global SAVED_TRANSPARENCY
    # restore transparency of objects...
    doc = FreeCAD.ActiveDocument

    for setting in SAVED_TRANSPARENCY:
        obj = doc.getObject(setting[0])
        if obj is not None:
            obj.ViewObject.Transparency = setting[1]
            if setting[2] == True :
                obj.ViewObject.DiffuseColor = setting[3]
            else:
                obj.ViewObject.ShapeColor = setting[3]
    SAVED_TRANSPARENCY = []
#------------------------------------------------------------------------------
I've left the debug messages in. Remove them if the code is tested for usefulness.

Unfortunately this hack doesn't work for higher grade assemblies. There's still a mouse-over the imported subassembly needed to see the changed 80% transparency and vice versa, when clicking toggle-transparency. This again shows that there's stuff for the other thread...
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

Hi Guy's,
the A2plus devel branch has been updated.
A2p now supports partslist/BOM to spreadsheet.

Please find here a picture of the 1) assembled object and 2.) the generated spreadsheet with the partslist/BOM
Frame-Assembly.png
Frame-Assembly.png (93.97 KiB) Viewed 1659 times
PartList.png
PartList.png (154.01 KiB) Viewed 1659 times
.
How to do a partlist/BOM ??
Use these two new buttons...
NewButtons.png
NewButtons.png (2.27 KiB) Viewed 1659 times
At first, insert a PartsInfo-Spreadsheet with the according button into each .fcstd-file, which you want to import. Enter your data and save the file
.
PartInfo-Spreadsheet.png
PartInfo-Spreadsheet.png (87.67 KiB) Viewed 1659 times
.
Second, open the assembly file and hit the "PartsList" button. A spreadsheet ist generated and all data is extracted from underlying imported files. Each PartsInfo-spreadsheet is evaluated.

When hitting the "PartList" button, you are asked if A2p should iterate recursively over all subassemblies, to generate a complete partslist. The involved importParts/subassemblies are not necessary to be open, as A2p is directly reading from compressed xml document data.

Have fun.
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
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

Hi,

there is a new release v0.1.5 available.
It contains the new basic partlist functionality, see my post before.
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
Post Reply