Arch Structure / Draft Edit / and possible bug

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Arch Structure / Draft Edit / and possible bug

Post by carlopav »

Found a possible bug:
- start new document
- create an arch structure
- set Show Nodes property to True
- i get this error:

Code: Select all

Traceback (most recent call last):
  File "C:\Users\Carlo\Desktop\FreeCAD_0.19.17803_x64_LP_12.1.2_PY3QT5-WinVS2015\Mod\Arch\ArchStructure.py", line 1005, in onChanged
    self.updateData(vobj.Object,"Nodes")
  File "C:\Users\Carlo\Desktop\FreeCAD_0.19.17803_x64_LP_12.1.2_PY3QT5-WinVS2015\Mod\Arch\ArchStructure.py", line 950, in updateData
    self.lineset.coordIndex.setValues(0,len(p)+1,range(len(p))+[-1])
<class 'TypeError'>: unsupported operand type(s) for +: 'range' and 'list'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
<class 'AttributeError'>: Attribute (Name: ShowNodes) error: 'unsupported operand type(s) for +: 'range' and 'list'' 
Stack Trace: Traceback (most recent call last):
  File "<string>", line 1, in <module>
Also reset nodes have some problems.

Also i was thinking: arch structure uses draft edit to change nodes position. Would it be good to be able to use DrafEdit also to change height /length of the element and position/rotation? maybe I could add a switch between the two modes.

Code: Select all

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.17803 (Git)
Build type: Release
Branch: master
Hash: 89961a33d46063a43e9fb5b0308ca95d559eca94
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Italian/Italy (it_IT)
follow my experiments on BIM modelling for architecture design
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Arch Structure / Draft Edit / and possible bug

Post by vocx »

carlopav wrote: Sat Aug 24, 2019 1:26 pm

Code: Select all

    self.lineset.coordIndex.setValues(0,len(p)+1,range(len(p))+[-1])
<class 'TypeError'>: unsupported operand type(s) for +: 'range' and 'list'
As I understand the error the third argument is invalid

Code: Select all

range(len(p))+[-1]
The function range() returns a list in Python 2, but in Python 3 it returns an iterator. An iterator cannot be added to a list. First the iterator needs to be converted to a list.

Maybe this is enough

Code: Select all

list(range(len(p)))+[-1]
This would add two lists together, which would solve the syntax error. This is all without considering that the lists are used as intended.

Also, here there should be a test to use one syntax for Python 2 and another for Python 3, if compatibility with the former is desired.

Code: Select all

if Py2:
    range(len(p))+[-1]
elif Py3:
    list(range(len(p)))+[-1]
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Arch Structure / Draft Edit / and possible bug

Post by carlopav »

Thanks @Vox for looking into this.

Code: Select all

list(range(len(p)))+[-1]
This works perfectly. The ArchStructure.py is huge!
Reset Nodes still provoke an error:

Code: Select all

Traceback (most recent call last):
  File "C:\Users\Carlo\Desktop\FreeCAD_0.19.17803_x64_LP_12.1.2_PY3QT5-WinVS2015\Mod\Arch\ArchStructure.py", line 1096, in resetNodes
    self.Object.Proxy.onChanged(self.Object,"ResetNodes")
  File "C:\Users\Carlo\Desktop\FreeCAD_0.19.17803_x64_LP_12.1.2_PY3QT5-WinVS2015\Mod\Arch\ArchStructure.py", line 875, in onChanged
    ArchComponent.Component.onChanged(self,obj,prop)
  File "C:\Users\Carlo\Desktop\FreeCAD_0.19.17803_x64_LP_12.1.2_PY3QT5-WinVS2015\Mod\Arch\ArchComponent.py", line 223, in onChanged
    ArchIFC.IfcProduct.onChanged(self, obj, prop)
  File "C:\Users\Carlo\Desktop\FreeCAD_0.19.17803_x64_LP_12.1.2_PY3QT5-WinVS2015\Mod\Arch\ArchIFC.py", line 33, in onChanged
    if obj.getGroupOfProperty(prop) == "IFC Attributes":
AttributeError: Property container has no property 'ResetNodes'
follow my experiments on BIM modelling for architecture design
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Arch Structure / Draft Edit / and possible bug

Post by yorik »

Thanks for the debugging guys. Both issues solved in git commit 3dac114f9f
Indeed since python3, range is not a list anymore but an iterable. It cannot be added to a list...
But since range() produced a list anyway in python2, it's safe to use list(range()) in all cases.

The other error is because ArchStructure produces a fake onChanged("ResetNodes") to trigger a change, (ResetNodes isn't a property,it's a bad hack I know :oops: ) but ArchIFC wasn't checking properly...
Post Reply