Skip to content

Commit

Permalink
v0.11.2 from Zolko-123/development
Browse files Browse the repository at this point in the history
  • Loading branch information
Zolko-123 authored Oct 8, 2021
2 parents 38b11e1 + 10d8562 commit 758a1ad
Show file tree
Hide file tree
Showing 8 changed files with 749 additions and 403 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ __pycache__/*
*.directory
AnimationLib_translated.py
.gitignore
InfoKeys.py
InfoScript.py
202 changes: 202 additions & 0 deletions InfoKeys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#!/usr/bin/env python3
# coding: utf-8
#
# LGPL
#
# libraries for FreeCAD's Assembly 4 workbench

import os, json

import FreeCAD as App
import infoPartCmd


# Autofilling info ref
partInfo =[ 'LabelDoc', \
'LabelPart', \
'PadLength', \
'ShapeLength']

infoToolTip = {'LabelDoc':'Return the Label of Document','LabelPart':'Return the Label of Part','PadLength':'Return the Length of Pad','ShapeLength':'Return the Length of Shape'}

# protection against update of user configuration
### to have the dir of external configuration file
ConfUserDir = os.path.join(App.getUserAppDataDir(),'Templates')
ConfUserFilename = "Asm4_infoPartConf.json"
ConfUserFilejson = os.path.join(ConfUserDir, ConfUserFilename)


### try to open existing external configuration file of user
try :
file = open(ConfUserFilejson, 'r')
file.close()
### else make the default external configuration file
except :
partInfoDef = dict()
for prop in partInfo:
partInfoDef.setdefault(prop,{'userData':prop + 'User','active':True})
try:
os.mkdir(ConfUserDir)
except:
pass
file = open(ConfUserFilejson, 'x')
json.dump(partInfoDef,file)
file.close()


### now user configuration is :
file = open(ConfUserFilejson, 'r')
infoKeysUser = json.load(file).copy()
file.close()

def infoDefault(self):
### auto filling module
### load infoKeysUser
file = open(ConfUserFilejson, 'r')
infoKeysUser = json.load(file).copy()
file.close()
### part variable creation
try :
self.TypeId
PART=self
except AttributeError:
PART=self.part
### you have PART
DOC=PART.Document
### 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)
"""
how make a new autoinfofield :
ref newautoinfofield name in partInfo[]
make a description in infoToolTip = {}
put newautoinfofield name in infoDefault() at the end with the right arg (PAD,SKETCH...)
write new def like that :
def newautoinfofieldname(self,PART(option : DOC , BODY , PAD , SKETCH):
###you can use DOC - PART - BODY - PAD - SKETCH
auto_info_field = infoKeysUser.get('newautoinfofieldname').get('userData')
auto_info_fill = newautoinfofield information
try:
### if the command comes from makeBom write autoinfo directly on Part
self.TypeId
setattr(PART,auto_info_field,str(auto_info_fill))
except AttributeError:
### if the command comes from infoPartUI write autoinfo on autofilling field on UI
try :
### if field is actived
for i in range(len(self.infoTable)):
if self.infoTable[i][0]== auto_info_field :
self.infos[i].setText(str(auto_info_fill))
except AttributeError:
### if field is not actived
pass
"""

def ShapeLength(self,PART,SKETCH):
###you can use DOC - PART - BODY - PAD - SKETCH
auto_info_field = infoKeysUser.get('ShapeLength').get('userData')
try :
auto_info_fill = SKETCH.Shape.Length
except AttributeError:
return
try:
### if the command comes from makeBom write autoinfo directly on Part
self.TypeId
setattr(PART,auto_info_field,str(auto_info_fill))
except AttributeError:
### if the command comes from infoPartUI write autoinfo on autofilling field on UI
try :
### if field is actived
for i in range(len(self.infoTable)):
if self.infoTable[i][0]== auto_info_field :
self.infos[i].setText(str(auto_info_fill))
except AttributeError:
### if field is not actived
pass


def PadLength(self,PART,PAD):
###you can use DOC - PART - BODY - PAD - SKETCH
auto_info_field = infoKeysUser.get('PadLength').get('userData')
try :
auto_info_fill = PAD.Length
except AttributeError:
return
try:
### if the command comes from makeBom write autoinfo directly on Part
self.TypeId
setattr(PART,auto_info_field,str(auto_info_fill))
except AttributeError:
### if the command comes from infoPartUI write autoinfo on autofilling field on UI
try :
### if field is actived
for i in range(len(self.infoTable)):
if self.infoTable[i][0]== auto_info_field :
self.infos[i].setText(str(auto_info_fill))
except AttributeError:
### if field is not actived
pass



def LabelDoc(self,PART,DOC):
docLabel = infoKeysUser.get('LabelDoc').get('userData')
try:
### if the command comes from makeBom write autoinfo directly on Part
self.TypeId
setattr(PART,docLabel,DOC.Label)
except AttributeError:
### if the command comes from infoPartUI write autoinfo on autofilling field on UI
try :
### if field is actived
for i in range(len(self.infoTable)):
if self.infoTable[i][0]==docLabel:
self.infos[i].setText(DOC.Label)
except AttributeError:
### if field is not actived
pass

def LabelPart(self,PART):
partLabel = infoKeysUser.get('LabelPart').get('userData')
try:
### if the command comes from makeBom write autoinfo directly on Part
self.TypeId
setattr(PART,partLabel,PART.Label)
except AttributeError:
### if the command comes from infoPartUI write autoinfo on autofilling field on UI
try :
### if field is actived
for i in range(len(self.infoTable)):
if self.infoTable[i][0]== partLabel:
self.infos[i].setText(PART.Label)
except AttributeError:
### if field is not actived
pass



pass
23 changes: 0 additions & 23 deletions InfoKeysInit.py

This file was deleted.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FreeCAD Assembly 4 workbench

Current version 0.11.1
Current version 0.11.2



Expand Down Expand Up @@ -52,6 +52,10 @@ You can get more information in the [user instructions](INSTRUCTIONS.md), the [t

## Release notes

* 2021.10.08 (**0.11.2**) :
added "Open File" to insertLink
BOM and infoPart improvements

* 2021.10.01 (**0.11.1**) :
reverted Asm4.QUnitSpinBox() to QtGui.QDoubleSpinBox() because of incompatibilites with some locale (',' comma decimal separators)

Expand Down
3 changes: 2 additions & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Assembly 4 Workbench for FreeCAD
v0.11.1
v0.11.2



Loading

0 comments on commit 758a1ad

Please sign in to comment.