Merge pull request #435 from Francisco-Rosa/master

Add updated parametric components.
This commit is contained in:
Yorik van Havre 2025-02-06 09:55:59 +01:00 committed by GitHub
commit 8a6a19e1bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 301 additions and 0 deletions

View file

@ -0,0 +1,115 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#***************************************************************************
#* *
#* Copyright (c) 2024 Francisco Rosa *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
# Macro get model +++++++++++++++++++++++++++++++++++++++++++++++++
import FreeCAD
import FreeCADGui as Gui
import Spreadsheet
# ----------------------------------------------------------------------
## GET MODEL FROM SPREADSHEET
# ----------------------------------------------------------------------
name = "None"
value = None
cellName = "None"
cellRows = []
cellValue = "None"
obj = "None"
propertyType = None
propName = "None"
objects = []
column = None
SpreadsheetModels = None
propertyRows = {}
# Get the property name with the initial information
propName = input("Confirme the name of the properties set or VarSet wich Label is 'Initial_information' (Ex.: Prop, Prop001, Prop002...or Varset, Varset001, Varset002...)")
if not FreeCAD.ActiveDocument.getObject(propName):
print(str(propName) + " is not correct!" + "\n")
# Get the spreadsheet name for saving model
SpreadsheetModels = FreeCAD.ActiveDocument.getObject(propName).A_Spreadsheet_models
objects = FreeCAD.ActiveDocument.getObject(propName).L_Property_objects_list
CellRows_Lists = []
CellRows_Lists = objects[0].L_Props_list
# propertyRows
for i in range(len(objects)):
propertyRows [objects[i].Name] = objects[0].getPropertyByName(CellRows_Lists[i])
# 2. Get properties
def getComponentModel(column = "None", objects = None, propertyRows = None, SpreadsheetModels = None):
for i in range(len(objects)):
# Prop, Prop001, ...or VarSet, Varset001...
obj = objects[i]
cellRows = propertyRows[obj.Name]
for n in range(len(cellRows)):
cellValue = column + cellRows[n]
value = str(SpreadsheetModels.get(cellValue))
if value == "Not used":
continue
cellName = "A" + cellRows[n]
name = SpreadsheetModels.get(cellName)
propertyType = obj.getTypeIdOfProperty(name)
if propertyType == "App::PropertyBool":
value = str(SpreadsheetModels.get(cellValue))
if value == "True":
value = 1
else:
value = 0
setattr(obj, name, value)
continue
if propertyType == "App::PropertyInteger":
value = SpreadsheetModels.get(cellValue)
setattr(obj, name, value)
continue
setattr(obj, name, value)
App.ActiveDocument.recompute()
# 1. Models spreadsheet - get model column
# Condition to get model
if objects[0].B_Confirm_model == True:
objects = FreeCAD.ActiveDocument.getObject(propName).L_Property_objects_list
column = objects[0].A_Model_name[0]
getComponentModel(column, objects, propertyRows, SpreadsheetModels)
objects[0].B_Confirm_model = False
App.ActiveDocument.recompute()
# Select the Prop or VarSet
Gui.Selection.clearSelection()
Gui.Selection.addSelection(SpreadsheetModels)
Gui.Selection.clearSelection()
Gui.Selection.addSelection(objects[0])
App.ActiveDocument.recompute()
else:
print("First you must choose or confirm the model name in 'Prop_General_configurations or Varset_General_configurations > I1-Get model configurations'> A_Model_name', then choose 'true' in 'B_Confirm_model!")
#-----------------------------------------------------------------------

View file

