Skip to main content
Byungwan Jung
Participant
July 4, 2023
Question

How to Create IPathFinder

  • July 4, 2023
  • 1 reply
  • 420 views
Hello InDesign SDK Developers.
I keep testing and I can't solve the problem, so I'm looking forward to your help.

I want to perform XOR operation on two or more closed paths using IPathFinder.

UIDRef uidRef1 = CreatePath()...;//CreatePath function receives PathPointList as a parameter and creates a closed path.UIDRef uidRef2 = CreatePath()...; InterfacePtr<IPathGeometry> pathGeometry(uidRef2 , UseDefaultIID()); InterfacePtr<IPathFinder>iPathFinder(uidRef1 , UseDefault()); if (! iPathFinder) { break; } iPathFinder->AddPath(pathGeometry); IPathGeometry *result = nil; iPathFinder->combine(result, IPathFinder::kXOr); I can't get iPathFinder here, I need help on how to do it thank you

 

This topic has been closed for replies.

1 reply

Legend
July 4, 2023

Untested:

IPathFinder is on kUtilsBoss.

Utils<IPathFinder>()->combine(…)

Byungwan Jung
Participant
July 6, 2023

 

Thanks Dirk Becker.
With your help, I solved my iPathFinder problem.
However, the problem has not been resolved yet.
The result differs depending on the result value in the combine function. 
If the result is treated as nil, the combine operation is forcibly terminated. How can I know what to do with the initial value of the result when AddPath is performed on two or more path objects and combine is called?

UIDRef uidRef1 = CreatePath(...);
UIDRef uidRef2 = CreatePath(...);
UIDRef uidRef3 = CreatePath(...);

InterfacePtr<IPathGeometry> pathGeometry1(uidRef1 , UseDefaultIID());
InterfacePtr<IPathGeometry> pathGeometry2(uidRef2 , UseDefaultIID());
InterfacePtr<IPathGeometry> pathGeometry3(uidRef3 , UseDefaultIID());

Utils<IPathFinder>()->AddPath( pathGeometry1 );
Utils<IPathFinder>()->AddPath( pathGeometry2 );
Utils<IPathFinder>()->AddPath( pathGeometry3 );

 

IPathGeometry *result = pathGeometry1;
status = Utils<IPathFinder>()->Combine( result, IPathFinder::kXOr )

When I run this part, there is no error, but it does not work normally. 
How should I set the value of IPathGeometry *result?

 

 

Legend
July 6, 2023

I never used IPathFinder. Anyway, let's have a look.

When called from the UI, the call is wrapped into a bunch of nested commands. So the pathfinder itself does not create appropriate commands, it is just the raw functionality taking place within.

If you never heard about commands, the long related section in the programming guide is worth a read.

 

The question is do you want the changes in the document - use the command. Or do you need some temporary buffer? Use a non-persistent boss for that happens to implement IPathGeomentry. kPathGeometryBoss looks like made for that.

 

Otherwise, say hi to kMergePathCmdBoss.

After some filtering (locked? bah!) the UIDList holds e.g. 2 kSplineItemBoss. The IPathGeometry of the command appears to be empty and the IntData is 1 in my case. Numeric value of kUnion, while on later try kDifference is 2.

Besides to the call to IPathFinder, there are sub-commands:

- do something about object attribute overrides

- delete the other page item(s)

- of course, removing it/them from the hierarchy on the way

- Tons of notifications - Preflight wants to reconsider, the items get removed from the selection, maybe there is some associated XML to clean up.

As result, the kMergePathCmdBoss has a filled-in IPathGeometry, and a reduced UIDList (only the last item survived). Likely it also copies the IPathGeometry into the survivor.