[SOLVED] A2P cannot import part if there is TechDraw sheet attached

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
babaroga
Posts: 178
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

[SOLVED] A2P cannot import part if there is TechDraw sheet attached

Post by babaroga »

Hello,

I have problem with importing part created in PartDesign if there is also TechDraw sheet generated inside of it.

In report View I get

Code: Select all

Running the Python command 'a2p_ImportPart' failed:
Traceback (most recent call last):
  File "/home/senja/.FreeCAD/Mod/A2plus/a2p_importpart.py", line 576, in Activated
    importedObject = importPartFromFile(doc, filename)
  File "/home/senja/.FreeCAD/Mod/A2plus/a2p_importpart.py", line 194, in importPartFromFile
    importableObjects = topoMapper.getTopLevelObjects(allowSketches=True)
  File "/home/senja/.FreeCAD/Mod/A2plus/a2p_topomapper.py", line 411, in getTopLevelObjects
    shapeObs = a2plib.filterShapeObs(self.doc.Objects,allowSketches)
  File "/home/senja/.FreeCAD/Mod/A2plus/a2plib.py", line 252, in filterShapeObs
    if len(ob.Shape.Faces) > 0 and len(ob.Shape.Vertexes) > 0:

'str' object has no attribute 'Faces'
If Tech Draw sheet is deletet, part imports as expected.

Is there some workaround to overcome this.

A2P is V 0.4.47 and FreeCAD is

Code: Select all

OS: Manjaro Linux (KDE//usr/share/xsessions/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.21525 (Git)
Build type: Release
Branch: master
Hash: 8311b1e66de5f13e4e8f5338958e4a9699020b82
Python version: 3.8.3
Qt version: 5.14.2
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)
In attachment, there is one example file. Try to import it to assembly, and then delete TechDraw sheet and try again.

Thank you in advance.
Attachments
Loka 2K-maska prednja.FCStd
(47.96 KiB) Downloaded 43 times
Last edited by babaroga on Tue Jun 09, 2020 6:54 am, edited 1 time in total.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: A2P cannot import part if there is TechDraw sheet attached

Post by Syres »

I could replicate your bug on Linux, need to do some further investigation on Windows but here is a fix:

Change line 251 in home/username/.FreeCAD/Mod/A2plus/a2plib.py from:

Code: Select all

        if hasattr(ob,"Shape"):

to:

Code: Select all

        if hasattr(ob,"Shape") and not ob.TypeId.startswith("TechDraw"):
or I've attached a copy of the modified file so you can overwrite it. Once I've verified on Windows I'll submit a PR for @kbwbe to merge into his master.
Attachments
a2plib.py
(45.34 KiB) Downloaded 45 times
User avatar
babaroga
Posts: 178
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: A2P cannot import part if there is TechDraw sheet attached

Post by babaroga »

Hello,

I spotted it first om my colleagues Windows box. To be actual, on three of them :-). So I can confirm, this bug also exists on windows. I will try your fix on one of them...
User avatar
babaroga
Posts: 178
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: A2P cannot import part if there is TechDraw sheet attached

Post by babaroga »

I can confirm, your fix works on Windows box too. Everything works as expected.

Thank you for quick response.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: [SOLVED] A2P cannot import part if there is TechDraw sheet attached

Post by Syres »

PR submitted for @kbwbe to review https://github.com/kbwbe/A2plus/pull/387
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: [SOLVED] A2P cannot import part if there is TechDraw sheet attached

Post by kbwbe »

Syres wrote: Tue Jun 09, 2020 2:46 pm PR submitted for @kbwbe to review https://github.com/kbwbe/A2plus/pull/387
Thank you for your PR. :D
New version of A2plus is V0.4.47a
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
wandererfan
Veteran
Posts: 6270
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [SOLVED] A2P cannot import part if there is TechDraw sheet attached

Post by wandererfan »

Syres wrote: Tue Jun 09, 2020 2:46 pm PR submitted for @kbwbe to review https://github.com/kbwbe/A2plus/pull/387
kbwbe wrote:
I was quite surprised to learn that TechDraw objects have a Shape. :o

Code: Select all

>>> v = App.ActiveDocument.View
>>> v.Shape
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'TechDraw.DrawViewPart' object has no attribute 'Shape'
I assume you are using Part.getShape() to make the determination that something has a shape?

Code: Select all

import Part
>>> Part.getShape(v)
<Shape object at 0x5614e9664240>
>>> x = Part.getShape(v)
>>> x
<Shape object at 0x5614e9668f00>
>>> x.isNull()
True
Be aware that Part.getShape() will return a null shape for many things that don't have a shape - for example, Spreadsheets:

Code: Select all

>>> ss = App.ActiveDocument.Spreadsheet
>>> ss.Shape
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'Spreadsheet.Sheet' object has no attribute 'Shape'
>>> Part.getShape(ss)
<Shape object at 0x5614e97ac200>
>>> x = Part.getShape(ss)
>>> x.isNull()
True
>>> 
You may want to change your fix so it tests for shape.isNull() instead of "starts with TechDraw".

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

Re: [SOLVED] A2P cannot import part if there is TechDraw sheet attached

Post by kbwbe »

wandererfan wrote: Wed Jun 10, 2020 12:43 pm I assume you are using Part.getShape() to make the determination that something has a shape?
...
Be aware that Part.getShape() will return a null shape for many things that don't have a shape...
Thank you for your hints. I checked my code and nowhere Part.getShape() is used. Investigating further, i found this within @babaroga's original file:

Code: Select all

>>> doc = App.activeDocument()
>>> balloon = doc.getObject('Balloon')
>>> hasattr(balloon,"Shape")
True
>>> balloon.Shape
'None'
It seem's, that the ballon object has an attribute 'Shape' with value 'None'. This caused A2p to fail.

Nevertheless i will modify the last fix and catch Shapes with value 'None'.
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
wandererfan
Veteran
Posts: 6270
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [SOLVED] A2P cannot import part if there is TechDraw sheet attached

Post by wandererfan »

kbwbe wrote: Thu Jun 11, 2020 9:45 am It seem's, that the ballon object has an attribute 'Shape' with value 'None'. This caused A2p to fail.
Thanks for finding this. I will change the name of Balloon.Shape since it doesn't represent what the rest of FC calls a Shape.
Post Reply