@ -0,0 +1,181 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#***************************************************************************
#* *
#* Copyright (c) 2024 Francisco Rosa *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
# Macro Save models +++++++++++++++++++++++++++++++++++++++++++++++++
import FreeCAD
import FreeCADGui as Gui
import Spreadsheet
# ----------------------------------------------------------------------
## SAVE MODEL FROM PROPERTIES TO SPREADSHEET
# ----------------------------------------------------------------------
# 2. Get and save properties
# 2.1. Organize the properties
name = "None"
value = "None"
obj = None
group = "None"
group1 = "None"
group2 = "None"
propName = 'None'
objects = []
SpreadsheetModels = None
# Get the property name with the initial information
propName = input("Confirme the name of the properties set or VarSet wich Label is 'Initial_information' (Ex.: Prop, Prop001, Prop002... or VarSet, VarSet001, VarSet002...)")
if not FreeCAD.ActiveDocument.getObject(propName):
print(str(propName) + " is not correct!" + "\n")
# Get the spreadsheet name for saving model
SpreadsheetModels = FreeCAD.ActiveDocument.getObject(propName).A_Spreadsheet_models
# objects = [Prop, Prop001, ...]
objects = FreeCAD.ActiveDocument.getObject(propName).L_Property_objects_list
def saveComponentModel(column = "None", objects = None, SpreadsheetModels = None):
groupAnt = "None"
cellName = "None"
cellValue = "None"
N = 0
T = 0
cellNumber = 0
cellValue = column + str(1)
SpreadsheetModels.setBackground(cellValue, (0.666667,0.666667,0.000000))
for i in range(len(objects)):
# Prop, Prop001, ...
obj = objects[i]
name = "Label"
value = obj.getPropertyByName(name)
# Prop to SpreadsheetModels:
cellValue = column + str(3 + T)
SpreadsheetModels.set(cellValue, value)
SpreadsheetModels.setStyle(cellValue, 'bold', 'add')
SpreadsheetModels.setBackground(cellValue, (0.666667,0.666667,0.000000))
App.ActiveDocument.recompute()
N += 1
T += 1
App.ActiveDocument.recompute()
# End save Prop to SpreadsheetModels
propertyNames = []
propertyNames = obj.PropertiesList
groups = []
# groups = sorted(groups)
for n in range(len(propertyNames)):
name = propertyNames[n]
group = obj.getGroupOfProperty(name)
if group not in ("", "Base"):
if group != groupAnt and group not in groups:
groups.append(group)
groups = sorted(groups)
# Save properties
for i in range(len(groups)):
group2 = groups[i]
cellValue = column + str(3 + T)
# group background
SpreadsheetModels.setBackground(cellValue, (0.666667,0.666667,0.000000))
App.ActiveDocument.recompute()
N += 1
T += 1
counter = 0
# Save value properties by group
for n in range(len(propertyNames)):
name = propertyNames[n]
group1 = obj.getGroupOfProperty(name)
value = obj.getPropertyByName(name)
propertyType = None
propertyType = obj.getTypeIdOfProperty(name)
if group1 == group2 and name[0] != "D" and propertyType not in ('App::PropertyLink', 'App::PropertyLinkList', 'App::PropertyStringList'):
# Property to SpreadsheetModels
cellValue = column + str(3 + T)
if obj.Visibility == False:
value = "Not used"
SpreadsheetModels.set(cellValue, value)
SpreadsheetModels.setForeground(cellValue, (0.501961,0.501961,0.501961))
else:
value = str(obj.getPropertyByName(name))
SpreadsheetModels.set(cellValue, value)
N += 1
T += 1
counter += 1
App.ActiveDocument.recompute()
# Delete group is no usefull data
if counter == 0:
N -= 1
T -= 1
cells = "None"
cells = column + str(2) + ":" + column + str(2000)
SpreadsheetModels.setAlignment(cells, 'center', 'keep')
SpreadsheetModels.setAlignment(cells, 'vcenter', 'keep')
App.ActiveDocument.recompute()
T = N
T += 1
# 3. Include the model name in the list of options.
obj = None
listModels = []
modelName = "None"
obj = objects[0]
modelName = column + " - " + nameTitle + " " + obj.A_General_label
listModels = obj.A_Model_list
listModels.append(modelName)
obj.A_Model_list = listModels
obj.A_Model_name = [f for f in obj.A_Model_list]
App.ActiveDocument.recompute()
# 1. Models spreadsheet - create model title
nameTitle = "None"
cellTitle = "None"
column = None
# Condition to save the model
if objects[0].B_Confirm_values == True:
column = objects[0].A_New_model_column_spreadsheet
cellTitle = column + str(2)
nameTitle = objects[0].A_New_model_name
SpreadsheetModels.set(cellTitle, nameTitle)
App.ActiveDocument.recompute()
SpreadsheetModels.setStyle(cellTitle, 'bold', 'add')
App.ActiveDocument.recompute()
objects[0].B_Confirm_values = False
saveComponentModel(column, objects, SpreadsheetModels)
# Select the SpreadsheetModels
Gui.Selection.clearSelection()
Gui.Selection.addSelection(SpreadsheetModels)
App.ActiveDocument.recompute()
else:
print("First you must write or confirm the spreadsheet column in 'Prop_General_configurations or VarSet_General_configurations> I2_Save_new_model'> A_New_model_column_spreadsheet', the model name in 'A_New_model_name', then choose 'true' in 'B_Confirm_values!")
# ------------------------------------------------------------------------------------------------

View file

@ -1,3 +1,7 @@
Playlist:
https://www.youtube.com/playlist?list=PLz-Uxf3mM5LWEMvdHpE3kUsUZo3kSFFjQ
Doors_Windows_module_01:
https://www.youtube.com/watch?v=CqzIvkohvYA

Binary file not shown.

1
Topography/Terrain.txt Normal file
View file

@ -0,0 +1 @@
https://forum.freecad.org/viewtopic.php?p=803014#p803014