I have some code and i want to create Property Note
var metric as EA.Element;
metric = thePackage.Elements.AddNew("", "Text");
What i should put instead of Text to add what i want?
I tried:
metric = thePackage.Elements.AddNew(text, "Property Note");
or
metric = thePackage.Elements.AddNew(text, "PropertyNote");
Edit:
metric = thePackage.Elements.AddNew(text, "Note");
does not work:
I am expecting
in the red box, not the element above it.
Answer:
metric = thePackage.Elements.AddNew("", "Text"); // the Note Property
metric.SubType = 18; // This will actually make a simple Text behave as Note Property
As promised here's the code to create a Diagram Note. Sorry for the Perl, but you'll likely be able to translate this to Javascript.
my $p = $rep->GetPackageByGUID("{157B01A5-8F9A-4458-8C7F-E48F5DA77B0A}"); # sample package
my $dnote = $p->Elements->AddNew("", "Text"); # the Note Property
$dnote->{SubType} = 18; # This will actually make a simple Text behave as Note Property
$dnote->Update(); # save in package elements
my $dia = $p->Diagrams->GetAt(0); # sample diagram
my $do = $dia->DiagramObjects->AddNew("l=10;r=110;t=-20;b=-80", ""); # place Note Property in diagram (coordinates are about top left)
$do->{ElementID} = $dnote->ElementID; # link with the Note Property
$do->Update(); # place in diagram
$rep->ReloadDiagram($dia->DiagramID); # make ir appear instantly
Related
I'm writing a macro with libreoffice basic to modify the styles and size of a selected (and only selected) chart in my spreadsheets.
After many documentation reading and many tries, I managed to have a partial solution to my problem:
Modifying all charts style
I managed to select a chart by it's indexe and modify it's styles with this macro:
Sub ModifyChart
Dim oDoc As Object
Dim oChart As Object
Dim aSize as new com.sun.star.awt.Size
oSheet = ThisComponent.sheets(0)
oCharts = oSheet.getCharts()
oChart = oCharts.getByIndex(0).getEmbeddedObject()
MsgBox oChart.ImplementationName
oChart.Title.String = "My title"
oChart.Title.CharColor = RGB(0,0,200)
oChart.Title.CharFontName = "Arial"
oChart.Title.CharHeight = 16
oChart.SubTitle.String = "My subtitle"
oChart.SubTitle.CharColor = RGB(0,0,200)
oChart.SubTitle.CharFontName = "Arial"
oChart.SubTitle.CharHeight = 12
oChart.Diagram.Wall.FillStyle = com.sun.star.drawing.FillStyle.SOLID
oChart.Diagram.Wall.FillColor = RGB(200,50,150)
oChart.Area.FillStyle = com.sun.star.drawing.FillStyle.SOLID
oChart.Area.FillColor = RGB(100,50,250)
aSize.Width=640
aSize.Height=400
oChart.setsize(aSize) ' Error occur at this point
End Sub
Problem: It's doesn't work with the selected chart and I can't resize it. The method setsize doesn't work for this kind of object. I tryed to get the parent object of the chart ( frame ? or shape ?) without success.
With ImplementationName, I found that the object is a com.sun.star.comp.sc.scshapeobj
Modifying the selected chart size
I managed to modify the selected chart size by using this macro
Sub ResizeChart
Dim oCurrSel As Object
Dim oItem As Object
Dim aSize As New com.sun.star.awt.Size
oCurrSel = ThisComponent.getCurrentSelection()
oItem = oCurrSel.getByIndex(0)
MsgBox oItem.ImplementationName
aSize.width=16000
aSize.height=12000
oItem.setsize(aSize)
End Sub
Problem: I can't access to the other styles of the chart. I tryed to find a method to get the object content without success. I also tryed to investigate the object with oItem.dbg_properties and oItem.dbg_methods but I didn't found anything useful.
With ImplementationName, I found that the object is a com.sun.star.comp.chart2.chartmodel
I have a look to the libreoffice api but I didn't find how these two kind of object are connected.
Is it possible to make what I want with libreoffice basic ?
Does anyone could explain me the hierachical structure of a libreoffice chart object (parents, childs, ...) and how to deal with it ?
Yes, you are absolutely right - parsing the current selection is not a trivial task.
Since the current selection may contain a variety of objects - Cell, CellRange, SheetCellRanges, Shapes, ShapeCollection, GraphicObjectShape and even in some cases just Text, parsing becomes similar to the game "Miner" - each next step requires additional checks (or error handling " blindly "with the help On Error Resume Next)
Your idea of using ImplementationName to identify objects is generally good. But Andrew Pitonyak in 4.1. Debugging And Inspecting Macros wrote "To determine the document type, look at the services it supports ... I assume that this is safer than using getImplementationName()" and I tend to believe him.
The transition from the current selection to the embedded chart can be something like this:
Sub ModifyChartInCurrentSelection
Dim oCurrentSelection As Variant
Dim i As Long
Dim oNextElementOfSelection As Variant
Dim oEmbeddedObject As Variant
Dim oComponent As Variant
Dim aSize As New com.sun.star.awt.Size
oCurrentSelection = ThisComponent.getCurrentSelection()
If oCurrentSelection.supportsService("com.sun.star.drawing.ShapeCollection") Then
For i = 0 To oCurrentSelection.getCount()-1
oNextElementOfSelection = oCurrentSelection.getByIndex(i)
If oNextElementOfSelection.supportsService("com.sun.star.drawing.OLE2Shape") Then
Rem Size of shape (outer wrapper around the chart)
If oNextElementOfSelection.supportsService("com.sun.star.drawing.Shape") Then
aSize = oNextElementOfSelection.getSize()
aSize.Height = aSize.Height * 2 ' or any other
aSize.Width = aSize.Width / 2
oNextElementOfSelection.setSize(aSize)
EndIf
Rem Properties of EmbeddedObject
oEmbeddedObject = oNextElementOfSelection.EmbeddedObject
If Not IsEmpty(oEmbeddedObject) Then
oComponent = oEmbeddedObject.getComponent()
oComponent.getTitle().String = "Foo-bar Foo-bar Foo-bar"
Rem and other settings...
EndIf
EndIf
Next i
EndIf
End Sub
I have some problem converting simples VB scripts (formating) into MATLAB:
VB script:
Range("A1").Select
Selection.Font.Italic = True
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
End With
I tried:
xlswrite('test.xls',1,'A1');
Excel = actxserver('Excel.Application');
Excel.Workbooks.Open('test.xls');
Range = Excel.Range('A1');
Range.Font.Italic = True; % Doesnt work
Range.Border.Item('xlEdgeRight').LineStyle = 1; % Doesnt work
Excel.Visible = 1;
Any workaround? Thanks
The problem is probably this line:
Range = Excel.Range('A1');
Your Excel object is an Application object, which doesn't have a Range property. The VBA example you follow uses a (IMHO) poor practice of using the global default objects that are only available within the context of the application itself. You need to grab a reference to the Workbook returned by this call:
Excel.Workbooks.Open('test.xls');
After that, you need to get the worksheet from it's indexed Worksheets property, then get the Range from that. Also, "xlEdgeRight" is an enumeration member so external calls have to use the integer values for them instead of a string. You can replace xlEdgeRight with 10.
I know next to nothing about Matlab, but this is what the more explicit code would look like in VBA:
Dim book As Workbook, sheet As Worksheet, rng As Range
Set book = Application.Workbooks.Open("test.xls")
Set sheet = book.Worksheets("Sheet1")
Set rng = sheet.Range("A1")
rng.Font.Italic = True
rng.Borders.Item(10).LineStyle = 1
You should be able to get it from there.
I'm creating a custom System Target File (STF) and adding some RTW options that need to be configured. Some options are dependent on others, and may or may not make sense depending on how they are configured. In these cases I would like to conditionally disable them (grey out).
So far I have something like this (Using MATLAB R2014a)
...
rtwoptions(oIdx).prompt = 'Enable Foo';
rtwoptions(oIdx).type = 'Checkbox';
rtwoptions(oIdx).default = 'off';
rtwoptions(oIdx).enable = 'on';
rtwoptions(oIdx).tlcvariable = 'Foo';
rtwoptions(oIdx).makevariable = 'FOO';
oIdx = oIdx + 1;
rtwoptions(oIdx).prompt = 'Bar only makes sense if Foo is enabled';
rtwoptions(oIdx).type = 'Checkbox';
rtwoptions(oIdx).default = 'off';
if foo <--- WHAT DO I PUT HERE?
rtwoptions(oIdx).enable = 'on';
else
rtwoptions(oIdx).enable = 'off';
end
According to the documentation there is such a thing as a conditional rtwoption by calling a MATLAB function, but I would like to make it dependent on another options.
This must be possible, as it is implemented in Code Generation --> Report tab ("Open report" is only enabled if you enable "Create Report").
What is the syntax of this condition? Can I use the "tlcvariable"?
This is possible using the rtwoptions(i).callback field and a Matlab function that uses slConfigUIGetVal to get the value of the controlling option (Foo in the example) and slConfigUISetEnabled to enable/disable the dependant option (Bar in the example).
I am trying to cycle through a list of variables I have say 30+ and calculate the maximum and minimum value for each column in each variable. Save this in a new array and then export to excel.
My thoughts were to use the who function to create an array with the name of all variables which are present. Then cycling through each one using a for loop after working out the size of the array which was created. This works fine, however when I try and use the string to reference the array it does not work.
I will add in the code which I have written hopefully someone will be able to come up with an easy solution :).
variable_list = who
cell2 = input('What cell size do you want to look at? ');
STARTcell = input('What was the start cell size? ');
[num_variables, temp] = size(variable_list);
for va = 1:num_variables
variable = variable_list{va}
[max_value, max_index] = max(variable{cell2/STARTcell})
[min_value, min_index] = min(variable{cell2/STARTcell})
format_values{va} = vertcat(max_values, max_index, min_value, min_index);
end
The variables I am looking at are arrays which is why I use the cell2/STARTcell to reference them.
You need to use the eval() function to be able to get the value of a variable corresponding to a string. For example:
a = 1;
b = 2;
variable_list = who;
c = eval(variable_list{2});
results in c being 2. In your code, the following line needs to change from:
variable = variable_list{va}
to:
variable = eval(variable_list{va});
resulting in variable having the value of the variable indicated by the string variable_list{va}. If variable is of cell type, then you should be fine, otherwise you may have to revise the next two lines of code as well because it seems that you are trying to access the content of a cell.
I am collecting data from a process in a struct as follows;
timepace(1,i) = struct(...
'stageNo',str2num(stageNo), ...
'split1', splits(1,1),...
'split2', splits(1,2),...
'split3', splits(1,3) );
However, the number of “splits” is can vary from 2 to 10. At the moment I am using a longer code than shown above to allocate all the “splits” and if not, put a 0. But this makes me create a lot of unused data for the “just in case” situation of having so many splits.
Would there be a way to make the length of it flexible? I know the required final number because it is an input to the system for each query that I do.
Any ideas on how to make it flexible and related to a length variable?
You could use something like
S = struct('stageNo',str2num(stageNo));
for jj = 1:size(splits,2)
S.(['split' num2str(jj)]) = splits(1,jj);
end
timepace(1,i) = S;
It's called "dynamic field reference". You can find more information here for instance.
Just use an array instead of struct:
timepace(1,i) = struct(...
'stageNo',str2num(stageNo), ...
'split', *PUT HERE YOUR ARRAY*...
);
Don't forget that in the case of cell array, you need additional {} brackets.
timepace(1,i) = struct(...
'stageNo',str2num(stageNo), ...
'split', {{1,2,3,4,5}}...
);
If you must use struct than see Rodys answer.
You could also use cell2struct:
labels = {'split1','split2','split3',...}
c = num2cell(splits);
f = labels(1:numel(c));
s = cell2struct(c,f,2);