Shrink trimmed srf reloaded
All  1-6  7-17

Previous
Next
 From:  Karsten (KMRQUS)
7983.7 In reply to 7983.3 
Hello,

maybe something like that:
function sTrSrf(){
var objs = moi.geometryDatabase.getSelectedObjects();
var objsSel = moi.geometryDatabase.createObjectList();

for ( var i = 0; i < objs.length; ++i )
{
objsSel.addObject(objs.item(i));
}

var factory = moi.command.createFactory( 'shrinktrimmedsrf' );
factory.setInput( 0, objs );
var xxx=factory.calculate();
factory.cancel();
moi.geometryDatabase.removeObjects(objs);
moi.geometryDatabase.addObjects(xxx);

xxx.item(0).selected=true;
}
sTrSrf();

Have a nice day
Karsten
  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:  Karsten (KMRQUS)
7983.8 In reply to 7983.3 
or shorter and for multiselection:

// config: norepeat noautolaunch
function sTrSrf(){
var objs = moi.geometryDatabase.getSelectedObjects();
var factory = moi.command.createFactory( 'shrinktrimmedsrf' );
factory.setInput( 0, objs );
var xxx=factory.calculate();
factory.cancel();
moi.geometryDatabase.removeObjects(objs);
moi.geometryDatabase.addObjects(xxx);
for(var i=0; i<xxx.length;i++)xxx.item(i).selected=true;
}
sTrSrf();
  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
7983.9 In reply to 7983.7 
It works!

It seems that the factory changes the nature of the object, so it must be deleted and substituted for.

- Brian (I was trying .calculate and making a duplicate object, but had not got a solution :-)
  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
7983.10 In reply to 7983.1 
Hi Marco,

> I've written a modified version of the "shrinktrimmedsrf" command, that should simply select again all
> the input objects at the end of the job.
>
> Why it doesn't work ? Am i missing something ?

The way shrinktrimmedsrf works is that it deletes the input objects and inserts new objects that have been shrunk. The original input objects are no longer in the geometry database after the factory has run, that's why you are not getting them selected.

If you want to keep the input objects, you'd need to call factory.calculate() (like Karsten shows above) that just generates the output objects (which are not in the geometry database, you would need to add them in yourself if you want them to appear) and does not disturb the input objects. Basically running factory.commit() will make things behave the same as the regular ShrinkTrimmedSrf command, which removes the original object and replaces it with a new shrunken one.

Or did you mean you wanted to select the _output_ objects, not the input objects like you wrote?

- 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:  mkdm
7983.11 In reply to 7983.10 
Hi Michael, Karsten and bemfarmer,

Thank you all for your help!!
Thank you very much Karsten for your code!

> The way shrinktrimmedsrf works is that it deletes the input objects and inserts new objects that have been shrunk.
> The original input objects are no longer in the geometry database after the factory has run, that's why you are not getting them selected.

I didn't know this behavior!

> Or did you mean you wanted to select the _output_ objects, not the input objects like you wrote?

Yes, you're right...i meant to say ...the output objects.

Here's my version of the script.

It differs from Karsten's version, only for the code that select the output objects.


I used :

code:
shrunkObj.setProperty("selected", 1);


The .3dm file contains a unjoined solid made by trimmed surfaces.

If you want to make a test, select all the surfaces and run ShrinkTrimmedSrfAutoSel command.

Now i want to write a version of the script that automatically should do the following steps :

1) unjoin all the selected objects
2) do the same job of ShrinkTrimmedSrfAutoSel
3) join back all the selected surfaces

So, if you select some solid that is made by trimmed surfaces, running this command, you will otbtain a shrunked version of the input solids.

At least, i hope to do so....

Nice night!

Marco (mkdm).

  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
7983.12 In reply to 7983.11 
Hi Marco, well the regular ShrinkTrimmedSrf command can be used on a solid already, if you select a solid before you run it, it will shrink all the surfaces of that solid and the output object will remain a joined solid.

If you want to have the output object selected you can change the ShrinkTrimmedSrf.js command to this instead:

code:
// config: norepeat noautolaunch

var factory = moi.command.createFactory( 'shrinktrimmedsrf' );
factory.setInput( 0, moi.geometryDatabase.getSelectedObjects() );

factory.update();
var objs = factory.getCreatedObjects();
factory.commit();

objs.setProperty( 'selected', true );



- 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:  mkdm
7983.13 In reply to 7983.12 
Wow Michael,

that's exactly what i wanted !!!

So...the trick is :

code:
factory.update();
var objs = factory.getCreatedObjects();


before factory.commit().

Good to know!

Grazie mille!

Marco (mkdm).
  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
7983.14 In reply to 7983.13 
Hi Marco, yup once you call .commit() the factory is all done and all its internal lists of objects are cleared out, basically it's not expecting anything more to be done with it after .commit() . So because of that you need to call .getCreatedObjects() before .commit() but also after .update() has been called to make the output be generated.

I could probably change some of this in v4 to make it a bit more friendly, like if you call .getCreatedObjects() and .update() has never been called, I could probably do the update for you and maybe it would be good for the factory to retain its lists of objects even after .commit() so you could retrieve them after the commit instead of only before.

- 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:  mkdm
7983.15 In reply to 7983.14 
Hi Michael,

Thank you very much for these clarifications!

> I could probably change some of this in v4 to make it a bit more friendly

I'm confident that your v4 Api will be more friendly and powerful, and i hope that will supply some Object Model
to access and operate on the objects' topology (control points, etc...).

Please let me ask one more question...

I'm trying to write a node for NodeEditor, that should be a modified version of "planarsrf" command,
that should return in output only the "caps" surfaces eventually generated ?

Can i apply the same logic that you have explained for the ShrinkTrimmedSrf command ?

That is, call .update() and than .getCreatedObjects() before .commit() ?
Or i must call .calculate(), than .getCreatedObjects(), and than . cancel() ?

Or it's a totally different thing ?

Thank you very much and have a nice day,

Marco (mkdm).
  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
7983.16 In reply to 7983.15 
Hi Marco, well there are 2 different ways PlanarSrf can be used. If you have curves selected it will build just a planar surface through those curves, if you only want the surface itself you would probably want to use it this way. The other way it can be used is if you select an entire joined surface object with holes in it - when you run it this way it will build the planar surfaces through naked edges that form closed planar loops and also join them with the main object. When run this second way the output object is not going to be just the planar surface, it's the whole entire joined object.

So if you want only the planar surfaces it would probably be good to give PlanarSrf curves for its input objects and then you should be able to do the .update() .getCreatedObjects() .commit() sequence.

- 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
 From:  mkdm
7983.17 In reply to 7983.16 
Hi Micheal,

Thank you for these explanations.

I am going to try and put these explanations into practice.

Nice day,

Marco (mkdm).
  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-6  7-17