Skip to main content
Known Participant
January 18, 2017
Answered

creating object with properties

  • January 18, 2017
  • 1 reply
  • 1815 views

Hi guys!

I'm trying to figure out how exactly creation properties work.

Here is some rectangle:

myFrame = app.activeDocument.pages[0].rectangles.add({

     geometricBounds: [0,0,100,100],

     fillColor: 'None',

     contentType: ContentType.GRAPHIC_TYPE

});

I want to add frameFittingOptions to in while I'm creating whole object, so:

     ...

     contentType: ContentType.GRAPHIC_TYPE,

     frameFittingOptions.fittingOnEmptyFrame: EmptyFrameFittingOptions.FILL_PROPORTIONALLY

});

And now I'm reciving error:

Where is my mistake?

Can I pass all properties during creating object?

Thanks for any feedback,

Jarek

This topic has been closed for replies.
Correct answer Loic.Aigon

Hi

myFrame = app.activeDocument.pages[0].rectangles.add({ 

     geometricBounds: [0,0,100,100], 

     fillColor: 'None', 

     contentType: ContentType.GRAPHIC_TYPE ,

  frameFittingOptions: {fittingOnEmptyFrame: EmptyFrameFittingOptions.FILL_PROPORTIONALLY} 

});

1 reply

Loic.Aigon
Loic.AigonCorrect answer
Legend
January 18, 2017

Hi

myFrame = app.activeDocument.pages[0].rectangles.add({ 

     geometricBounds: [0,0,100,100], 

     fillColor: 'None', 

     contentType: ContentType.GRAPHIC_TYPE ,

  frameFittingOptions: {fittingOnEmptyFrame: EmptyFrameFittingOptions.FILL_PROPORTIONALLY} 

});

foltmanAuthor
Known Participant
January 18, 2017

Heh, it is now quite obvious! Thank you, Loic.Aigon.

Now there is second part of my problem. Can I add any type of property corresponding to object type?

For example I'm trying to add grep style to a paragraph style the same way I did with frameFittingOptions:

myDoc = app.activeDocument;

myStyle = myDoc.paragraphStyles.add({

    name: "BODY",

    nestedGrepStyles: {

        appliedCharacterStyle: myDoc.characterStyles.item('some style'),

        grepExpression: 'some expression'

    }

});

And it doesn't work, style is being created, but without grep style.

..

Jarek

Marc Autret
Legend
January 18, 2017

Hi Jarek,

Keep in mind that nestedGrepStyles (as well as paragraphStyles) refers to a collection, that is, a special member that requires the add() method to be fueled. So you need to load it separately:

myStyle = myDoc.paragraphStyles.add({ 

    name: "BODY", 

    });

myStyle.nestedGrepStyles.add({ 

    appliedCharacterStyle: myDoc.characterStyles.item('some style'), 

    grepExpression: 'some expression',

    });

@+

Marc