How to remove a basedOn style without losing the bet in shape

I have a problem that I solved in my case, but I wonder if there is a cleaner solution. I have a function that removes the basedOn of a paragraph style or a character style that is passed. I thought that it worked, but it came to my attention that the character styles were losing their formatting when their basedOn style has been deleted (in fact, the value '[No Style character]'). Set the style basedOn the "[None]" style has the same effect. I also tried to create a dummy no style and use it as my base, same effect. When you do this through InDesign UI, the formatting is preserved, so I think it's a bug. My solution has been to create a new character style, all properties of the first style (except basedOn and properties) copy on it, delete the original style (replace with the new style), and then rename the new style to match the old. Far as I can tell it works, but it seems exaggerated. Does anyone have a better suggestion or hint?

Here is the code that causes the problem:

function unBaseStyle(funcSty){
    //Current style name.
    var myStyName = funcSty.name;
    //If the style is surrounded in brackets it is a default InDesign style and should not be unbased. In that case, skips to next style.
    if (myStyName.lastIndexOf("[", 0)  != -1) {return false;}
    else{
        var myBaseStyName = funcSty.basedOn.name;
        //Checks that the base style isn't undefined (which would indicate that it is already [No ... Style] and also that it isn't bracketed.
        if (myBaseStyName == undefined || myBaseStyName.lastIndexOf("[", 0)  != -1) {return false;}
        else{
            //If the style is a paragraph style, bases it on [No Paragraph Style].
            if (funcSty instanceof ParagraphStyle){funcSty.basedOn = "[No Paragraph Style]";}
            //If the style is a character style, bases it on [No Character Style].
//--->This is the line that causes the problem. funcDoc.characterStyles("None") has the same effect.
            else{funcSty.basedOn = "[No Character Style]";}
            return true;
        }
    }
}

Here is my code to work:

