Jump to content
Sign in to follow this  
minimalaco

problem importing wordltools SQM

Recommended Posts

Hi all.

when you import a sqm in wordltools, objects do not appear to match that are placed on the editor.

There is an option that says: GET SCRIPTS FOR V3, but when I press that option, throw error.

where I get the modified script?

Share this post


Link to post
Share on other sites

Why not post in the world tools thread? This way shezan would see it most easily. :)

Share this post


Link to post
Share on other sites

it's strange... i'll check for this issue and i'll add the script here.

Share this post


Link to post
Share on other sites

Thanks shezan !

whf12.jpg

Edited by Minimalaco

Share this post


Link to post
Share on other sites

this happens when you click on Get Script for V3?

probably the script extension is mapped with Visitor 3 and the application tries to open the V3.exe...

Here the script, it's also saved in your personal settings folder (where WT saves settings and other infos):

// *************************************************************************************************************
// Copyright (C) 2007 Bohemia Interactive
// *************************************************************************************************************
// This script is free software for any non commercial use; you can redistribute it and/or modify as long as you
// include this licensing notice. This script is distributed in the hope that it will be useful, but without any
// warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
// *************************************************************************************************************
//
// ImportObjectsAbsHeight.vis
//
// *************************************************************************************************************
// This script allows to load objects from file using absolute height. 
// *************************************************************************************************************
// This script expects to read an ascii file (no matter what extension) with the following format of records
// (colon separated data):
// "templatename";X;Y;Z;orientation;
// example:
// "misc\water_tank";12064.1;17650.2;-0.841085;0;
// *************************************************************************************************************
// This script reads the file and inserts in the current document all the object whose template is already in the
// document. All the other objects are rejected.
// The number of inserted and rejected objects is shown when the script ends running.
// *************************************************************************************************************
// In the current implementation the script doesn't do any validation of the numerical values expected from the
// file (X, Y, Z and orientation).
// *************************************************************************************************************
// In the current implementation the script uses the current setDir function, which works with opposite 
// orientation than the getDir function [for this reason orientations are considered with the minus (-) sign.]
// *************************************************************************************************************

// ---------------------
// functions definitions
// ---------------------

// **********************************************************************************************************
// GetNaturalTemplateNamesInDoc
// **********************************************************************************************************
GetNaturalTemplateNamesInDoc =
{
private["_doc", "_templates", "_templateNames"];

// gets the document
_doc = _this;

// gets 'natural' templates in the document
_templates = _doc getObjectTemplates "natural";
_templates sortBy {getName(_x) strCmp getName(_y)};

// core - gets template names
_templateNames = [];
{
	_templateNames = _templateNames + [getName _x];
} forEach _templates;

// return value
_templateNames
};


// **********************************************************************************************************
// GetArtificialTemplateNamesInDoc
// **********************************************************************************************************
GetArtificialTemplateNamesInDoc =
{
private["_doc", "_templates", "_templateNames"];

// gets the document
_doc = _this;

// gets 'artificial' templates in the document
_templates = (_doc getObjectTemplates "artificial");
_templates sortBy {getName(_x) strCmp getName(_y)};

// core - gets template names
_templateNames = [];
{
	_templateNames = _templateNames + [getName _x];
} forEach _templates;

// return value
_templateNames
};


// **********************************************************************************************************
// WarningDialog
// **********************************************************************************************************
WarningDialog =
{
private["_type", "_title", "_messageRow1", "_messageRow2", "_dlgWarning", "_result"];

// gets the type of warning
_type = _this;

// sets title and message
_title = "";
_messageRow1 = "";
_messageRow2 = "";
switch(_type) do
{
	case 1:
 		{
			_title = "Warning - No area selected.";
			_messageRow1 = "This script requires that you select an area before you run it.";
			_messageRow2 = "Please select an area and then rerun the script.";
 		};
	case 2:
	 	{
			_title = "Warning - No templates in document.";
			_messageRow1 = "This script requires that templates are already in the document.";
			_messageRow2 = "Please define the needed templates and then rerun the script.";
	 	};
	default
	 	{
			_title = "Warning - Error in dialog setting";
			_messageRow1 = "Error in WarningDialog function.";
	 	};
}; 

// sets dialog
_dlgWarning = [220, 55, _title,
	    	  ["label", 200, 13, _messageRow1, 0], ["break"],
    		  ["label", 200, 13, _messageRow2, 0], ["break"],
    		  	  ["ok-button", 50, 13]];

// shows the dialog
_result = dialogBox _dlgWarning;

// return value
_result
};


