The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniGraffle > OmniGraffle General
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Dictionary for initializing shape properties when using Objective-C ScriptBridge Thread Tools Search this Thread Display Modes
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]];
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];
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.

Last edited by Joe.Hocker; 2013-11-07 at 11:04 PM.. Reason: wrapping some code with code attributes
 
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)...
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"];
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -8. The time now is 03:44 PM.


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