• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

creating object with properties

Explorer ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

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:

screen.png

Where is my mistake?

Can I pass all properties during creating object?

Thanks for any feedback,

Jarek

TOPICS
Scripting

Views

1.3K

Translate

Translate

Report

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

correct answers 1 Correct answer

People's Champ , Jan 18, 2017 Jan 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} 

});

Votes

Translate

Translate
People's Champ ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

Hi

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

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

     fillColor: 'None', 

     contentType: ContentType.GRAPHIC_TYPE ,

  frameFittingOptions: {fittingOnEmptyFrame: EmptyFrameFittingOptions.FILL_PROPORTIONALLY} 

});

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

Ok, Marc, I understand. Everything is clear now, I see the difference.

Thank you!

..

Jarek

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

Hi all!

In a similar way, I've a problem to add an auto-resizing property when I create an object style!

    try {

        var myOStyle = app.activeDocument.objectStyles.item("mySel");

        myOStyle.name;

    }  catch (e) {

            var myOStyle = app.activeDocument.objectStyles.add({name: "mySel", enableFill: false, enableStroke: false});

    }

    myFrame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH;

    myFrame.textFramePreferences.useNoLineBreaksForAutoSizing = true;

Thanks in advance! 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 19, 2017 Jan 19, 2017

Copy link to clipboard

Copied

Why? I think, Loics example is pretty clear?!

var curDoc = app.activeDocument;

var oStye = (curDoc.objectStyles.itemByName("mySel").isValid) ? curDoc.objectStyles.itemByName("mySel") : curDoc.objectStyles.add({name: "mySel"});

oStye.properties = {

  enableTextFrameAutoSizingOptions: true,

  textFramePreferences: {

    autoSizingType: AutoSizingTypeEnum.HEIGHT_AND_WIDTH,

    autoSizingReferencePoint: AutoSizingReferenceEnum.TOP_CENTER_POINT,

    useNoLineBreaksForAutoSizing: true

  }

};

or

var curDoc = app.activeDocument;

if  (! curDoc.objectStyles.itemByName("mySel").isValid) {

  var oStyle = curDoc.objectStyles.add({

    name: "mySel",

    enableTextFrameAutoSizingOptions: true,

    textFramePreferences: {

      autoSizingType: AutoSizingTypeEnum.HEIGHT_AND_WIDTH,

      autoSizingReferencePoint: AutoSizingReferenceEnum.TOP_CENTER_POINT,

      useNoLineBreaksForAutoSizing: true

    }

  });

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 19, 2017 Jan 19, 2017

Copy link to clipboard

Copied

LATEST

Thanks Kai! Clear now! 

(^/)

Votes

Translate

Translate

Report

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