function unBaseStyle(funcDoc, funcSty){
    //Current style name.
    var myStyName = funcSty.name;
    //If the style is surrounded in brackets it is a default InDesign style and should not be unbased. In that case, skips to next style.
    if (myStyName.lastIndexOf("[", 0)  != -1) {return false;}
    else{
        var myBaseStyName = funcSty.basedOn.name;
        //Checks that the base style isn't undefined (which would indicate that it is already [No ... Style] and also that it isn't bracketed.
        if (myBaseStyName == undefined || myBaseStyName.lastIndexOf("[", 0)  != -1) {return false;}
        else{
            //If the style is a paragraph style, bases it on [No Paragraph Style].
            if (funcSty instanceof ParagraphStyle){funcSty.basedOn = "[No Paragraph Style]";}
            //If the style is a character style, bases it on [No Character Style].
                else{
                    var funcStyName = funcSty.name;
                    var newSty = funcDoc.characterStyles.add(funcStyName + " basedOnCopy");
                    var p
                    for (p in funcSty){
                        if (funcSty.hasOwnProperty(p) && p != "basedOn" && p != "properties"){
//-->This copies over the properties; wrapped in try/catch because some properties are read-only.
                            try{newSty[p] = funcSty[p];}catch(e){}}
                    }
                    funcSty.remove(newSty);
                    newSty.name = funcStyName;
            return true;
        }
    }
}

Am I missing something or is my solution more or less the way forward?

Hi cchimi,

Easily check if a style property is inherited is a question open for me

Perhaps our fellow Scripting Guys have some ideas on this point.

In regards to your routine of rewriting from scratch , a better approach (although not fully tested) may be:

function unBaseStyle(/*ParagraphStyle|CharacterStyle*/sty)
{
    var o = sty.properties;
    if( !o.hasOwnProperty('basedOn') || 0 <= o.name.indexOf('[') ) return;
    o.basedOn = "$ID/None";
    sty.properties = o;
}

@+

Marc

Tags: InDesign

Similar Questions

  • How to post jsp code snippets without losing the bet in shape

    Please forgive me for this stupid question and do not know if this is the right place. But I'm having a hard time sticking the jsp code snippets when I answer all the sections. The jsp code snippet will be all html tags with ' < ' and ' / > ' etc. I tried to replace by & lt; etc but still no help. I see that other users are able to view the jsp code correctly snippets. Is there something special I need to do. I use both FF and IE browser. I use
    ...tag also. Still no help. Also I am not able to paste any Graphic images. How can we do this. Any help highly appreciated.
    
    Thanks
    Ravi Jegga
    
    Edited by: Ravi Jegga on Nov 18, 2009 11:06 AM
    
    Edited by: Ravi Jegga on Nov 18, 2009 11:07 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    Hello Ravi,

    More-than and less - that signs are deleted by the forum software. From:

    http://wiki.Oracle.com/page/Oracle+discussion+forums+FAQ

    but from my experience, sometimes they appear and sometimes they are not. I have yet to understand the model. The FAQ says. = can be used instead of a more - and less - than, but I never got it to work.

    You cannot paste images in, but you can use exclamation points at the ends of a full URL to put in an image tag, for example:

    !http://forums.oracle.com/forums/themes/english/resources/oralogo_small.gif!
    

    becomes

    ! http://forums.Oracle.com/forums/themes/English/resources/oralogo_small.gif!

    The 'Preview' in the editor mode is the best way I have found to see what forums software will make your formatting, so that you can play with formatting before posting.

    Kevin

  • How can I force a paragraph style without losing the italics?

    This has been annoying me for ages. I work on documents in Word, using italics for book titles, etc. and then import them into indesign. I apply a paragraph style and three out of four times the bits in italics are preserved. However, the fourth time the paragraph style does not (probably due to the presence of italics) and I have to force him to do it using Alt-click. Invariably, the italics is replaced by Roman.

    It happens earlier with a bunch of notes and endnotes in a book, I'm working on and means I have to go back through each of them, manually applying italics to my books and reference titles. Is it possible to force a paragraph of note/reference style without losing the text in italics?

    Thanks for your suggestions,

    Tom.

    I'm not sure that long-term planning is needed here.

    If your only concern loses italics when importing from Word, create,.

    in InDesign, an italic character style. Then do a search and replace

    in the document, InDesign (once you have placed the Word file)

    looking for an italics, formatting and replacing with your italics

    character style.

    Who will save you from losing your italic formatting.

    Repeat for bold, bold italic, exponent, index and nothing else

    the author uses.

    There are scripts that help in this process (I think one of them is

    called "preptext", by Jongware).

    If you want a complete solution that can be found all types of

    override setting in shape and creates and applies the appropriate character

    style, check out my script "create character the Styles of overrides him."

    available on the script on freelancebookdesign.com tab.

    Ariel

  • How to use reveal all this without losing the work of culture?

    My workflow is to editing and cropping of images. I need the flexibility to perform any order.

    When I use the crop tool, I continue to delete the cropped Pixels unchecked. When I edit the images I want to edit the complete picture, not cropped image.

    If I use reveal all to make alterations on the full image after cropping, I lose my job of cropping. Is there a solution?

    How to use reveal all this without losing the work of culture?

    How to take a bath without getting wet?

    Enter drollery side you could use a path of access to store the current size before calling "Reveal everything", then later on the path as a selection of load, switch to the crop tool and hit.

    Or convert to smart object before you crop, then do the editing in the SO (it could be a potentially significant increase in file size, however).

  • [win] [js] [cs4] find/replace the paragraph styles without losing the replacements the

    Hi guys I need some help here.

    I created a javascript script that will find and replace paragraph styles for the DOCFILE with indesign paragraph styles. everything works fine but the problem is that, when she applies paragraph styles, he loses all replacements the. I tried:

    changetext (false);

    but his does not work, this is a kind of conditional parameter that I can put in the function changetext() so that it used clear local overrides?

    Thank you.

    Horse

    Use findGrep() (or findText()) instead of changeText(). This returns an array of items found. Then, you can loop through the array and apply a paragraph style without erasing the replacements (the 2nd parameter must be false).

    Example:

    Main();
    
    function Main() {
        var foundItem;
        var doc = app.activeDocument;
    
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
    
        app.findGrepPreferences.findWhat = ".+";
        app.findGrepPreferences.appliedParagraphStyle = "Body text";
    
        var foundItems = doc.findGrep();
    
        for (var i = 0; i < foundItems.length; i++) {
            foundItem = foundItems[i];
            foundItem.applyParagraphStyle(doc.paragraphStyles.item("Body"), false);
        }
    
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
    }
    
  • How to remove a logical Partition without disturbing the other

    Hello, I recently ran into some trouble.

    As you can see from the picture, there are little free space next to the D: (10.55 GB) drive. I want to merge the free space with the 5 GB unallocated space and want to create a primary partition to install another version of windows. The problem is that when I right click the free space, the partition option delete is gray. I discovered that to delete the D: drive to get space but I can't do that. Even my backup drive is full.

    So, how do to remove free space without disturbing D: drive

    You can merge only the free and not allocated using a third-party partitioning tool and not the built in tool of victory.

    It's free http://www.easeus.com/partition-manager/epm-free.html

    If you add another partition to base all existing partitions will be converted to dynamic, the recovery partition to the then will no longer work

  • Laptop with XP/Ubuntu Dual Boot (grub 2, not to wubi). How to safely to Windows 7 without losing the dual boot ubuntu?

    Hello

    I have a laptop Dell Inspiron 6400/1505 (1.73 Gz, Intel Core 2 Duo, 2 GB RAM, 750 GB (7200 RPM) HARD drive) with Windows XP and Ubuntu 12.04 LTS installed in dual boot. I installed Ubuntu in a separate partition, not not using WUBI. Since support for XP runs in the month of April, I have to upgrade to Windows 7. I would like to know if I could pass safely XP to Windows 7 (I understand the parameters and programs cannot be transferred to the upgraded version of Windows and must be done manually) without disturbing my score of Ubutnu and the GRUB that starts when I turn on the computer. What are my options if this is not possible. I know one option is to completely wipe the hard drive and start over. But I just wanted to know if I could save my Ubuntu installation.

    PS. forgive me if this has been discussed already, please redirect.

    Thank you

    Joseph.

    To begin with, as you already know, there is no way to upgrade from Windows XP to Windows 7, it will have to do a clean install.  When you install Windows 7 it will rewrite the MBR and dislodge the grub, you need to reinstall GRUB after Windows installation and you need to add the Windows installation for the grub.

    John

  • How can I copy properties related without losing the connection to the control?

    I have dealt with a problem that is boring when copying / pasting properties. If the properties are bound to a control when copy them, they lose this link in the pasted version.

    Basically, the paste does not really the expected behavior of 'copy', 'paste' that results is different from the copied item. Is there a way to get around this in addition to having to go to each of them and re - link manually?

    Here are the excerpts to demonstrate the problem:

    Before pasting

    After pasting:

    So the solution then, as I found from reading the post of the wish list, is to CTRL-click and drag.

  • Equium A200: How to remove a partition without losing the BONE

    I have a laptop of A200 equium with a 120 GB hard drive but it is partitioned.
    Can you remove a partition on a hard disk without losing the operating system and get a hard drive with 120 GB?

    If so can you tell me how.

    Hello

    If you want to use the Toshiba Recovery CD and then the whole HARD disk will be formatted and all partitions will be deleted!
    Don t forget that the Toshiba Recovery CD is not the same as an original Microsoft windows Vista CD. The restore CD contains the OS, the driver and additional software

    Concerning

  • How can I re - install firefox without losing my data. It is infested bame ad.

    Firefox is infested with "ads name.

    How can I get rid of it or how can I
    Re-install firefox without losing any data?

    There is a rash that goes around, and the solution is not yet clear 100%. I suggest try reinstalling this way:

    Clean reinstall it

    We use this name, but it is not about the deletion of your settings, it comes to ensure that program files are-own and contain no alien code files. As described below, this process does not disrupt your existing settings. Don't uninstall NOT Firefox, that does not need.

    (1) download a fresh Installer for Firefox 37.0.1 of https://www.mozilla.org/firefox/all/ in an ideal location. (Scroll down your preferred language).

    (2) close Firefox (if applicable).

    (3) to rename the program folder

    (Windows 32-bit folder names)

    C:\Program Files\Mozilla Firefox
    

    TO

    C:\Program Files\OldFirefox
    

    (Windows 64-bit folder names)

    C:\Program Files (x86)\Mozilla Firefox
    

    TO

    C:\Program Files (x86)\OldFirefox
    

    (4) run the installer you downloaded in the #1. It should automatically connect to your existing settings.

    Any improvement?

    Note: Some plugins can only exist in this OldFirefox file. If it is missing something essential, present in these files:

    • \OldFirefox\Plugins
    • \OldFirefox\browser\plugins
  • How to save pictures of Photos in the form of files without losing the GPS data?

    Hello!

    Can someone advice me in the following cases:

    I want to erase my Photos from iPhone and iMac. Before that, I wish I had pictures of my library of Photos saved as a regular directory with files. As Windows does, for example.

    Can someone tell me how to save all Photos in the form of files without losing the GPS data? Thank you!

    Just export them (File menu) in unmodified versions.

  • Two copies of Firefox open. How to close one without losing the lugs on the other.

    Firefox has been slow to open up, so after awhile I clicked on the icon a second time.
    Then two copies opened, one with this page of solution of Mozilla and the other with all the many tabs that I use frequently.
    But when I tried to close the copy of solution of Mozilla, I was warned that the two copies would be closed, I know from
    experience can sometimes cause me to lose all the tabs on my master copy.
    So, how can I safely close a copy without losing the tabs on the other?
    Thank you.
    Dave

    Press Alt to display the Menu bar, and then press F to open the file menu, and then use the menu item close this window .
    Or use the X in the upper right of this window.

  • I forgot my password and got my iphone disabled after several attempts. its display to connect to itunes, but I am unable to connect to itunes too. How can I unlock my phone without losing any data? Help, please

    I forgot my password and got my iphone disabled after several attempts. its display to connect to itunes, but I am unable to connect to itunes too. How can I unlock my phone without losing any data? Help, please

    In short - you can't

    IF you have a computer with iTunes on which you did a prior backup - the phone will be recognized and iTunes offer todo backup before it clears your device - that - except if you know the access code the content cannot be saved

  • How can I remove songs from playlist without deleting the library?

    I have the song in the playlist right click and you click on delete, then the song just completely deleted my iTunes library. But I want only to remove it from my reading list. How can I remove songs from playlist without deleting the library?

    Highlight the track, press the delete key. If it still removes the track completely from the library, then at some point in the past you must tell it to do things like that.   iTunes prefs > advanced > reset all warnings of the dialog box. - https://discussions.apple.com/message/23987276

  • How can I switch phones with a member of the family without losing the data on a phone?

    How can I switch phones with a member of the family without losing the data on a phone?

    jkatts wrote:

    How can I switch phones with a member of the family without losing the data on a phone?

    Make a backup of each phone to iTunes or iCloud (do not forget to use your Apple ID or personal computer), then do whatever your carrier wants do you to change numbers if that's your intention, then restore these backups on the device of the "other."

Maybe you are looking for

  • "The computer was restarted due to a problem."

    I just started using my old Macbook Pro 2010 after the flight of my model of 2014. I swapped the HARD drive for an SSD (at the suggestion of a tech Genius), but three times now, I received the error "your computer has been restarted due to a problem"

  • I need help my program read in limited amounts of data at a time

    I have attached my schema. I have problems are the following I need to read the data from a .txt (alternately .lvm) entered file 250 at a time. The problem with the construction, I have now, is that the dynamics of the table buffer destroyed point ty

  • shortcut on the desktop fonts

    I want to change the font that shows on the desktop shortcuts. The default type is a white font with a black shadow and I want to change to a solid black arial font. Can anyone help?Thank you

  • BlackBerry, Blackberry Passport box

    Hello Please tell me what exactly the area of passport for blackberry?I watched several videos on unboxing passport blackberry in youtubeand there are two different types of boxes, a small and anotherbigger and of course there are 3 clips charger, ca

  • Help, please! 100 e-mail exporting do not in files exported from the old Windows Live Mail to the new computer laptop

    I just bought a new laptop, have both Windows 7 and both have Windows Live Mail. I have several folders in the program my old portable Windows Live Mail and hundreds of emails in each folder. I experienced the process of export of emails every day no