Scripting notes, 2023

Next
 From:  bemfarmer
10932.1 
After spending an hour or two trying to get AssignPresetName script to work with MoI4 and MoI5beta, I finally downloaded Pilou's French version, which worked just fine.
Then the versions I had struggled with, starting working. I wonder if there is some sort of Caching going on with my computer? I also think that Microsoft oneDrive perhaps should not be used while working on scripts? There is a several minute delay between work and home computers updating saved script versions.
Yesterday I had to replace the cmos battery in the computer at home. The clock kept stopping, and files were back-time dated, at home. And once, the improper time prevented logon to MoI forum.

Next came naming an object in a script.

Name that point, (and style it RED):

code:
function CreatePoint( xValue, yValue, zValue, ptName )
{
	var pt = moi.vectorMath.createPoint( xValue, yValue, zValue );
	var factory = moi.command.createFactory( 'point' );
	factory.setInput( 0, pt );
	var ptObj = factory.calculate();
	if ( !ptObj )
		return false;
	ptObj.setProperty( 'name', ptName ); // Name the point.	
	var point = ptObj.item(0);

var g_style_index = 1;// This Style MAY be red.	
point.styleIndex = g_style_index;
// All the points created ended up Style RED.  	
	
	return point;
}

	// Create pointA
	var xValue = 1;
	var yValue = 2;
	var zValue = 0;
	var ptName = 'pointA';
	var pointA = CreatePoint( xValue, yValue, zValue, ptName );
	moi.geometryDatabase.addObject( pointA );



The Style code was just a lark, and different Styles could be fed to the subroutine function.

- Brian

I suppose there is some way to script assigning an object to a group...

EDITED: 29 Dec 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10932.2 In reply to 10932.1 
Hi Brian, yes by default scripts are only loaded into memory once and cached for subsequent runs.

There's a link to how to disable that here:
https://moi3d.com/wiki/Scripting

re:
> I suppose there is some way to script assigning an object to a group...

You can do it by creating a new group using the group factory, check out Group.js for an example.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Larry Fahnoe (FAHNOE)
10932.3 In reply to 10932.1 
Hi Brian,

Re: styles

Here's how I got the style colors for later use in some debugging (I wanted colored point as well!):

code:
var debugRedStyle;
var debugGreenStyle;
var styles = moi.geometryDatabase.getObjectStyles();
for ( var i = 0; i < styles.length; i++)
{
    if ( styles.item( i).name == 'Red')
        debugRedStyle = styles.item( i).index;
    if ( styles.item( i).name == 'Green')
        debugGreenStyle = styles.item( i).index;
}


--Larry
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10932.4 
Thankyou Michael and Larry.

Today I managed to create and name pointD, which does not show up in the Geometry. It seems to be "everywhere", but cannot be seen on the screen.

In the objects box, selecting the name pointD shows 1.#QNAN00 X 1.#QNAN00
which I guess means "no such number" or something.
The math equation of the point coordinates must be generating a non-number...(?)

Anyway:

Mouse scroll box of any blank area of the screen indicates that pointD has been selected.

Mouse scroll box select of any other point showing on the screen, shows there to be one extra point.
Mouse point selection, of say pointA, and hiding it, gets rid of the dot on the screen. (But blank area selection there still indicates (invisible) presence of pointD.

Weird result...

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Michael Gibson
10932.5 In reply to 10932.4 
Hi Brian, the 1.#QNAN00 is "not a number":
https://en.wikipedia.org/wiki/NaN

Usually it's the result of a division by zero. So probably something's not right with the calculation.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All