freecad
This is an old revision of the document!
Table of Contents
freecad
Techdraw
Update cartridge
# get time
def getTime():
from datetime import datetime
now = datetime.now()
return now.strftime("%d/%m/%Y %H:%M:%S")
# get author
def getAuthor():
doc = App.ActiveDocument
return doc.CreatedBy.title()
#convert scale
def convertScale(scale):
left = 1
right = 1
if scale > 1:
left = scale
right = 1
elif scale < 1:
left = 1
right = 1 / scale
return str(left)+":"+str(right)
# update values
def updateValues(author, time):
s = FreeCADGui.Selection.getSelection()
if len(s) < 1:
print ("Please select 1 TechDraw Page")
return
for item in s:
#print ("Object in selection is a: ", item.TypeId)
if item.isDerivedFrom("TechDraw::DrawPage"):
for o in item.OutList:
if o.TypeId == "TechDraw::DrawSVGTemplate":
texts = o.EditableTexts.copy()
texts["DRAWING_TITLE"] = item.Label
texts["FC-SC"] = convertScale(item.Scale)
texts["AUTHOR_NAME"] = author
texts["FC-DATE"] = time
o.EditableTexts = texts
return
updateValues(getAuthor(), getTime())
Lighting test
Set Properties
def setLightingProperties():
selection = FreeCADGui.Selection.getSelection()
# stop if none selected
if len(selection) < 1:
App.Console.PrintMessage("Please select devices")
return
# assign properties
for item in selection:
# delete all the "lighting" properties
for prop in item.PropertiesList:
if item.getGroupOfProperty(prop) == "Lighting":
item.removeProperty(prop)
App.Console.PrintMessage("Property "+ prop+ " deleted from "+ item.Label+ "\n")
# fixture type
if not hasattr(item,"Lighting_FixtureType"):
item.addProperty("App::PropertyString", "FixtureType", "Lighting")
# channel
if not hasattr(item,"Lighting_Channel"):
item.addProperty("App::PropertyInteger", "Channel", "Lighting")
# dimmer
if not hasattr(item,"Lighting_Dimmer"):
item.addProperty("App::PropertyInteger", "Dimmer", "Lighting")
# gel
if not hasattr(item,"Lighting_Gel"):
item.addProperty("App::PropertyString", "Gel", "Lighting")
setLightingProperties()
Build sheets
import collections
# get doc
doc = FreeCAD.ActiveDocument
# ====================
# create spreadsheets
# ====================
# fixtures list
if doc.getObjectsByLabel("Fixtures Count"):
doc.removeObject("fixturesCount")
doc.recompute()
App.Console.PrintMessage("Old 'fixtures count' sheet deleted\n")
fixtures_count_sheet = doc.addObject('Spreadsheet::Sheet','fixturesCount')
fixtures_count_sheet.Label = "Fixtures Count"
App.Console.PrintMessage("New 'Fixtures Count' sheet created\n")
# build first line
fixtures_count_sheet.set("A1", "Type")
fixtures_count_sheet.set("B1", "Qty")
fixtures_count_sheet.setStyle('A1:B1', 'bold', 'add')
doc.recompute()
# gels list
if doc.getObjectsByLabel("Gels Count"):
doc.removeObject("gelsCount")
doc.recompute()
App.Console.PrintMessage("Old 'gels count' sheet deleted\n")
gels_count_sheet = doc.addObject('Spreadsheet::Sheet','gelsCount')
gels_count_sheet.Label = "Gels Count"
App.Console.PrintMessage("New 'Gels Count' sheet created\n")
# build first line
gels_count_sheet.set("A1", "Type")
gels_count_sheet.set("B1", "Qty")
gels_count_sheet.setStyle('A1:B1', 'bold', 'add')
doc.recompute()
# fixtures list by channel
if doc.getObjectsByLabel("Fixtures List By Channel"):
doc.removeObject("fixturesListByChannel")
doc.recompute()
App.Console.PrintMessage("Old 'fixtures list by channel' sheet deleted\n")
fixtures_list_by_channel_sheet = doc.addObject('Spreadsheet::Sheet','fixturesListByChannel')
fixtures_list_by_channel_sheet.Label = "Fixtures List By Channel"
App.Console.PrintMessage("New 'Fixtures List By Channel' sheet created\n")
# build first line
fixtures_list_by_channel_sheet.set("A1", "Channel")
fixtures_list_by_channel_sheet.set("B1", "Dimmer")
fixtures_list_by_channel_sheet.set("C1", "Type")
fixtures_list_by_channel_sheet.set("D1", "Gel")
fixtures_list_by_channel_sheet.set("E1", "Label")
fixtures_list_by_channel_sheet.setStyle('A1:E1', 'bold', 'add')
doc.recompute()
# fixtures list by dimmer
if doc.getObjectsByLabel("Fixtures List By Dimmer"):
doc.removeObject("fixturesListByDimmer")
doc.recompute()
App.Console.PrintMessage("Old 'fixtures list by dimmer' sheet deleted\n")
fixtures_list_by_dimmer_sheet = doc.addObject('Spreadsheet::Sheet','fixturesListByDimmer')
fixtures_list_by_dimmer_sheet.Label = "Fixtures List By Dimmer"
App.Console.PrintMessage("New 'Fixtures List By Dimmer' sheet created\n")
# build first line
fixtures_list_by_dimmer_sheet.set("A1", "Dimmer")
fixtures_list_by_dimmer_sheet.set("B1", "Channel")
fixtures_list_by_dimmer_sheet.set("C1", "Type")
fixtures_list_by_dimmer_sheet.set("D1", "Gel")
fixtures_list_by_dimmer_sheet.set("E1", "Label")
fixtures_list_by_dimmer_sheet.setStyle('A1:E1', 'bold', 'add')
doc.recompute()
# ====================
# parse objects
# ====================
objs = FreeCAD.ActiveDocument.Objects
#App.Console.PrintMessage(str(objs) + "\n")
# fill the devices list
fixtures_types_count = {}
gels_types_count = {}
fixtures_list_by_channel = {}
fixtures_list_by_dimmer = {}
for obj in objs:
if obj.isDerivedFrom("Part::Part2DObject"):
if hasattr(obj,"FixtureType"):
# get properties
fixture_type = obj.getPropertyByName("FixtureType")
fixture_gel = obj.getPropertyByName("Gel")
fixture_channel = obj.getPropertyByName("Channel")
fixture_dimmer = obj.getPropertyByName("Dimmer")
# fill the devices count
if fixture_type not in fixtures_types_count:
fixtures_types_count[fixture_type] = 0
fixtures_types_count[fixture_type] += 1
# fill the gels count
if fixture_gel not in gels_types_count:
gels_types_count[fixture_gel] = 0
gels_types_count[fixture_gel] += 1
# fill the list by channel
if not fixture_channel in fixtures_list_by_channel:
fixtures_list_by_channel[fixture_channel] = []
fixtures_list_by_channel[fixture_channel].append(obj)
# fill the list by dimmer
if not fixture_dimmer in fixtures_list_by_dimmer:
fixtures_list_by_dimmer[fixture_dimmer] = []
fixtures_list_by_dimmer[fixture_dimmer].append(obj)
#App.Console.PrintMessage(str(fixtures_types_count)+"\n")
#App.Console.PrintMessage(str(gels_types_count)+"\n")
#App.Console.PrintMessage(str(fixtures_list_by_channel)+"\n")
#App.Console.PrintMessage(str(fixtures_list_by_dimmer)+"\n")
# order by key
fixtures_types_count = collections.OrderedDict(sorted(fixtures_types_count.items()))
gels_types_count = collections.OrderedDict(sorted(gels_types_count.items()))
fixtures_list_by_channel = collections.OrderedDict(sorted(fixtures_list_by_channel.items()))
fixtures_list_by_dimmer = collections.OrderedDict(sorted(fixtures_list_by_dimmer.items()))
# ==============================
# fill the fixtures count sheet
# ==============================
cell_idx = 2
for fixt, qty in fixtures_types_count.items():
type_cell = "A"+ str(cell_idx)
qty_cell = "B"+ str(cell_idx)
fixtures_count_sheet.set(type_cell, fixt)
fixtures_count_sheet.set(qty_cell, str(qty))
cell_idx += 1
# ==============================
# fill the gels count sheet
# ==============================
cell_idx = 2
for gel, qty in gels_types_count.items():
type_cell = "A"+ str(cell_idx)
qty_cell = "B"+ str(cell_idx)
gels_count_sheet.set(type_cell, gel)
gels_count_sheet.set(qty_cell, str(qty))
cell_idx += 1
# ==================================
# fill the fixtures list by channel
# ==================================
cell_idx = 2
for k,v in fixtures_list_by_channel.items():
for fixture in fixtures_list_by_channel[k]:
channel_cell = "A"+ str(cell_idx)
dimmer_cell = "B"+ str(cell_idx)
type_cell = "C"+ str(cell_idx)
gel_cell = "D"+ str(cell_idx)
label_cell = "E"+ str(cell_idx)
fixtures_list_by_channel_sheet.set(channel_cell, str(fixture.getPropertyByName("Channel")))
fixtures_list_by_channel_sheet.set(dimmer_cell, str(fixture.getPropertyByName("Dimmer")))
fixtures_list_by_channel_sheet.set(type_cell, fixture.getPropertyByName("Gel"))
fixtures_list_by_channel_sheet.set(gel_cell, fixture.getPropertyByName("FixtureType"))
fixtures_list_by_channel_sheet.set(label_cell, fixture.Label)
cell_idx += 1
# ==================================
# fill the fixtures list by dimmer
# ==================================
cell_idx = 2
for k,v in fixtures_list_by_dimmer.items():
for fixture in fixtures_list_by_dimmer[k]:
dimmer_cell = "A"+ str(cell_idx)
channel_cell = "B"+ str(cell_idx)
type_cell = "C"+ str(cell_idx)
gel_cell = "D"+ str(cell_idx)
label_cell = "E"+ str(cell_idx)
fixtures_list_by_dimmer_sheet.set(dimmer_cell, str(fixture.getPropertyByName("Dimmer")))
fixtures_list_by_dimmer_sheet.set(channel_cell, str(fixture.getPropertyByName("Channel")))
fixtures_list_by_dimmer_sheet.set(type_cell, fixture.getPropertyByName("Gel"))
fixtures_list_by_dimmer_sheet.set(gel_cell, fixture.getPropertyByName("FixtureType"))
fixtures_list_by_dimmer_sheet.set(label_cell, fixture.Label)
cell_idx += 1
doc.recompute()
freecad.1694527554.txt.gz · Last modified: by ssm2017
