Getting access to a sheets Title block using python - revit-api

Dynamo Script
Within Dynamo I was able to adjust the title block per sheet but I was requested to simplify it into a button click using python only.
I can find the sheets but I can not adjust the parameters per sheet. I believe this is because the parameter I am trying to toggle on and off is located within the Titleblock and not on the sheet it self. I thought maybe I would need to unwrap these but I could not get the function to work outside of Dynamo. Any help would be appreciated.
sheet_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets) \
.WhereElementIsNotElementType() \
.ToElements()
for sheet in sheet_collector:
print(sheet.Name)
The snippet above is how I am sourcing all the sheets and I have been able to find everyone but when searching for the custome parameter, it comes up nil.

To get the FamilyInstance of the title block you can use this:
var titleBlockFamInst = new FilteredElementCollector(doc, viewSheetId).OfCategory(BuiltInCategory.OST_TitleBlocks).FirstElement() as FamilyInstance;

Related

How to make partial changes in attribute table without missing with the whole data?

I want to change some letters in attribute table of the image below, for example: change code from "PK705" to "NA705". SO what I mean is changing the first two letters without missing with the code numbers of the the rest of attribute table.
Any suggested trick for the solution, it would be appreciated.
Attribute table image
Suppose you have already got the list of the attributes value
adm2_pcode = ['PK631','PK632','PK816','PK614','PK219','PK620','PK705','PK613','PK611','PK601','PK235']
Use str.replace(old, new ) to change it:
adm2_pcode = [adm2_pcode[i].replace('PK','NA') for i in range(len(adm2_pcode))]

Office Script Excel Pivot Table Count Instead of Sum

I'm using Office Script to generate a pivot table and that works. However, for my data hierarchy, I need "count" instead of the default "sum". How do I go about doing that?
I'm adding a hierarchy using the following - this works but summarizes by "sum"
pivotTable.addRowHierarchy(pivotTable.getHierarchy("Company"));
pivotTable.addDataHierarchy(pivotTable.getHierarchy("Unit ID"));
From the script reference page, I need to somehow embed the count function into the above snippet. Does anyone know how to do that? I tried "Record Actions", but it wasn't able to catch the switch from "sum" to "count".
Thanks a lot
Figured it out - to change the summarize function, we need to chain the aggregate function to the end of addDataHierarchy.
The second line in the previous example therefore becomes:
pivotTable.addDataHierarchy(pivotTable.getHierarchy("Unit ID")).setSummarizeBy(ExcelScript.AggregationFunction.count);
For more details refer to setSummarizeBy(summarizeBy).

Google Sheets Script, how to create a NEW loose object of a sheet tab

I can't find the answer but it might be that I'm looking for the wrong things.
I got a sheet that got tabs for every letter in the alphabet and those includes data beginning
on that letter. I now want to copy those line into a summary sheet but before I just copy it
I need to remove the first line from every tab as that is the heading, the heading should not
appear over and over down all the lines in the new summary tab.
If I just do a variable of a tab and remove the first line, like:
var sheets = ss.getSheetByName(tabs[i]);, this will reflect into the tab itself
and that is wrong as the heading is now gone in that tab and that I can understand as it is not
a new object but a referencing variable.
I tried to create a new object like: var sheets = new Object(ss.getSheetByName(tabs[i]));
and then change that figuring it wouldn't touch the tab itself as this is now not a reference object
but it seems it is, as changing the 'sheets' variable still changes the original data in that tab.
I hope that makes it clear.
How can I create a new object of that tab and is NOT a reference but a COPY of it so I can do
whatever I want to that object without changing the original data in the tab it came from.
Perhaps something like this might work:
function summaryAZ() {
const sA=['A','B','C'];//etc
const ss=SpreadsheetApp.getActive();
const sumsh=ss.getSheetByName('Summary')
sumsh.getRange(2,1,sumsh.getLastRow()-1,sumsh.getLastColumn()).clearContent();//clear everything except header row
sA.forEach((n,i)=>{
let sh=ss.getSheetByName(n);
let [hA, ...data]=sh.getDataRange();
sumsh.getRange(sumsh.getLastRow()+1,1,data.length,data[0].length).setValues(data);
});
}

Referencing a dynamic name in PowerQuery results in an error

I have created a new name (variable) in excel using the Name Manager which is called fPath. The value for the name is =CELL("filename").
I would like to reference this name as a parameter to the source within a function query. But, when I try to invoke the function within the Power Query Editor, I get an error that it wasn't able to find the name.
When the name refers to a cell within the sheet, this works perfectly but when a name is created without a reference to a cell, it is unable to find it.
Am I correct in assuming that what I'm trying to do is not possible?
EDIT:
Here's the code for for the Function Query where I have defined a parameter which is then used to dynamically get the source of the file.
[]
Please see this from Ken Puls
https://www.excelguru.ca/blog/2014/11/26/building-a-parameter-table-for-power-query/
Try this:
= Excel.CurrentWorkbook(){[Name="fPath"]}[Content]
Or:
= Excel.Workbook(File.Contents("C:\YourFile.xlsx"), null, true){[Item="fPath",Kind="DefinedName"]}[Data]

google spreadsheet script - how to get the reference to a specific block inside method

I am currently trying to fill a block with a int from a method that I wrote with the script editor.
And ofcourse I know I can just left click a block and type the number in, but I need to do more than that.
I have no experience in java script, but I code in JAVA, so I could understand a lot of it.
I have the following code inside my method:
var sheet = SpreadsheetApp.getActiveSpreadsheet();
sheet[5][15] = 60 ; // I have stripe down almost everything to where my problem occurred
I am trying to fill row 5, column O with 60. But it isn't working.
I tried sheet[5][O] = 60; but this doesn't work neither.
So how can I refer to the location 5,O on the sheet and give it a value?
sheet.getRange("O5").setValue(60);
or
sheet.getRange(5, 15).setValue(60);

Resources