// **********************************************************************************************************
// ErrorDialog
// **********************************************************************************************************
ErrorDialog =
{
private["_type", "_title", "_messageRow1", "_messageRow2", "_dlgError", "_result"];

// gets the type of warning
_type = _this;

// sets title and message
_title = "";
_messageRow1 = "";
_messageRow2 = "";
switch(_type) do
{
	case 1:
 		{
			_title = "Error in script execution";
			_messageRow1 = "Error in opening the specified file.";
	 	};
	case 2:
 		{
			_title = "Error in script execution";
			_messageRow1 = "Bad data format in the specified file.";
	 	};
	default
	 	{
			_title = "Warning - Error in dialog setting";
			_messageRow1 = "Error in ErrorDialog function.";
	 	};
}; 

// sets dialog
_dlgError = [220, 55, _title,
	      ["label", 200, 13, _messageRow1, 0], ["break"],
      	["label", 200, 13, _messageRow2, 0], ["break"],
   			["ok-button", 50, 13]];

// shows the dialog
_result = dialogBox _dlgError;

// return value
_result
};

// **********************************************************************************************************
// SetTemplatesList
// **********************************************************************************************************
SetTemplatesList =
{
private["_params", 
	  "_naturalTemplsInDoc", "_artificialTemplsInDoc", 
	  "_templateNames"];

// gets the params
_params = _this;
_naturalTemplsInDoc    = _params select 0;
_artificialTemplsInDoc = _params select 1;

// core - gets template names
_templateNames = [];

_templateNames = _naturalTemplsInDoc;		 
_templateNames = _templateNames + _artificialTemplsInDoc;		 

// return value
_templateNames
};


// **********************************************************************************************************
// ParseLine
// **********************************************************************************************************
ParseLine =
{
private["_line", "_pos", "_name", "_XX", "_YY", "_ZZ", "_orient", "_result"];

// gets the line to parse
_line = _this;

_name = "";
_XX = "";
_YY = "";
_ZZ = "";
_orient = "";

// core - parse the line

// first gets object template name
_pos = _line find ";";
if (!isnil "_pos") then
{
	_name = _line @ [0, _pos];

	// then gets object X coord
	_line = _line @ [_pos + 1];
	_pos = _line find ";";
	if (!isnil "_pos") then
	{
		_XX = _line @ [0, _pos];

		// then gets object Y coord
		_line = _line @ [_pos + 1];
		_pos = _line find ";";
		if (!isnil "_pos") then
		{
			_YY = _line @ [0, _pos];

			// then gets object Z coord
			_line = _line @ [_pos + 1];
			_pos = _line find ";";
			if (!isnil "_pos") then
			{
				_ZZ = _line @ [0, _pos];

				// finally gets object orientation
				_line = _line @ [_pos + 1];
				_pos = _line find ";";
				if (!isnil "_pos") then
				{
					_orient = _line @ [0, _pos];
				}
				else    // bad data format orientation
				{
					// shows error dialog
					_errorNum = 2;
					_errorNum call ErrorDialog;
				};
			}
			else    // bad data format Z
			{
				// shows error dialog
				_errorNum = 2;
				_errorNum call ErrorDialog;
			};
		}
		else    // bad data format Y
		{
			// shows error dialog
			_errorNum = 2;
			_errorNum call ErrorDialog;
		};
	}
	else    // bad data format X
	{
		// shows error dialog
		_errorNum = 2;
		_errorNum call ErrorDialog;
	};
}
else    // bad data format name
{
	// shows error dialog
	_errorNum = 2;
	_errorNum call ErrorDialog;
};

// sets the result
_result = [];
_result = _result + [_name];
_result = _result + [_XX];
_result = _result + [_YY];
_result = _result + [_ZZ];
_result = _result + [_orient];

// return value
_result
};


// ---------------------------------
// internal variables default values
// ---------------------------------
_scriptName                    = "Import Objects using absolute height 1.0.0";
_naturalTemplateNamesInDoc     = [];
_artificialTemplateNamesInDoc  = [];
_nNaturalTemplateNamesInDoc    = 0;
_nArtificialTemplateNamesInDoc = 0;
_fileName                      = "";
_insCounter                    = 0;    // counter for inserted objects
_rejCounter                    = 0;    // counter for rejected objects


echo "-----------------";
echo "ImportObjects.vis";
echo "-----------------";

// ------------------------
// gets the active document
// ------------------------
_doc = getActiveDoc;    

