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

Insert variable automatically with Element (FM2019)

Enthusiast ,
May 02, 2022 May 02, 2022

Copy link to clipboard

Copied

Before I spend hours investigating something that isn't possible, I thought I'd ask the experts.

 

Is it possible to insert a variable automatically when inserting an Element? I.e. If I insert a ProdName Element, it automatically inserts the variable ProductName. We don't use DITA or XML or any scripting, so would prever to do this (if possible) natively.

 

Thanks,

Quintin

Views

400

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

Community Expert , May 03, 2022 May 03, 2022

Here is a script that will insert a ProductName user variable automatically when you insert a ProdName element. Save the code to a text file and put it in this folder:

 

C:\Users\<UserName>\AppData\Roaming\Adobe\FrameMaker\<Version>\startup

 

where <UserName> is your Windows login name and <Version> is your FrameMaker version. You may have to create the startup folder.

 

Quit and restart FrameMaker and try inserting a ProdName element.

 

If the script is useful to you, please consider visiting http://give.roswellpark.org/goto/rickquatro

...

Votes

Translate

Translate
Community Expert ,
May 02, 2022 May 02, 2022

Copy link to clipboard

Copied

You just gave me something to ruminate on as I go to bed. You can't do it with stock FrameMaker, but I have an idea for a simple script. I will report back tomorrow.

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 ,
May 02, 2022 May 02, 2022

Copy link to clipboard

Copied

Thanks, but we specifically don't want to run a script to achieve this. If FrameMaker can't do this natively, that's fine too. I was just hoping there was a way to it natively (similar to auto inserting Child Elements.)

Thanks,

Quintin

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
Community Expert ,
May 03, 2022 May 03, 2022

Copy link to clipboard

Copied

Here is a script that will insert a ProductName user variable automatically when you insert a ProdName element. Save the code to a text file and put it in this folder:

 

C:\Users\<UserName>\AppData\Roaming\Adobe\FrameMaker\<Version>\startup

 

where <UserName> is your Windows login name and <Version> is your FrameMaker version. You may have to create the startup folder.

 

Quit and restart FrameMaker and try inserting a ProdName element.

 

If the script is useful to you, please consider visiting http://give.roswellpark.org/goto/rickquatro

#target framemaker

Notification (Constants.FA_Note_PostInsertElement, true);

function Notify (note, object, sparam, iparam) {
	
	var doc, element;
    
    switch (note) {
        
		// This event will be triggered after an element is inserted.
        case Constants.FA_Note_PostInsertElement:
		
			doc = object;
			element = doc.ElementSelection.beg.parent;
			// Check which element is the last one inserted.
			if (element.ElementDef.Name === "ProdName") {
				// Insert a user variable.
				insertVariable (element, "ProductName", doc);
			}
			
			break;
    }
}

function insertVariable (element, name, doc) {
	
	var textLoc;
	
	textLoc = doc.ElementLocToTextLoc (doc.ElementSelection.beg);
	doc.NewAnchoredFormattedVar (name, textLoc);	
}

 

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
Advisor ,
May 03, 2022 May 03, 2022

Copy link to clipboard

Copied

