0% found this document useful (0 votes)
40 views1 page

Solutions 39

This document provides sample code for creating a vertical ruler guide on the first page of the active spread in a layout document. The code gets the active document layer and spread, then creates a new guide command with the parent spread layer UID, distance from the left edge of the first page bounding box, page owner UID, default guide threshold and color from the guide preferences. It processes the command to add the new vertical ruler guide.

Uploaded by

Charana Studios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

Solutions 39

This document provides sample code for creating a vertical ruler guide on the first page of the active spread in a layout document. The code gets the active document layer and spread, then creates a new guide command with the parent spread layer UID, distance from the left edge of the first page bounding box, page owner UID, default guide threshold and color from the guide preferences. It processes the command to add the new vertical ruler guide.

Uploaded by

Charana Studios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CHAPTER 1: Layout Guides and grids 39

Sample code

The following example demonstrates how to create a vertical ruler guide item on the first page of the
active spread. For code simplicity, error checking is omitted.
InterfacePtr<ILayoutControlData>
layoutData(Utils<ILayoutUtils>()->QueryFrontLayoutData());
// Get the active document layer
InterfacePtr<IDocumentLayer> docLayer(layoutData->
QueryActiveDocLayer());

InterfacePtr<ISpread> spread(layoutData->GetSpread(), IID_ISPREAD);


IDataBase* db = ::GetDataBase(spread);

// Get the guide spread layer for the active spread.


InterfacePtr<ISpreadLayer> spreadLayer(spread->QueryLayer(docLayer, nil, kTrue));

// The parent for the new guide is the guide spread layer.
UID parent = ::GetUID(spreadLayer);
UIDRef parentUIDRef(db, parent);

// Get the first page UID. ownerUID is a page for short guides.
UID ownerUID = spread->GetNthPageUID(0);

// Note: The parent for the guide we are to create is the spread. Each
// page owns its guides. We need to convert the guide coordinates
// to its parent space - spread space.

// Get the bounding box of the page in spread space.


InterfacePtr<IGeometry> geometry(db, ownerUID, IID_IGEOMETRY);
PBPMRect bBox = geometry->
GetStrokeBoundingBox(::InnerToParentMatrix(geometry));

InterfacePtr<ICommand> newGuideCmd(CmdUtils::CreateCommand(kNewGuideCmdBoss));

InterfacePtr<INewGuideCmdData> newGuideCmdData(newGuideCmd, IID_INEWGUIDECMDDATA);

// The distance the guide is located at.


PMReal distance = bBox.Left() + bBox.GetHCenter();

// Get the default guide preference


InterfacePtr<IGuidePrefs>
iGuideDefault((IGuidePrefs*)::QueryPreferences(IID_IGUIDEPREFERENCES,
kGetFrontmostPrefs));

// Get the guide threshold and the color index


PMReal guideThreshold = iGuideDefault->GetGuidesThreshold();
int32 guideColorIndex = iGuideDefault->GetGuidesColorIndex();

newGuideCmdData->Set(parentUIDRef, kFalse, distance, ownerUID, kTrue, guideThreshold,


guideColorIndex);

if (CmdUtils::ProcessCommand(newGuideCmd) != kSuccess)
// Report process command failure.

Related APIs

 IGuideData

You might also like