// ------------------------------
// gets the templates in document
// ------------------------------
_naturalTemplateNamesInDoc = _doc call GetNaturalTemplateNamesInDoc;
_artificialTemplateNamesInDoc = _doc call GetArtificialTemplateNamesInDoc;
_nNaturalTemplateNamesInDoc = count _naturalTemplateNamesInDoc;
_nArtificialTemplateNamesInDoc = count _artificialTemplateNamesInDoc;

// --------------------
// verify the templates 
// --------------------
_thereAreNaturalTemplateNames = false;
if(_nNaturalTemplateNamesInDoc > 0) then
{
_thereAreNaturalTemplateNames  = true;
};

_thereAreArtificialTemplateNames = false;
if(_nArtificialTemplateNamesInDoc > 0) then
{
_thereAreArtificialTemplateNames = true;
};

// -----------------------
// sets the templates list
// -----------------------
_templatesList = [_naturalTemplateNamesInDoc, _artificialTemplateNamesInDoc] call SetTemplatesList;

// -------------------
// dialogs definitions
// -------------------

_dlgInput = [330, 60, _scriptName,
	["init",
		  {
			_id = 1;
			_id dlgEnableControl false;
		  }],
	["begin-subframe", 320, 30, " Source file "],
	    	["label", 40, 13, "File name:", 0], 
	    	["textline", 220, 13, "_fileName", 4], 
		["onchange",
				{
					if((count _fileName) != 0) then
					{
						_id = 1;
						_id dlgEnableControl true;
					}
					else
					{
						_id = 1;
						_id dlgEnableControl false;
					};
				}],
		["browse-button", 40, 13, "All files|*.*|", false, "Open file"], ["break"],
	["end-subframe"], ["break"],
	["ok-button", 50, 13], ["cancel-button", 50, 13]];


_dlgOutput = [220, 80, _scriptName,
	 ["dynlabel", 200, 13, "_insCounter", 2], ["break"],
	 ["label", 200, 13, "objects imported", 2], ["break"],
	 ["dynlabel", 200, 13, "_rejCounter", 2], ["break"],
	 ["label", 200, 13, "objects rejected", 2], ["break"],
		 ["ok-button", 50, 13]];

// -----------
// script core 
// -----------

if(_thereAreNaturalTemplateNames || _thereAreArtificialTemplateNames) then    // there are templates in document   
{
// shows the input dialog
_res = dialogBox _dlgInput;

if(_res == 1) then
{
	// open the input file
	_file = openFile [_fileName, 1]; 

	if (!isnil "_file") then    // file has been found
	{
		// gets data from file
		while{!eof(_file)} do
		{
			//get next record from file
			_line = getLine _file;

			if((count _line) > 0) then    // not empty line
			{					
				_data = _line call ParseLine;		

				_name   = _data select 0;
				_coordX = _data select 1;
				_coordY = _data select 2;
				_coordZ = _data select 3;
				_orient = _data select 4;

				//
				// data conversion
				//

				// template name
				_len = count _name;
				_name = _name @ [1, _len - 1];

				// converts to numbers coordinates
				_xP = val (_coordX);     //  MISSING
				_yP = val (_coordY);     //  ERROR CHECKING
				_zP = val (_coordZ);     //  

				// object orientation

				// converts to number
				// WARNING
                             // uses the minus sign because there is a bug in the visitor
				// scripting language
				_orP =  -val (_orient);     //  MISSING ERROR CHECKING

				// finally creates the imported object 
				if(_name in _templatesList) then    // template recognized
				{
					// cretes new object
					_obj = _doc createPosEdObject _name; 

					// sets object position
					_insPos = [_xP, _yP];				
					_obj setPos _insPos;  

					// sets object relative height
					//_obj setRelHeight _zP;





					_pos = getZeroPos _obj; 
					_landHeight = (_doc getLandHeight _pos) select 0; 
					_offset = _zP - _landHeight;
					_obj setRelHeight _offset; 





					// sets object orientation
					_obj setDir _orP;  

					_insCounter = _insCounter + 1;
				}
				else    // template not recognized
				{
					_rejCounter = _rejCounter + 1;
				};
			};
		};
		// shows the output dialog
		_result = dialogBox _dlgOutput;
	}
	else
	{
		// shows error dialog
		_errorNum = 1;
		_errorNum call ErrorDialog;
	};
};

}
else    // no templates in document
{
// shows warning dialog
_warningNum = 2;
_warningNum call WarningDialog;
};

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×