Skip to main content
Inspiring
November 17, 2021
Question

Way to quickly replace the marker text in all same custom markers

  • November 17, 2021
  • 4 replies
  • 620 views

Hi! I am a novice user of FrameMaker 2019.

I use in a large book a lot of the same custom markers (several hundred) with the same type of marker text.

  1. Is there a way to quickly replace the marker text in all same custom markers (for example, replace 17.11.2021 with 18.12.2022)?
  2. Is there a way to quickly replace one type of marker with another type in a large document?

 

Thanks!

Igor

    This topic has been closed for replies.

    4 replies

    K.Daube
    Community Expert
    Community Expert
    November 17, 2021

    I'm currently developing a script which allows to

    • walk through all - or all of a distinct type - markers
    • search a marker (all or specific type) with a specific text - and replace it 
    • change the type of a found marker

    There is no function yet to find/change all markers of specific type in one 'batch'. But I will think about this.

    frameexpert
    Community Expert
    Community Expert
    November 17, 2021

    Hi Klaus, here is some starter code for you (untested):

    main ();
    
    function main () {
    	
    	var doc;
    	
    	doc = app.ActiveDoc;
    	if (doc.ObjectValid () === 1) {
    		processDoc (doc);
    	}
    }
    
    function processDoc (doc) {
    	
    	var marker, markerType;
    	
    	// Get the change-to marker type.
    	markerType = getMarkerType ("newMarkerType", doc);
    	if (markerType.ObjectValid () === 1) {
    		// Loop through the markers in the document.
    		marker = doc.FirstMarkerInDoc;
    		while (marker.ObjectValid () === 1) {
    			if (marker.MarkerTypeId.Name === "oldMarkerName") {
    				marker.MarkerTypeId = markerType;
    			}
    			marker = marker.NextMarkerInDoc;
    		}
    	}
    }
    
    function getMarkerType (markerName, doc) {  
         
        // markerType = getMarkerType (markerName, doc);
        // Get a marker type from the document; if it doesn't exist, create it.
        
        var markerType = doc.GetNamedMarkerType (markerName);  
        if (markerType.ObjectValid () === 0) {  
            markerType = doc.NewNamedMarkerType (markerName);  
        }  
        return markerType;  
    }
    
    K.Daube
    Community Expert
    Community Expert
    November 18, 2021

    Thank You Rick, for these snippets.

    To change the contents (MarkerText) it is OK to just change it in the 'current marker'.

    I had, however, no success in doing so for the marker type. I need to test with your proposal - it looks more promising.

    Edit: with Rick's proposal things work as expected! Thank You again.

    IGOR5C0CAuthor
    Inspiring
    November 17, 2021
    Hi Bob!
    Thanks for your feedback!
    To my regret, I am a novice user and have the most superficial knowledge of programming. Could you clarify your proposal with a simple example?
    Thank you in advance!
     
    Igor
    Bob_Niland
    Community Expert
    Community Expert
    November 17, 2021

    IGOR5C0C: Could you clarify your proposal with a simple example?

     

    MIF is Marker Interchange Format. It's a save-as option that renders a .fm (or .book) as plain ASCII in a legacy FM markup notation.

     

    I created a default portrait document {mif-marker.fm} with some random body text.
    I used Insert Marker to create a custom marker of name CustomMarkerName
    and with marker text of 17.11.2021. I inserted another after creating the marker type.
    I then saved the document as MIF to mif-marker.mif
    and opened that with a plain text editor (notepad).

     

    The body text instances of the marker look like this in the MIF:

    <Marker

     <MType 19>

     <MTypeName `CustomMarkerName'>

     <MText `17.11.2021'>

     <MCurrPage `1'>

     <Unique 998427>

    > # end of Marker

     

    If this is similar to what's in the MIF for your documents, it might be sufficient to:

    1. Save all the .fm & .book as mifs
    2. Open the mifs in an editor
    3. change all instances of
      <MText `17.11.2021'>
      to
      <MText `18.12.2022'>
    4. Save the revised files (still mifs)
    5. Open the mifs in FM, and if no problems…
    6. save-as back to .fm or .book

     

    I used to write Unix sed scripts to batch similar changes across huge books.

    Bob_Niland
    Community Expert
    Community Expert
    November 17, 2021

    What do a couple of these markers look like in the MIF?

    If they have unique content or syntax, just doing a replace op in a text editor might suffice.

    Jeff_Coatsworth
    Community Expert
    Community Expert
    November 17, 2021