Quintin,

   There are a few techniques that get close to what you want, but they are not pretty. Before I list them, indulge me in an anecodte from my distant past. Decades ago I read a paper on user interfaces (I really wish I remember where I read it, so I could credit the author, but haven't been able to locate it). It included a story about two users of a graphics package, which was something such as the following. One user gushed about how wonderful the software was. The other complained that it did not provide a method of drawing butterflies. "No problem," said the other. "Just insert a white tulip upside down." The message, of course, was that solutions should be intuitive. The methods I list below are upside-down tulips. They are:

  1.  Use sytem variables.
  2.  Create a product-specific EDD.
  3.  Use a cross-reference instead of a variable.

 

In more detail:

 

Use system variables

FrameMaker supports two types of system variables: user variables and system variables. You can create and name user variables as needed. A container element cannot insert a user variable, which is what you would like to do. However, an element can be a system variable. The available system variables are predefined so you cannot create a new one called ProductName, but you can redefine the text displayed by a system variable. Therefore, if there is a system variable your documents will never, ever use, you can define that variable to be the product name. For example, if you will not be using Sub Section Number, your EDD can define an element called ProductName that displays the Sub Section Number variable. To define the product name, in a particular document, a writer would  have to define Sub Section Number to the product name (that's the "white tulip upside down" part), but once that is done inserting the ProductName element would display the desired text.

 

Create a product-specific EDD

If the number of products is small, you can create a different EDD for each one. The only difference among the various EDDs would be the definition of a container called ProductName, defined to be an empty text-range with a prefix (or suffix) that contains the product name. Defining its general-rule to be <EMPTY> prevents the writer from entering content into the element, but the prefix causes it to display the product name. 

 

To maintain the different EDDs, define a variable in the EDD called ProductName to be the name of a particular product. Use this variable in the definition of the prefix. 

 

Simple as the differences among the various EDDs is, maintaining them all can be tedious and susceptible to human error. Tassos Anastasiou and I have a plugin that automatically updates all the variations whenever you make a change to one of them.

 

Use a cross-reference instead of a variable

Another possibility is to use a cross-reference instead of a variable. In particular, create a new element called ProductName. Make ProductName a container with the general rule <TEXT> and make it a valid highest-level element. Have the writers create a new flow either in a different document or on a reference page of a document in one of the actual books. In this flow, the author of each book will insert a ProductName element whose text is the desired product name. The text of a second, unstructured flow on the same page can document the purpose of the other flow. Then, to insert the product name into the book, the writer would insert a cross-reference to the ProductName element in the separate document or reference page.

 

   --Lynne

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
Community Expert ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

Hi Lynne, I love the white upside-down tulip workarounds! -Rick

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
Community Expert ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

Your variable needs to be defined as an element. Are you trying to insert an unstructured variable in a structured doc?

-Matt Sullivan
FrameMaker Course Creator, Author, Trainer, Consultant

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 ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

Hmmm - in hind sight I should have included more backgroun in my original question, but was hoping that a simple question would result in a simple answer (is that ever the case with FM?)

 

We use a standard, pre-defined, set of Variables in all our documents. 'ProductName' is just one of them. These are maintained in a single Master document. 'ProductName', along with a few other variables, are updated depending on the document. The content of the variable will change, but the variable name is consistent across all documents, i.e. in document A, ProductName = MyProduct, in document B, ProductName = YourProduct, etc. 

 

@Lynne A. Price I'm not sure if the System Variable option would work for us as it refers to an Element/paragraph style - neither are associated with the Variable. We have too many documents (requiring various variations of the Variable content) to make maintaining multiple EDDs practical. Using a cross-reference would also not work as it too would require the Variable to be a Element or have a specific paragraph style.

 

@Matt-Tech Comm Tools That is sort of what I want to do - define my variable as an Element, but not 'hardcode' the content of the Element and have it updated from a Variable.

 

@frameexpert Your solution would work, though I'm not fond of the idea of using a script. It would mean that we would need to constantly maintain it when we change our EDD/Variables master list.

 

In conclusion to my original question, my takeaway answer would be: Yes, if we change the way we treat these variables. No, if wewant to continue using the Variables in the same way.

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
Community Expert ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

I put together my script as a quick solution. It could be modified to use an outside settings file where the element names/variable names could be configured with different EDDs/templates, etc. I can understand your hesitation, but if you insert a lot of these elements and variables, the small trouble of changing script settings could be paid back quickly and continually.

 

One way you could make it more convenient is to always make your Element names match the corresponding user variable names. Then the script just has to check if a variable exists that matches particular element that the user is inserting.

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
Community Expert ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

I actually think my solution is the best white, upside-down tulip 🙂

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 ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

LATEST

I do like your solution the best. I am typically in favour of automating things as much as possible. I'm just not a big fan of customisation in order to change a product's behaviour to make it do something it wasn't designed to do.

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