local variable 'PAD' referenced before assignment

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Ningrich3
Posts: 12
Joined: Mon Jul 18, 2022 4:18 am

local variable 'PAD' referenced before assignment

Post by Ningrich3 »

My intention is to recursively create a very primitive complete list of all the components in my assembly, no matter if csv, tsv, xml, xls, ...

When trying to create such a BOM by using the Assembly 4 Create Part List function I receive an error message that always says:
"local variable 'PAD' referenced before assignment"
Trying to add part info by using the Assembly 4 Edit Part Information functionality will throw the same error.

To find out more about the issue I have tried to create part info and generate a BOM by using small test assemblies and single parts but I always fail and receive the above mentioned error alert.

My research online and in the forum brought no useful findings on the concern.

The problem is related to the FreeCAD\Mod\Assembly4\InfoKeys.py:

Code: Select all

### you have DOC
    ### research
    for i in range(len(PART.Group)):
        if PART.Group[i].TypeId == 'PartDesign::Body' :
            BODY=PART.Group[i]
            ### you have BODY
            for i in range(len(BODY.Group)):
                if BODY.Group[i].TypeId == 'PartDesign::Pad' :
                    PAD=BODY.Group[i]
                    ### you have PAD
                    try :
                        SKETCH=PAD.Profile[0]
                        ### you have SKETCH
                    except NameError :
                        print('there is no Sketch on a Pad of : ',PART.FullName )

    ### start all autoinfofield
    LabelDoc(self,PART,DOC)
    LabelPart(self,PART)
    PadLength(self,PART,PAD)
    ShapeLength(self,PART,SKETCH)
Here the PAD variable is assigned only under the condition that

Code: Select all

BODY.Group[i].TypeId == 'PartDesign::Pad'

is TRUE. Later the variable is used even if not initialized.

Can someone help? Thank you!
Last edited by Ningrich3 on Mon Jul 18, 2022 9:09 am, edited 1 time in total.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: local variable 'PAD' referenced before assignment

Post by openBrain »

Moved to Assembly
Ping @Zolko
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: local variable 'PAD' referenced before assignment

Post by Zolko »

Ningrich3 wrote: Mon Jul 18, 2022 7:53 am My intention is to recursively create a very primitive complete list of all the components in my assembly, no matter if csv, tsv, xml, xls, ...
...
Can someone help? Thank you!
unfortunately, the BOM function is broken currently (it was implemented by several people each looking for his own special neds, and nobody could yet come up with a general solution).

If you have the time and knowledge to make a generic PartInfo and BoM functionality, that would be very welcome. The general idea would be to have default InfoPart keywords, and be able to add/remove keys on-demand, both to the PartInfo and BoM, and if possible to store user-defined values in a JSON config file.
try the Assembly4 workbench for FreCAD — tutorials here and here
Ningrich3
Posts: 12
Joined: Mon Jul 18, 2022 4:18 am

Re: local variable 'PAD' referenced before assignment

Post by Ningrich3 »

Thank you very much for your super fast response!

I was considering to implement a solution myself, but currently my python knowledge is very limited and since this project's time is running out I'll first extract the components and their quantities manually.
Post Reply