Scripting the Trim command  1-20  21-32

Next
 From:  bemfarmer
8786.1 
Hi Michael,
In a script, I'm selecting a cone base edge, getting start point, and arraying it.
Then an object list is made of all of the points, which took morning alertness to accomplish :-)
All of the points of the object list can be added to the Geometry Database.
Then a Trim is attempted, without success.
Code is a mix of LineWeb and BlendCap. The BlendCap trim code just doesn't work for me.
(It is so easy, interactively.)
Maybe tomorrow morning a fresh start will work :-)

Is there something special that needs to be done to Trim a planar edge curve with multiple points, in script?

I can post some code later, or study the Trim.js more :-)

- Brian

Maybe I'm using the wrong kind of points...

EDITED: 13 Jan 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
8786.2 In reply to 8786.1 
Hi Brian, the Trim factory is a little awkward to script because it's heavily based on the workflow of the Trim command and has a couple of custom methods that need to be called. Here's an example though that makes a line curve and a point and trims the line. Let me know if trimming an edge instead of a curve isn't working.

code:

var linefactory = moi.command.createFactory( 'line' );
linefactory.setInput( 0, moi.vectorMath.createPoint(0,0,0) );
linefactory.setInput( 1, moi.vectorMath.createPoint(10,0,0) );
var linelist = linefactory.calculate();

var pointfactory = moi.command.createFactory( 'point' );
pointfactory.setInput( 0, moi.vectorMath.createPoint(8,0,0) );
var pointlist = pointfactory.calculate();

/*
Trim factory inputs:

0: ObjectList - Objects to trim.
1: ObjectList - Cutting objects.
2: ObjectList - Selected fragments to keep or remove, can be an empty list to keep all fragments but it can't be left just unset.
3: String - Mode, "remove" or "keep"
4: Boolean - Extend lines
5: Boolean - Use projected intersections
6: List - Optional list of picked points for curve trimming, used by the "Add trim points" function in the Trim command.
*/

var trimfactory = moi.command.createFactory( 'trim' );

trimfactory.setInput( 0, linelist );
trimfactory.setInput( 1, pointlist );
trimfactory.setInput( 2, moi.geometryDatabase.createObjectList() );

/*
Note - the trim factory is heavily based on the trim command workflow and works a little
different than the standard behavior. You need to call the custom functions
.generateFragments() and finishedPickingFragments() for it to finish and because of
the .generateFragments() step puts objects in the geometry database it won't work to
call calculate() to generate "loose" objects that aren't in the geometry database as
is normally possible.
*/

trimfactory.generateFragments();
trimfactory.finishedPickingFragments();

trimfactory.update();

var objs = trimfactory.getCreatedObjects();
moi.ui.alert( objs.length + ' objects created' );

trimfactory.commit();



- 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:  bemfarmer
8786.3 In reply to 8786.2 
Thank you Michael!

I'll check your code out, and hopefully incorporate it into a new unwrap/net script.

- 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
Next
 From:  Cemortan_Tudor
8786.4 
thanks !
  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
8786.5 
I'm getting some positive results with edges and curves !!!
I'll post something after more work and cleanup...
- B
  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
8786.6 
The script TrimCurveTEST chops up one curve or one edge into multiple equal length segments. The curves can be open or closed.

The script is not completely polished. Names are left as remnants. There is some difference in naming standalone curves, versus edges.
Selecting edges will first need a click on the associated surface.
There is no option to remove FINAL points. Without seeing the points, the chopped up curve/edge segments cannot be seen, unless selected.

Current help, and past help, from Michael was used.

The script is in the TESTING phase, and seems to work well, in both MoI3 and MoI4Dec2018beta.

I needed the code of the script for my Oblique Elliptical or Circular cone Unwrap (Net) project.

Included is a test .3dm of some objects, with open and closed curves and edges.
Right click can reactivate the script.

- Brian

One big question is whether or not Trimmed segments are saved, or recoverable, in ORDER.
If the Order is "random," using the segments will be a problem.

Updated version 07 located in post #13.

EDITED: 16 Jan 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
8786.7 In reply to 8786.6 
Hi Brian, that's great!

re:
> One big question is whether or not Trimmed segments are saved, or recoverable, in ORDER.
> If the Order is "random," using the segments will be a problem.

For a curve trim the trimmed pieces should be generated in order from the start of the curve to the end of the curve.

- 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:  bemfarmer
8786.8 In reply to 8786.7 
Thank you Michael!
- 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
Next
 From:  Cemortan_Tudor
8786.9 
so easy to read with comments :)
  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:  yakas
8786.10 
I was searching for a way to add a shortcut for just "add trim point" and this result came back, but when I click on it it takes me to another post:

MoI discussion forum > Add Trim Point | Hotkey
Hello everyone. Hope all is well and that your CAD journey is rewarding. Anyone knows how one could make a hotkey for the Trim -> Add Trim Point command? Bests, -J. EDITED: 18 Oct 14:41 by BERUBE. Image Attachments: Size: 475.4 KB, Downloaded: 14 times, Dimensions: 1427x748px ...
moi3d.com/forum/messages.php?webtag=MOI


Anyway, I can't find the above post so is it possible to have a hotkey just jump right into adding trim points on a selected curve?

Thanks
  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
8786.11 In reply to 8786.10 
Hi yakas,

re:
> Anyway, I can't find the above post so is it possible to have a hotkey just jump
> right into adding trim points on a selected curve?

It's possible in the v4 beta - there's a new mechanism in v4 for automatically activating UI controls within a command. For "Add trim points" put this on a shortcut key:

