====== freecad ====== ===== blender 3 to freecad 19 ===== blender : obj include : selection only onjects as onj objects transform : scale 1000 forward y forward up z up geometry : triangulate faces freecad : file / import alias mesh = 1 object wavefront obj = multiple objects select all part workbench : menu part / create shape from mesh tolerance : 0.10 delete selection select all menu part / create a copy / refine shape select copied menu part / convert to solid delete others ====== 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 # ==================== def deleteSheets(): sheets = {"fixturesCount":"Fixtures Count", "gelsCount": "Gels Count", "fixturesListByChannel": "Fixtures List By Channel", "fixturesListByDimmer": "Fixtures List By Dimmer"} # delete old spreadsheets for sheet_name, sheet_label in sheets.items(): if doc.getObject(sheet_name): doc.removeObject(sheet_name) App.Console.PrintMessage("Old "+ sheet_name+ " sheeet deleted\n") doc.recompute() # fixtures list fixtures_count_sheet = doc.getObject('fixturesCountSheet') if not fixtures_count_sheet: fixtures_count_sheet = doc.addObject('Spreadsheet::Sheet','fixturesCountSheet') fixtures_count_sheet.Label = "Fixtures Count" App.Console.PrintMessage("New 'Fixtures Count' sheet created\n") # empty the sheet fixtures_count_sheet.clearAll() # 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 gels_count_sheet = doc.getObject('gelsCountSheet') if not gels_count_sheet: gels_count_sheet = doc.addObject('Spreadsheet::Sheet','gelsCountSheet') gels_count_sheet.Label = "Gels Count" App.Console.PrintMessage("New 'Gels Count' sheet created\n") # empty the sheet gels_count_sheet.clearAll() # 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 fixtures_list_by_channel_sheet = doc.getObject('fixturesListByChannelSheet') if not fixtures_list_by_channel_sheet: fixtures_list_by_channel_sheet = doc.addObject('Spreadsheet::Sheet','fixturesListByChannelSheet') fixtures_list_by_channel_sheet.Label = "Fixtures List By Channel" App.Console.PrintMessage("New 'Fixtures List By Channel' sheet created\n") # empty the sheet fixtures_list_by_channel_sheet.clearAll() # 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 fixtures_list_by_dimmer_sheet = doc.getObject('fixturesListByDimmerSheet') if not fixtures_list_by_dimmer_sheet: fixtures_list_by_dimmer_sheet = doc.addObject('Spreadsheet::Sheet','fixturesListByDimmerSheet') fixtures_list_by_dimmer_sheet.Label = "Fixtures List By Dimmer" App.Console.PrintMessage("New 'Fixtures List By Dimmer' sheet created\n") # empty the sheet fixtures_list_by_dimmer_sheet.clearAll() # 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() {{tag>freecad python}}