The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Problem Using Scripting Bridge and OmniGraffle (http://forums.omnigroup.com/showthread.php?t=14702)

pixel 2009-12-02 12:45 PM

Problem Using Scripting Bridge and OmniGraffle
 
Hi -

I'm attempting to programatically create shapes, etc via an app I'm creating using Scripting Bridge, but I'm not having much luck.

I have the following code:

[CODE]OmniGraffleDocument *document = [[[omnigraffle classForScriptingClass:@"document"] alloc] init];
[[omnigraffle documents] addObject:document];
SBElementArray *canvases = [document canvases];
OmniGraffleCanvas *mainCanvas = [canvases objectAtIndex:0];

// build the shape
NSDictionary *props = [NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObjects:[NSNumber numberWithInt:20],[NSNumber numberWithInt:20]],@"origin",
[NSArray arrayWithObjects:[NSNumber numberWithInt:100],[NSNumber numberWithInt:100]],@"size",
FALSE,@"drawsShadow",
TRUE,@"drawsStroke",
@"ShapeName","name",
[NSColor blackColor],@"stroke color"
];

OmniGraffleShape *shape = [[[[omnigraffle classForScriptingClass:@"shape"] alloc] initWithProperties:props] autorelease];
[[mainCanvas shapes] addObject:shape][/CODE];


It successfully communicates to OmniGraffle, and creates a new document. But when it attempts to add the new shape to the canvas (the last line of code), it dies with the following in the debugger:

[CODE]2009-12-02 16:43:13.242 TestApp[29013:813] Apple event returned an error. Event = 'core'\'crel'{ 'kocl':'OGSh', 'insh':'insl'{ 'kobj':'obj '{ 'want':'OGSh', 'from':'obj '{ 'want':'OGWS', 'from':'obj '{ 'from':'null'(), 'want':'docu', 'form':'name', 'seld':'utxt'("Untitled 5") }, 'form':'indx', 'seld':1 }, 'form':'indx', 'seld':'abso'($206C6C61$) }, 'kpos':'end ' }, 'prdt':{ } }
Error info = {
ErrorNumber = -10000;
}[/CODE]

Anyone have any experiences using Scripting Bridge and OmniGraffle?

Thanks!
--Eric

pixel 2009-12-03 08:52 AM

Found Solution.
 
The shape needs to be added to the graphics array of the layers array of the canvas:

[CODE]OmniGraffleCanvas *mainCanvas = [canvases objectAtIndex:0];
OmniGraffleLayer *mainLayer = [[mainCanvas layers] objectAtIndex:0];
OmniGraffleShape *shape = [[[[omnigraffle classForScriptingClass:@"shape"] alloc] initWithProperties:props] autorelease];
[[mainLayer graphics] addObject:shape];
[/CODE]


All times are GMT -8. The time now is 02:14 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.