How can I switch on AI smart guides in my plugin

Community Beginner ,
Feb 22, 2021

Copy link to clipboard

Copied

Hello

Do you know how can I programmatically switch on AI smart guides in my plugin?

I've tried to set preferences like kAISnappingPrefShowSmartGuides & kAISnappingPrefShowToolGuides, but it does not help. Probably there should be a tool option but again cannot find any.

Any other ides? I know it is possible as I've seen it in other plugins. Just cannot figure out how

 

 

TOPICS
How to, SDK, Third party plugins, Tools

Views

118

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

1 Correct Answer

Participant , Feb 23, 2021
MilosR Participant , Feb 23, 2021
@syuzie Ok. I managed to do it. Create tool using AIToolSuite and assign it kToolWantsToTrackCursorOptionIn Plugin::TrackToolCursor (where you receive AIToolMessage, this is kSelectorAITrackToolCursor selector) you will receive AIToolMessage, this message contains event and cursor point (AIRealPoint)Call following to activate snap and get destination/snap point (snap annotations will be drawn automatically by AICursorSnapSuite suite)     // Get current view AIDocumentViewHandle vh; sAIDocumentVi...

Likes

Translate

Translate
Jump to answer Jump to answer
Participant ,
Feb 22, 2021

Copy link to clipboard

Copied

You can try one of following options:

 

  1. Using AICommandManagerSuite::GetCommandIDFromName get command ID from command name "Snapomatic on-off menu item" (kSnapomaticOnOffMenuItemCommandStr), then with that ID call AIMenuSuite::InvokeMenuAction. To check wether smart guides are enabled i guess you can use AICursorSnapSuite::UseSmartGuides 
  2. Record an action, save to file, examine the file to find out which command is called (probably same as above, invoke menu action with key written above) and trigger same action using AIActionManagerSuite::RecordActionEvent. It would be something like this:
AIActionParamValueRef param;

sAIActionManager->AINewActionParamValue(&param);
sAIActionManager->AIActionSetStringUS(param, 'itnm', ai::UnicodeString(kSnapomaticOnOffMenuItemCommandStr));

return sAIActionManager->PlayActionEvent("adobe_commandManager", kDialogOff, param);

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
syuzie AUTHOR
Community Beginner ,
Feb 22, 2021

Copy link to clipboard

Copied

Thanks MilosR for the answer.

I've tried solution 1 but didn't get the expected result, then figured out that InvokeMenuAction actually is the same as I have clicked it in menu. 

So when my plugin tool is active and I select View->Smart Guides (Ctrl+u) it anyway doesn't show me smart guides.

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
syuzie AUTHOR
Community Beginner ,
Feb 22, 2021

Copy link to clipboard

Copied

Forgot to mension

AICursorSnapSuite::UseSmartGuides(NULL) always return false despite the "View-> Smart Guide" menu item is choosen or no

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Feb 23, 2021

Copy link to clipboard

Copied

Did you try second solution (just paste code). It is same as Invoke, but it work in some cases when options are grayed-out/disabled

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
syuzie AUTHOR
Community Beginner ,
Feb 23, 2021

Copy link to clipboard

Copied

@MilosR  I've tried and it looks it does the same just switches on/of smart guides in menu, but doesn't show guides.

I think the problem is: UseSmartGuides is not returning true. And I cannot figure out how to switch it on.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Feb 23, 2021

Copy link to clipboard

Copied

Did you create tool with AIToolSuite? Could you please describe that part. I tested method using PlayActionEvent and Smart Guides are turned on/off with code above - guides are also visible after, when i drag some element. It could be that it isn't possible to toggle smart guides at specific point in your code, maybe during drag.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Feb 23, 2021

Copy link to clipboard

Copied

I also checked with AnnotatorTool example. When Annotator Tool is active it is possible to toggle Smart Guides using code above or manually.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Feb 23, 2021

Copy link to clipboard

Copied

I think I got your point. You are able to toggle option, but guides are not visible while your tool is active.

 

If you wish for your tool to snap to guides during drag I think you need to make that yourself using AIHitTestSuite and AICursorSnapSuite. I didn't use this feature, so I don't know much. I will try to find out more, if i find something i will get back to you.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Feb 23, 2021

Copy link to clipboard

Copied

@syuzie Ok. I managed to do it.

 

  1. Create tool using AIToolSuite and assign it kToolWantsToTrackCursorOption
  2. In Plugin::TrackToolCursor (where you receive AIToolMessage, this is kSelectorAITrackToolCursor selector) you will receive AIToolMessage, this message contains event and cursor point (AIRealPoint)
  3. Call following to activate snap and get destination/snap point (snap annotations will be drawn automatically by AICursorSnapSuite suite)

 

 

 

 

 

// Get current view
AIDocumentViewHandle vh;
sAIDocumentView->GetNthDocumentView(0, &vh);

// Check if smart guides are active
if(sAICursorSnap->UseSmartGuides(vh)){

	AIRealPoint dst;

	// See documentation for control letters
	// You can also use HitTrack or TrackInRect 
	error = sAICursorSnap->Track(vh, fCursorArtPoint, message->event, "ATFGPLM v i o f", &dst);

	// After this you will have snap point in dst

}​

 

 

 

 

 

Per documentation AICursorSnapSuite functions doesn't accept NULL. You need to pass AIDocumentViewHandle

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
syuzie AUTHOR LATEST
Community Beginner ,
Feb 23, 2021

Copy link to clipboard

Copied

@MilosR you made my day! THANKS a lot

I was using HitTrack but with NULL and getting error PARM, but was playing with other parameters butnot with document.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more