JSON - Dynamic Modification of Variables in Drawing
Online Demo Link
Try out this CADViewer Dynamic Modification Variables using JSON Sample on our onlinedemo.cadviewer.com server. Make sure to allow pop-up’s in your web-browser for this server.
About This Sample
This CADViewer sample uses the AutoXchange 2020 interface for JSON variables, where text strings defined either as %%%variable%%% or $$$variable$$$ can be identified and replaced with custom content.
This CADViewer sample uses the Url parameter interface to pass over parameters to set the Print Modal to activate the controls:
- Add a Checkbox to activate JSON when calling AutoXchange: print_modal_custom_checkbox=add_json
- Add a Textfield to be able to enter the text to replace with variable names. Variable names are comma-separated: print_modal_variable_replacement=variable1,variable2,variable3
- A variable can be prepended with a text-string, use the syntax {prependvariable:CADVIEWER-SK-} as the variable expression. Where the variable itself is listed before the “:” symbol, and the text string to be pre-pended is listed behind the “:” symbol
URL parameters
The URL parameter call is (the Url and exact file-paths will change depending on the implementation platform):
https://onlinedemo.cadviewer.com/cadviewer_6_1_0/html/CADViewer_jsonstrings_610.html?drawing_name=https://onlinedemo.cadviewer.com/cadviewer_6_1_0/content/drawings/dwg/base_xref_json.dwg&print_modal_custom_checkbox=add_json&print_modal_variable_replacement=titlevariable,{prependvariable:CADVIEWER-SK-}
Please see Load Parameters from URL on the internal API call to retrive the URL parameters.
Variables in Drawing
The sample drawings consists of a base drawing base_xref_json.dwg which in turn loads in two external references ( Xref’s) , where the Xref’s are placed in the same server folder as the base drawing.
The drawing in this sample has two variables, $$$titlevariable$$$ and $$$prependvariable$$$ defined.
When activating Print Title Block the content of the Textfield is passed over in a JSON file to AutoXchange 2020 to modify the variables $$$titlevariable$$$ and $$$prependvariable$$$ in the PDF the Output.
Alternative to URL parameters
Variable settings through API
As an alternative to passing over the Variables Parameters through an URL parameter, if the $$$ variables strings can be set through the API interface:
The API methods to set the Print Modal for Variable Parameter input are below. Note that in the case of two variables only, users can choose to set a separate text-box for each variable, cvjs_setPrintModalCustomDualTextBox(). This method call is mutually exclusive to the general cvjs_setPrintModalCustomTextBox() call.
Loading configuration file through API
The variable settings configuration files can directly be loading in using API commands. The files must be located in the /cadviewer/app/cv folder. This is useful in drawings are static in nature, for example if the $$$ are part of a Title Block Frame, that are read in as an External Reference and thus has the same content over entire libraries of drawings.
The API methods to set the Print Modal for Variable Parameter input through a configuration file are below. Note that in the case of two variables only, users can choose to set a separate text-box for each variable, cvjs_setPrintModalCustomDualTextBoxFromFile(). This method call is mutually exclusive to the general cvjs_setPrintModalCustomTextBoxFromFile() call.
Code sample:
CADViewer Operation
Choose the following settings for CADViewer Print Modal and Print:
In Adobe Acrobat, zoom into the PDF Output to verify the Variable content has been dynamically changed:
Source Code
The Source file for CADViewer_jsonstrings_610.html is:
Please also visit our comprehensive Online CADViewer Demos section with other File Demos with both CADViewer 6.1, CADViewer 4.1 and AutoXchange 2020