Script request, center cplane on export
All  1-9  10-19

Previous
Next
 From:  Michael Gibson
5461.10 In reply to 5461.8 
Hi Martin, you can leave out the .commit() when you're using .calculate() instead, basically calculate() is an alternate mechanism to the update/commit mechanism.

The never ending calculating loop is because of another quirk of async factories, in order for async factories to work correctly right now objects must have unique ID value generated for them and that happens when they are added to the geometry database.

But when you call .calculate(), the objects are handed back to you and they are not automatically added to the geometry database as they are with the update/commit mechanism. So they won't be visible in the display and also won't get unique IDs assigned to them. Also when you do .calculate() there won't be any input objects removed from the geometry database automatically as well so both the adding and the removing will need to be done manually for that case.

Try this (note the additional calls after .calculate() ):

code:
	/*make cylinder 1*/
	frame = moi.vectorMath.createTopFrame();
	frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
	factory = moi.command.createFactory( 'cylinder' );
	factory.setInput( 1, frame );
	factory.setInput( 3, 30 );
	factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 60 ) );
	factory.update();
	var cyl1 = factory.getCreatedObjects();
	factory.commit();
	
	/*make cylinder 2*/
	frame = moi.vectorMath.createTopFrame();
	frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
	factory = moi.command.createFactory( 'cylinder' );
	factory.setInput( 1, frame );
	factory.setInput( 3, 60 );
	factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 30 ) );
	factory.update();
	var cyl2 = factory.getCreatedObjects();
	factory.commit();
	
	/*cyl2 minus cyl1*/
	moi.geometryDatabase.deselectAll();
	factory = moi.command.createFactory( 'booleandifference' );
	factory.setInput( 0, cyl2 );
	factory.setInput( 1, cyl1 );
	factory.setInput( 2, false );
	var result = factory.calculate();
	moi.geometryDatabase.addObjects( result );
	moi.geometryDatabase.removeObjects( cyl2 );
	moi.geometryDatabase.removeObjects( cyl1 );

	/*make cylinder 3*/
	frame = moi.vectorMath.createTopFrame();
	frame.origin = moi.vectorMath.createPoint( 25, 0, 0 );
	factory = moi.command.createFactory( 'cylinder' );
	factory.setInput( 1, frame );
	factory.setInput( 3, 30 );
	factory.setInput( 4, moi.vectorMath.createPoint( 25, 0, 30 ) );
	factory.update();
	var cyl3 = factory.getCreatedObjects();
	factory.commit();
	
	moi.geometryDatabase.selectAll();
	moi.view.resetAll();
	
	/*result minus cyl3*/
	moi.geometryDatabase.deselectAll();
	factory = moi.command.createFactory( 'booleandifference' );
	factory.setInput( 0, result );
	factory.setInput( 1, cyl3 );
	factory.setInput( 2, false );
	factory.commit();
  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
5461.11 In reply to 5461.8 
Tomorrow I'll try to take a look and see what's involved in making "loose" (meaning not actually a part of the geometry database) objects work as input into async factories, maybe I can also get that tuned up to work.

- 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:  Samuel Zeller
5461.12 In reply to 5461.7 
"When you say create a bounding box and delete the bounding box, do you mean that you want an actual separate box object to be created so that there's a big extra box geometry additionally inserted into your export?"

No

"Or are you just talking about creating a bounding box only as an internal calculation step (not actually creating any box geometry to export) for getting the base point?"

Exactly :)

"If I understand you correctly you want the entire selection to move more all together keeping the pieces in the same relative position and not move each one separately to the origin"

Spot on :D
-- shapenoid.com
  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:  Martin (MARTIN3D)
5461.13 In reply to 5461.10 
Ha, now it works perfectly :-) and your explanations make sense to me. Thanks a lot.

>Tomorrow I'll try to take a look and see what's involved in making "loose" (meaning not actually a part of the geometry database) objects work as input into async factories, maybe I can also get that tuned up to work.

That would mean that, when the script makes a thread for example, the profile and helix created using just .calculate()) will never appear? Also the cutter object and the cylinder would just be .calculated() in the background and just the finished thread pops up after some time like magic?
  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:  Martin (MARTIN3D)
5461.14 In reply to 5461.13 
Two observations:
When using this var = factory.calculate() method for sweep and boolean diff

a) the "Calculating ..." message doesn't apear
b) the calculation terminates after 90 s. It seems that this certain JavaScript protection also kicks in here.
  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
5461.15 In reply to 5461.12 
Hi DesuDeus, please try the attached ExportCentered2 command, hopefully it does what you were wanting.

- Michael
Attachments:

  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
5461.16 In reply to 5461.13 
Hi Martin,

> That would mean that, when the script makes a thread for example, the profile and helix
> created using just .calculate()) will never appear? Also the cutter object and the cylinder
> would just be .calculated() in the background and just the finished thread pops up after
> some time like magic?

Well by the "fixing it" part I meant that I'll see if I can get loose objects (objects that are only referenced by the script engine itself and not added into MoI's geometry database) to work ok as input objects into async factories.

What I was referring to there would not change the behavior of when things appear on screen or not.

And yes, when you use the .calculate() method the result returned back will not by itself automatically appear on the screen - that's because the returned object is only referenced in that case by the script engine - when MoI redraws the screen the things that are drawn are all the stuff that's in it's geometry database, so if you want to have an object actually displayed you need to add it to the geometry database, just adding it will trigger a screen redraw.


> When using this var = factory.calculate() method for sweep and boolean diff
>
> a) the "Calculating ..." message doesn't apear
> b) the calculation terminates after 90 s. It seems that this certain JavaScript protection also kicks in here.

Yes, the .calculate() method is synchronous, it runs directly on the main thread and does not use the worker process mechanism. So that means no "Calculating..." message and also MoI will appear frozen while it is crunching away. It could very well be triggering the script timeout because of that as well, but with the next v3 beta that script timeout will be removed so hopefully that limit will go away with it.

But also in the next v3 beta you will not be forced to use .calculate(), that other .getCreatedObjects() method will pause the script until the async update is complete so with the next v3 release that method you were using previously will work ok with async factories.

- 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:  Martin (MARTIN3D)
5461.17 In reply to 5461.16 
Thanks Michael, I understood that you are just looking. Anyway I went back to my old method. The script is more reliable and - very important - it also works in older MoI versions.
  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:  Samuel Zeller
5461.18 In reply to 5461.15 
Hi,

Tried ExportCentered2

Two things are not working.

1. Once the export in 3DM is done it doesn't revert the centered model (I need to cmd+Z)

2. It doesn't work if I try to output an OBJ, it doesn't display the meshing settings

I need this script specially for exporting to OBJ -> Cinema 4D :)
-- shapenoid.com
  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
5461.19 In reply to 5461.18 
Hi DesuDeus, I just tested ExportCentered2 over here both in Windows and Mac versions and I can't reproduce any of those problems.

How are you installing and running it? Make sure that you are placing it into the \commands folder and to trigger it put in only: ExportCentered2 as the command name, nothing else like "script:" for this case.

- 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

 

 
 
Show messages: All  1-9  10-19