Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A2Assembly, path incorrect when generating the BOM File #50

Closed
didiergm opened this issue Mar 12, 2024 · 16 comments
Closed

A2Assembly, path incorrect when generating the BOM File #50

didiergm opened this issue Mar 12, 2024 · 16 comments

Comments

@didiergm
Copy link

didiergm commented Mar 12, 2024

I wanted to check if importing a sub assembly woud work when creating a BOM.
I creatd the sub assemply in a sub sirectory, for practical reasons, A2plus, does not complain and it's parts list is fine.

But when generating the BOM list I get the following

16:02:05 File '/home/didier/Bureau/Cuisine/tiroir_assembly.FCStd' does not exist!
16:02:05 Traceback (most recent call last):
16:02:05 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./Load_BoM_Panel.py", line 286, in on_CreateBOM_clicked
16:02:05 GetBOM_A2plus.BomFunctions.Start(
16:02:05 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 723, in Start
16:02:05 raise e
16:02:05 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 701, in Start
16:02:05 self.GetTreeObjects(checkAssemblyType=CheckAssemblyType)
16:02:05 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 74, in GetTreeObjects
16:02:05 self.GoThrough_Objects(
16:02:05 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 179, in GoThrough_Objects
16:02:05 ObjectDocument = App.openDocument(FullPath, True)
16:02:05 OSError: File '/home/didier/Bureau/Cuisine/tiroir_assembly.FCStd' does not exist!

It is normal, that file does not exists, it is in /home/didier/Bureau/Cuisine/tiroir/tiroir_assembly.FCStd, notice the missing tiroir subdirectory

If that helps, I am happy to provide a new set of files

@APEbbers
Copy link
Owner

I couldn't reproduce the error. However, I've changed the code to try something.
Can you switch to the following branch and see if anything has changed?
"git checkout Patch-1"

The A2plus workbench works differently than the others. it doesn't allow to get to the absolute paths. I've written code for that, which I tweaked.

@didiergm
Copy link
Author

git checkout Patch-1 is rejected here
and making a git branch -r I got

origin/Develop
origin/HEAD -> origin/main
origin/main

I am happy, if you tell me which file I need to bring up to date to simply copy/paste the new code

@APEbbers
Copy link
Owner

APEbbers commented Mar 12, 2024

if you can change in the file "GetBOM_A2plus.py" on lines 173 and 256 the following:
replace "if FullPath.startswith("."):" with "if FullPath.startswith(".\\") or FullPath.startswith("./"):"

image

Hopefully that helps

@didiergm
Copy link
Author

Sorry to be the bearer of bad news, it does not.

My Python knowledge is at best sparse, so I can't really help debug, but I am happy to do more testing if it helps

@APEbbers
Copy link
Owner

If you select the sub assembly. do you see an absolute path like this?
image

@didiergm
Copy link
Author

No a path relative to the main assembly

./tiroir/tiroir_assembly.FCStd

@APEbbers
Copy link
Owner

Thank!, that's the problem. On my windows pc and my linux pc I have absolute paths when the items are on a different location then the assembly there are in. Probably this is different for some linux versions or with certain settings.

Now I have something to go on and start to figure how to tackle this to cover both situations.

@APEbbers
Copy link
Owner

I believe that I've found it. Can you update the WB to version 0.05.11 and give it a try?

@didiergm
Copy link
Author

Update did not go as planned :
I first had the option in the addon manager to update, to 0.05.11, I clicked on update, update went through and noticed that the message was "0.05.7" installed, up-to-date. I restarted, checked and I was indeed on 0.05.7
I desintalled completely, restarted, installed again and I am stuck on 0.05.7 , 0.05.11 is not suggested anymore

I then deinstalled, went to the addons directory, removed a directory BillOfMaterials.backup1710312901.0584648 which was a leftover (may be from the manual updates I did yesterday)

started, installed, installer said "version ..11", did the install and again I got version ..7
which is not a happy bunny :

07:58:18 Initializing A2plus Workbench v0.4.64.
07:59:06 Traceback (most recent call last):
07:59:06 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./Load_BoM_Panel.py", line 286, in on_CreateBOM_clicked
07:59:06 GetBOM_A2plus.BomFunctions.Start(
07:59:06 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 723, in Start
07:59:06 raise e
07:59:06 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 701, in Start
07:59:06 self.GetTreeObjects(checkAssemblyType=CheckAssemblyType)
07:59:06 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 74, in GetTreeObjects
07:59:06 self.GoThrough_Objects(
07:59:06 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 184, in GoThrough_Objects
07:59:06 if childObject.objectType == "a2pPart":
07:59:06 AttributeError: 'FeaturePython' object has no attribute 'objectType'

@APEbbers
Copy link
Owner

Maybe it helps if you do a git pull from the command line?
You can check if in package.xml, version 0.0.5.11 is mentioned.

You have modified the files by hand. These can give a problem because these are no longer in sync with the versions in github.
Can you try: "git checkout GetBOM_A2plus.py" followed by "Git pull"?

Maybe reverting the file and then update to the latest version helps.

@didiergm
Copy link
Author

Something went wrong with the AddOn cache, so even if freecad was saying that I installed version 11, on the next start the version installed was .7. After removing freecad completely and reinstalling it afresh , I now have v11 installed.

But I get this message
21:53:44 Traceback (most recent call last):
21:53:44 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./Load_BoM_Panel.py", line 286, in on_CreateBOM_clicked
21:53:44 GetBOM_A2plus.BomFunctions.Start(
21:53:44 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 723, in Start
21:53:44 raise e
21:53:44 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 701, in Start
21:53:44 self.GetTreeObjects(checkAssemblyType=CheckAssemblyType)
21:53:44 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 74, in GetTreeObjects
21:53:44 self.GoThrough_Objects(
21:53:44 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 184, in GoThrough_Objects
21:53:44 if childObject.objectType == "a2pPart":
21:53:44 AttributeError: 'FeaturePython' object has no attribute 'objectType'

@APEbbers
Copy link
Owner

I've found the cause of the error. it was caused by that not all objects have an objectType property.
image

Maybe there was an part or feature added outside A2plus.

Now everything that is not added with the a2plus wb will be ignored. The new version is 0.0.5.12

@didiergm
Copy link
Author

Progress, but still not there yet, though. And I hate to waste your time.

Original exception was:
10:31:16 Traceback (most recent call last):
10:31:16 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./Load_BoM_Panel.py", line 286, in on_CreateBOM_clicked
10:31:16 GetBOM_A2plus.BomFunctions.Start(
10:31:16 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 724, in Start
10:31:16 raise e
10:31:16 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 706, in Start
10:31:16 self.CreateTotalBoM(
10:31:16 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 339, in CreateTotalBoM
10:31:16 CopyMainList = self.ReturnDuplicates()
10:31:16 File "/home/didier/.local/share/FreeCAD/Mod/BillOfMaterials/./GetBOM_A2plus.py", line 300, in ReturnDuplicates
10:31:16 if Label.rsplit("", 1)[1].isnumeric() and len(Label.rsplit("", 1)[1]) == 3:
10:31:16 IndexError: list index out of range

However, I would also like to test Assembly3, do you foresee any issues ?

@APEbbers
Copy link
Owner

I for see no issues for the Assembly3 WB. the A2plus WB is a bit of a special case. Internally the assembly 3 (and 4) follow more the workings of FreeCAD self.

I actually apricate it that you are willing to test my WB. As you switch to Assembly3 can I perhaps get a copy of your files that generate the latest error? Then I can see what is going on. I probably overlooked a usecase scenario.

@didiergm
Copy link
Author

didiergm commented Mar 15, 2024

I am dead set on using your addon, I started using Freecad as I have many, quite complex furnitures to make in my house, and I don't want to desing by hand, and my ultimate goal is to go up to an optimized cutlist of plywood sheets (hence my enhancement request about width, length and offset) .

As a software developper myself, I understand that these things take time and needs several or many iterations before being perfect, too bad I don't have the time to learn Python and Freecad's internals or I would have been happy to help more. Perhaps, this is a conversation we can have directly you and I.

I am planning to look at assembly3, but A2Plus almost fit my needs (there are a few missing constraints like distance between planes, but it can be emulated with offsets, not as clean and straight forward as I would like).

By all means, I am happy to carry on helping and I attach all my files, nothing is confidential, if you want e to try and test something, just say so.
envoi.zip

Note that it is work in progress, not yet finished, and again this is my first freecad project, so it my not follow Freecad's best practices, but please do keep us posted on your progress

@APEbbers
Copy link
Owner

I've found the cause of the error. It was caused by items that were renamed. This is a totally fine practice. So no worries.
I've fixed this in version 0.0.5.13

In FreeCAD as default when you add parts twice or more, you get _001, _002, etc after the name. I've created a function to return the original part, so that in the BoM, the qty increases and avoid add them all separately.
However I've overlooked the fact that you can use the same part, but rename them differently and then remove the follow up number. That was the cause.
currently, when you rename the same parts differently you will get each item separate in the BoM.

When you use one of the other assembly workbenches, you can expand the subassemblies in the tree. A2plus is different in this area. (as an answer to # #49)

To explain a little about me, I'm actually not a professional software developer but a mechanical engineer. I'd like to program as a hobby and have learned my self Python, c# and VB.net. FreeCAD is for me the ideal program for all my projects. Both for design projects and programming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants