The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Dictionary for initializing shape properties when using Objective-C ScriptBridge (http://forums.omnigroup.com/showthread.php?t=31021)

Joe.Hocker 2013-11-07 11:00 PM

Dictionary for initializing shape properties when using Objective-C ScriptBridge
 
I'm using Objective-C ScriptBridge to build some shapes in OmniGraffle.
I'm able to create and add the shape to a canvas, but there are many properties which I can't figure out how to set correctly.
For instance I'm able to set things like origin, side padding, size, draws shadow. But I can't figure out how to set text placement. This shows as an enum.
I need to make that an object so that it can be added to the dictionary which I'm using as properties to initialize the shape (initWithProperties)... It looks something like this:
[CODE]OmniGraffleShape *anotherGraffleShape = [[[self.graffleApp classForScriptingClass:@"shape"] alloc] initWithProperties:[self grafflePropertiesForHostShape:shapeMetaData]];
[/CODE]

Here is a sample of my dictionary which I'm passing for the initWithProperties:

[CODE]NSMutableDictionary *graffleProperties = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:shapeMetaData.sidePadding],@"sidePadding",
[NSArray arrayWithObjects:[NSNumber numberWithInt:shapeMetaData.startingXOrigin],[NSNumber numberWithInt:shapeMetaData.startingYOrigin], nil],@"origin",
[NSArray arrayWithObjects:[NSNumber numberWithInt:shapeMetaData.shapeWidth],[NSNumber numberWithInt:shapeMetaData.shapeHeight], nil],@"size",
[NSNumber numberWithBool: shapeMetaData.drawsShadow],@"drawsShadow",
[NSNumber numberWithBool: shapeMetaData.drawsStroke],@"drawsStroke",
[NSNumber numberWithDouble:shapeMetaData.cornerRadius],@"cornerRadius",
[NSString stringWithFormat:@"%c", OmniGraffleOGvaTop],@"textPlacement",
nil];[/CODE]

It it wasn't obvious, the above example is using a custom object calls shapeMetaData, which I set most of the properties for a shape. Here I'm just getting those properties and adding them to a dictionary which will later be used to initialize the OmniGraffle Shape object.

I would really appreciate any examples of how to set the various properties for a shape. It would be even better if somebody could show an example of how to build a properties dictionary with most every property in the example.

Joe.Hocker 2014-01-04 03:01 PM

Setting Text Alignment using Scripting Bridge
 
[QUOTE]But I can't figure out how to set text placement. This shows as an enum.
I need to make that an object so that it can be added to the dictionary which I'm using as properties to initialize the shape (initWithProperties)...[/QUOTE]

OK... Finally figured it out. I know enums are supposed to be simple, but I sure had a hard time figuring out how to use them.
It is easiest just to show a code snippet. I've broken it down to several steps...
1. properties are passed using an NSDictionary. In this example: graffleProperties
2. As I understand now, emun is just an integer. So, I get the integer value using int textPlacementInt = (OmniGraffleOGva)OmniGraffleOGvaTop; // Not sure if there is a better way, but this works.
3. NSDictionary needs an object, not scalar value. So, turn the int into an NSNumber.
4. Now you are set to add the key / value pair to the dictionary using the key @"textPlacement" and the NSNumber representation of (OmniGraffleOGva)OmniGraffleOGvaTop

I hope this helps somebody other than me. :)

[CODE]NSMutableDictionary *graffleProperties = [NSMutableDictionary dictionaryWithCapacity:10];
int textPlacementInt = (OmniGraffleOGva)OmniGraffleOGvaTop;
NSNumber *textPlacementNumber = [NSNumber numberWithInt:textPlacementInt];
NSLog(@"JBHDiagramController - omniGrafflePropertiesForPolygonShape: textPlacementInt: %d", textPlacementInt);
[graffleProperties setObject:textPlacementNumber forKey:@"textPlacement"];[/CODE]


All times are GMT -8. The time now is 04:08 PM.

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