Another approach to assembly solver (A2plus)

Discussion about the development of the Assembly workbench.
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Postby manuelkrause » Mon Oct 29, 2018 1:49 pm

Jee-Bee wrote:
Mon Oct 29, 2018 1:28 pm

Code: Select all

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15007 (Git)
Build type: Release
Branch: master
Hash: 70fef3934190aabc61f5e1346483359d5ad21403
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Dutch/Netherlands (nl_NL)
kbwbe wrote: ping
Hi, Klaus,
this is a nice one: Please read @Jee-Bee's posts and test the assembly file on your side.
There are "invisible"-set bodies in the assembly.

I'm at least getting this:

Code: Select all

Running the Python command 'a2p_ViewConnectionsCommand' failed:
Traceback (most recent call last):
  File "/home/manuel/.FreeCAD/Mod/A2plus/a2p_importpart.py", line 769, in Activated
    a2plib.setTransparency()
  File "/home/manuel/.FreeCAD/Mod/A2plus/a2plib.py", line 110, in setTransparency
    if ( len(obj.ViewObject.DiffuseColor) == 1 ) :

'Gui.ViewProviderDocumentObject' object has no attribute 'DiffuseColor'
But maybe this is due to my testing around @wandererfan's color improvements.

Anyway, trying to solve this, I get a:

Code: Select all

===== Start Solving System ====== 
====================
Hierarchy:
====================
Draft_001 - distance 0
   Body001_001 - distance 1
      Body001_002 - distance 1
         Body001_009 - distance 2
      Body001_008 - distance 2
   Body001_002 - distance 1
      Body001_009 - distance 2
   Body001_003 - distance 1
      Body001_010 - distance 2
         Body001_011 - distance 3
   Body001_004 - distance 1
   Body001_005 - distance 1
      Body001_006 - distance 2
      Body001_007 - distance 2
====================

convergency-conter: 151
Calculation stopped, no convergency anymore!
TARGET   POS-ACCURACY :0.0001
REACHED  POS-ACCURACY :0.0008623529216662061
TARGET  SPIN-ACCURACY :0.0001
REACHED SPIN-ACCURACY :2.7704921932800045e-05
===== System solved using partial + recursive unfixing =====
User avatar
wandererfan
Posts: 3152
Joined: Tue Nov 06, 2012 5:42 pm

Re: Another approach to assembly solver (A2plus)

Postby wandererfan » 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.
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Postby manuelkrause » Mon Oct 29, 2018 4:02 pm

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
Posts: 3152
Joined: Tue Nov 06, 2012 5:42 pm

Re: Another approach to assembly solver (A2plus)

Postby wandererfan » 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.
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Postby manuelkrause » Mon Oct 29, 2018 4:17 pm

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)

Postby manuelkrause » Mon Oct 29, 2018 4:21 pm

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)

Postby manuelkrause » Mon Oct 29, 2018 5:06 pm

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

Re: Another approach to assembly solver (A2plus)

Postby kbwbe » Mon Oct 29, 2018 8:43 pm

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.30, installable via FreeCAD's addon manager
Tutorials:
Paul Randall: https://youtu.be/mnkecA9S7kc
anisim (deutsch): https://www.youtube.com/watch?v=vDcaFq6IEJM
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Postby manuelkrause » Tue Oct 30, 2018 4:26 pm

@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
Posts: 881
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Postby kbwbe » Wed Oct 31, 2018 3:03 pm

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 480 times
PartList.png
PartList.png (154.01 KiB) Viewed 480 times
.
How to do a partlist/BOM ??
Use these two new buttons...
NewButtons.png
NewButtons.png (2.27 KiB) Viewed 480 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 480 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.30, installable via FreeCAD's addon manager
Tutorials:
Paul Randall: https://youtu.be/mnkecA9S7kc
anisim (deutsch): https://www.youtube.com/watch?v=vDcaFq6IEJM