Trim addtrimpoints

That will automatically push the "Add trim points" button when it shows up.

Some other ways to control the Trim command are:

Trim addtrimpoints removekeepmode=keep

Trim addtrimpoints removekeepmode=remove

Trim isocurve isodir=u

Trim isocurve isodir=v

- 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:  bemfarmer
8786.12 
A bit of "polishing" of the TrimCurve script is working out, removing segment names upon Done button pushed, (code from BlendCap), but work is not done yet.
Have not yet been able to remove names when delete button is pressed.

For some unknown reason, Naming is working better now.

It is nice to Comment out the Alert window in the code.

When using the script, it is helpful to (click) activate the Objects Tab in MoI. Then the segments can be selected, while still in the script...

- 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
Next
 From:  bemfarmer
8786.13 In reply to 8786.12 
Version 07, polished up quite a bit.

Handling of Standalone Curves is sometimes different that for Edges.

Object Names seem to be a bit persistent. They come back with Undo History.

- Brian

Edit 1/18/2018

Here is the re-posted script.
I deleted a few comments. The script is nearly the same as version07.

EDITED: 18 Jan by BEMFARMER

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:  bemfarmer
8786.14 In reply to 8786.13 
Something peculiar is going on when copying different versions of a script to the MoI command directory, and using customUI.

A functional script named _TrimCurve07.js, and .htm is in MoI's command directory.

A copy of the script named "_TrimCurve07 - Copy" is modified a little bit, with a missing "curve" variable, and copied to the MoI command directory.
The - Copy (seems) to run in MoI

If the defective "_TrimCurve07 - Copy" is renamed to "_TrimCurve08" it does not work.

So the lesson is do not use " - Copy" versions when testing.

This happened a couple of months ago... when this "crazy" behavior was first encountered.
This example is on a different computer...

- Brian

(See next post.)

EDITED: 18 Jan 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:  bemfarmer
8786.15 In reply to 8786.14 
Okay, here is a very simple example of a version of the problem with Somescript - Copy.js, which is created in Windows7, 3rd option when copy pasting a script into MoI's command folder, using the _Angle.js script.

Copy _Angle.js from the command folder, to the command folder, using Windows7 3rd paste option, which yields _Angle - Copy.js.
Do not copy _Angle.htm.

Copy _Angle.js again, and rename copy to _AngleSecondCopy.js,
and do not copy _Angle.htm to _AngleSecondCopy.htm.

_Angle - Copy (seems) to run fine.
_AngleSecondCopy will not run correctly.

- Brian

Using TAB and MoI's command entry window line, has the same behavior.

(Revised) conclusion, MoI does not recognize _Angle - Copy.js. Instead MoI just runs _Angle.js. (???)

(A reminder to myself, not to jump to conclusions, there could be another explanation:-)

EDITED: 18 Jan 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
8786.16 In reply to 8786.15 
Hi Brian - you can't have spaces in command names. That's because of being able to have command line parameters sent as well, which are separated by a space from the command name.

So for example if you set up a shortcut key with: SaveAs c:\temp\test.obj , it won't try to run a command script of "SaveAs c:\temp\test.obj.js" , it runs SaveAs.js and the c:\temp\test.obj after it is a command line parameter to the SaveAs command.

Similarly if you try to run "Somescript - Copy" it's going to look for Somescript.js and the "- Copy" will be a command line parameter, not part of the command name.

- 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:  bemfarmer
8786.17 In reply to 8786.16 
Michael, thank you very much for the explanation.

When testing scripts, so as not to overwrite a version, I sometimes used the 3rd option on the copy/paste, which has the not-allowed spaces.
I'll stop doing that :-)

I wonder if there is some version control software that uses notepad++?

- Brian

Google of "version control with notepad++ is getting some hits. I'll do some more reading...
  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
8786.18 
I somehow managed to create an open curve which has strange behavior.
Running _TrimCurve on it with a setting of 8 segments, results in 7 segments.
One of the 7 segments is of double length. It failed to divide.
Multiples of 8, such as 16, 24, and 32 also fail to divide all of the segments. Approximately 1 or 3 segments are lacking.

This strange curve, as an open cone, came up while testing _ObliqueConeUnwrap script, which works for a right circular cone, but not for
an oblique cone, (yet). :-) The shape of the Net is not quite right...

- Brian
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
8786.19 In reply to 8786.18 
Hi Brian,

re:
> I somehow managed to create an open curve which has strange behavior.

Looks like this is a tolerance related bug in the Trim command, on this particular curve it's ending up using too tight of a tolerance which makes it think that point was not on the curve.

I've got it tuned up for the next v4 beta so it should work ok then. Thanks for posting the file!

- 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:  bemfarmer
8786.20 In reply to 8786.19 
Hi Michael,

Thank you.

Is it possible to fix in MoI3?
Or is the "tolerance bug" in the C++ Trim factory?

MoI4beta seems to be working very well overall, so one of these days I'll move over to version 4!

- Brian

With _TrimCurve test script, on higher powers of 2, or 8, such as 512, 1024, and even 512+1024, the segment count is 3 short.
In either MoI3 or MoI4Dec2017beta. At these "high" point counts, MoI3 has a several second lag in Done completion,
MoI4Beta is very fast.

Testing with stock Trim command in MoI3 or MoI4DecBeta, show the "bug," for this particular curve. Other open curves work just fine.

Scaling the curve, 2X, also shows the "bug," But a new arc "on top of it," does not show the bug.

EDITED: 23 Jan 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
 

Reply to All Reply to All

 

 
Show messages:  1-20  21-32