I am trying to follow the Google Slides API reference material; 'Lines' but I must be missing something. I have successfully added rectangle shapes using the script, but now I want to connect them with a line. Here is what I have so far:
function addConnections()
{
var myPresentation = SlidesApp.getActivePresentation()
var presentationId = myPresentation.getId();
var slideId = myPresentation.getSlides()[0].getObjectId()
var requests = []
requests.push(
{
createLine:
{
lineProperties:
{
startConnection:
{
connectedObjectId: 'queryD200',
connectionSiteIndex: 3
},
endConnection:
{
connectedObjectId: 'queryD201',
connectionSiteIndex: 0
}
},
lineType: 'CURVED_CONNECTOR_2'
}
})
Slides.Presentations.batchUpdate({requests: requests}, presentationId);
}
The error that I get is: Unknown name "lineType" at 'requests[0].create_line': Cannot find field. Unknown name "lineProperties" at 'requests[0].create_line': Cannot find field.
But those are the exact field names that google uses in their documentation. I tried them both with quotations and without. Please Help! and thank you
I believe your goal as follows.
For this, how about this answer?
lineProperties
in createLine
.lineType
in LineProperties
.fields
is not used.createLine
.lineProperties
.
lineProperties
can be used for the existing line object using UpdateLinePropertiesRequest
.When your script is modified, it becomes as follows.
function addConnections() {
var myPresentation = SlidesApp.getActivePresentation()
var presentationId = myPresentation.getId();
var slideId = myPresentation.getSlides()[0].getObjectId();
var lineObjectId = "sampleline001";
var startShape = "queryD200";
var endShape = "queryD201";
var requests = [
{createLine: {
objectId: lineObjectId,
lineCategory: "CURVED",
elementProperties: {pageObjectId: slideId, size: {height: {magnitude: 1 ,unit: "PT"}, width: {magnitude: 1, unit: "PT"}}}
}},
{updateLineProperties: {
objectId: lineObjectId,
lineProperties: {startConnection: {connectedObjectId: startShape}, endConnection: {connectedObjectId: endShape}},
fields: "startConnection,endConnection"
}}
];
Slides.Presentations.batchUpdate({requests: requests}, presentationId);
}
As another pattern, you can also achieve this using Slides service instead of Slides API.
function addConnections() {
var myPresentation = SlidesApp.getActivePresentation()
var presentationId = myPresentation.getId();
var slide = myPresentation.getSlides()[0];
var slideId = slide.getObjectId();
var startShape = "queryD200";
var endShape = "queryD201";
var line = slide.insertLine(
SlidesApp.LineCategory.CURVED,
slide.getPageElementById(startShape).asShape().getConnectionSites()[0],
slide.getPageElementById(endShape).asShape().getConnectionSites()[0]
);
}
When above both scripts are run for 2 shapes, the following result can be obtained.
queryD200
and queryD201
are correct. So please be careful this.