MoI discussion forum
MoI discussion forum

Full Version: Updates to the MoI API of David C Morrill

Show messages:  1-20  21-40  41-47

From: bemfarmer
19 Sep 2022   [#1]
Documentation for more MoI factories could be added to the MoI API, of David C. Morrill.

I took a look with Microsoft Edge browser, View Page Source, at the MoI API, which is in html, at 11465 lines of code.
It was a surprise that the background colors, and the icons were based upon the moi.css file, and images in the moi images directory. etc.
e.g. moi4.0 > ui > moi_ref > moi.css. And also ...moi_ref > images > various icons.
See first 24 lines of the html code.
The documented factories are all separate, and each factories documentation is in a few dozen lines of code +/-.

Next I'll try do do documentation for the "rebuildcurve" factory. That should be fairly easy.

- Brian
From: bemfarmer
19 Sep 2022   [#2]
The rebuildcurve factory has 3 modes, so it may be more understandable to have 3 documentation sections.

For use as a function to refit a curve in a script: (To Be Tested)

code:
function Rebuild( obj, tol, deleteTF )
{
	var factory = moi.command.createFactory( 'rebuildcurve' );	
	factory.setInput( 0, obj ); // object(s)
//	factory.setInput( 0, WrapWithObjectList(obj) );  // Might be needed?
	factory.setInput( 1, 'refit' ); // 'mode'
	factory.setInput( 2, tol );  // default tol = 0.01
	factory.setInput( 4, deleteTF ); // 'Delete input object(s), TrueFalse'
	var rebuilt_obj = curvefactory.calculate().item(0);	
	return rebuilt_obj;	
}	

//  Code not needed for refit_only Rebuild:
//	factory.disableUpdate( true );
//	ui.bindUIToInput( 'mode', 'value', factory.getInput(1) );
//	factory.setInput( 3, 'numpoints' );
//	factory.setInput( 5, 'keepcorners' );
//	factory.setInput( 6, 'breakangle' );
//	factory.disableUpdate( false );





The above code is NOT the API documentation.

The ui.bindUIToInput comes from the rebuildcurve command.

- Brian
From: pressure (PEER)
20 Sep 2022   [#3] In reply to [#1]
Brian,

I've been wishing for an updated reference too. You're message pushed me over the edge and I'm working on it now. We'll see how far I get...

When I add a new row that messes up the table zebra striping since it's done with separate even and odd row classes. Any ideas for automatically redoing the striping?

Also, it makes it hard to do text search when all sections default to "show basic". Any ideas for getting it to default to showing detailed descriptions or even to disable this feature entirely so that detailed descriptions are always shown? I tried changing "var desc_toggle = false;" to "var desc_toggle = true;" at line 24 of moi.js, but that had no effect.
From: Michael Gibson
20 Sep 2022   [#4] In reply to [#3]
Hi Peer,

re:
> When I add a new row that messes up the table zebra striping since it's done with separate even
> and odd row classes. Any ideas for automatically redoing the striping?

Try this:

code:
/*
.odd td {
  background-color: #F0F0F0;
}  

.even td {
  background-color: #E0E0E0;
}
*/ 

tr:nth-child(odd) {
	background-color: #F0F0F0;
}

tr:nth-child(even) {
	background-color: #E0E0E0;
}


- Michael
From: bemfarmer
20 Sep 2022   [#5] In reply to [#3]
Hi Peer,
I am learning as I go, so I do not have much understanding of the html.
I'll have to study your questions tonight :-)

Michael's post seems to have some documentation here:
https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child

This is the first time I ever heard of nth-child()

- Brian
From: pressure (PEER)
20 Sep 2022   [#6] In reply to [#4]
Thanks Michael! That did the trick.
From: bemfarmer
20 Sep 2022   [#7] In reply to [#5]
Hi Peer,

Thank you for your current and future efforts on upgrading the API.

I recall that in various scripts, Michael has documented some of the newer factories, and their inputs.

A list of the newer factories, undocumented in the API, could be made, and the files, or posts, that have any explanations located.

- Brian
An explanation of the API Names and Types would also be nice, due to my limited understanding. As well as examples.
From: bemfarmer
20 Sep 2022   [#8]
The puzzling CSS :nth-child() Selector has a good example at w3schools:

https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_nth-child

So it appears that the CSS :nth-child() Selector can be used in the <style> ... </style> section of the html file.

So hundreds of odd or even statements could be eliminated from the API html ???

- Brian
From: Michael Gibson
20 Sep 2022   [#9] In reply to [#8]
Hi Brian,

re:
> So it appears that the CSS :nth-child() Selector can be used in the <style> ... </style> section of the html file.

Yup, it can go in either a .css file that is included by a <link> inside the html file or also inside of a <style>...</style> section directly inside the html file.


> So hundreds of odd or even statements could be eliminated from the API html ???

Yup all of those class="odd" and class="even" could be removed.

It might be good for there to be some kind of mark on the <table> where it should be applied though. The one that I posted above will apply it to every <table> inside the whole file which means the table at the very top of the document will get the striping applied to it now as well when it didn't have it before. But it doesn't seem to look bad there.

This whole thing would probably be a good candidate to have as an .xml file with an XSLT stylesheet along with it to generate HTML output, but I don't think a whole lot of people are familiar with XSL. But that's what I do for generating the MoI command reference (XML/XSLT to HTML).

- Michael
From: bemfarmer
20 Sep 2022   [#10] In reply to [#9]
Thank you Michael.

So much to learn, and play with.
Will have to look into the (XML/XSLT to HTML). (someday :-)

I did a test file, RevolveAndMirrorTest_API_DM, with the first 19 lines of the API, then a style section with your tr:nth-child(odd), and ...(even), then the revolve doc, then the mirror doc.
I changed all of the many API (tr...odd and tr ... even to just greater than, tr, less than.

The code can be saved to an .html, and viewed with the Edge browser, which shows a pretty good match with the stock API. Some () are colored black.

code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="index, follow, noodp" name="robots"/>
<meta content="Moment of Inspiration Javascript Documentation" name="description"/>
<meta content="Moment of Inspiration, MoI, 3d, nurbs, modeling" name="keywords"/>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<title>Moment of Inspiration Javascript Documentation</title>
<link media="screen" type="text/css" href="moi.css" rel="stylesheet">    
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="moi.js"></script>
</head>
<body> 
<div id="content">
<a name="toc"></a>

<h1>Moment of Inspiration Javascript Documentation
<a href="#help"><img id="htoggle" src="images/help.png" width="34" height="17"></a>
</h1>

<style>
tr:nth-child(odd) {
	background-color: #F0F0F0;
}

tr:nth-child(even) {
	background-color: #E0E0E0;
}
</style> 

<a name="_revolve">
<h2><a href="#gftoc">revolve</a> ( <a href="#_GeometryFactory">GeometryFactory</a> )</h2>
<div>
<p>
<table>
<tr>
  <td class="caption" colspan="3"><b>Inputs</b></td>
</tr>
<tr class="title">
  <td width="30">Index</td>
  <td width="250">Name</td>
  <td>Type</td>
</tr>
<tr>

  <td>0</td>
  <td>Objects</td>
  <td><a href="#_ObjectList">ObjectList</a></td>
</tr>
<tr>
  <td>1</td>
  <td>Axis start</td>
  <td><a href="#_Point">Point</a></td>
</tr>
<tr>
  <td>2</td>
  <td>Axis end</td>
  <td><a href="#_Point">Point</a></td>
</tr>
<tr>
  <td>3</td>
  <td>Angle</td>
  <td>float</td>
</tr>
<tr>
  <td>4</td>
  <td>Cap ends</td>
  <td>boolean</td>
</tr>
</tr>
</table>
</p>
</div>


<a name="_mirror">
<h2><a href="#gftoc">mirror</a> ( <a href="#_GeometryFactory">GeometryFactory</a> )</h2>
<div>
<p>
<table>
<tr>
  <td class="caption" colspan="3"><b>Inputs</b></td>
</tr>
<tr class="title">
  <td width="30">Index</td>
  <td width="250">Name</td>
  <td>Type</td>
</tr>
<tr>
  <td>0</td>
  <td>Objects</td>
  <td><a href="#_ObjectList">ObjectList</a></td>
</tr>
<tr>
  <td>1</td>
  <td>Base pt</td>
  <td><a href="#_CoordinateFrame">CoordinateFrame</a></td>
</tr>
<tr>
  <td>2</td>
  <td>End pt</td>
  <td><a href="#_Point">Point</a></td>
</tr>
<tr>
  <td>3</td>
  <td>Delete inputs</td>
  <td>boolean</td>
</tr>
</tr>
</table>
</p>
</div>


- Brian
From: pressure (PEER)
21 Sep 2022   [#11] In reply to [#7]
Brian,

Where might I find new factories that are undocumented? Near as I can tell they aren't in moi.idl from 2015. Can you think of any off the top of your head?
From: bemfarmer
21 Sep 2022   [#12] In reply to [#11]
Hi Peer,

Flow, Twist,...

The MoI4 commands folder has flow.js, flow.htm, twist.js, flow.htm.

Some are in forum posts, somewhere.
Some are in some scripts that I have done. (?)
Chainmaker.js has Twist and Flow. Maybe check forum posts on chainmaker script

Sorry, I am very busy with work now.
Will do some looking tonight.

- Brian
From: bemfarmer
21 Sep 2022   [#13] In reply to [#9]
The XML looks a lot like a database.

For alternating colors, XSLT:
https://stackoverflow.com/questions/8156906/alternate-row-color-of-table-using-xslt

- Brian
From: Michael Gibson
21 Sep 2022   [#14] In reply to [#13]
Hi Brian,

re:
> The XML looks a lot like a database.

Yeah the way that works is in the XML you can make up your own tag names that contain just plain data content and not any display specific stuff like pixel widths and table structures and such. Then the XSLT part is for generating HTML display content from the XML data.

After setting it up like that then modifying it becomes simpler because you are working with less stuff like you add in something like:

<factory>
   <name>Twist</name>
   <param>
        <description>Text content here</description>
    </param>
</factory>

That XML part is pretty straightforward but the XSLT part is kind of hard to learn.

- Michael
From: pressure (PEER)
21 Sep 2022   [#15] In reply to [#14]
Michael,

Are you up for providing something like an updated moi.idl and a list of all factories? I'm having a hard time sussing out some things related to sceneBrowser, sceneBrowser items, DXF export, SVG export, getDirs, UpdateViewTab, annotation objects, and SaveAs. And I have no clue about what factories have been added aside from what Brian listed.
From: bemfarmer
21 Sep 2022   [#16] In reply to [#11]
I think that NSided and Rebuild have factories, that the API does not document.
Orient, and OrientLineToLine, and ArrayGem, all have factories that are not documented by the API.
Also ExplodeMove, BoundingBox, BoundingBoxCenter, Make2D, and RemoveDuplicates, all have factories that are not documented by the API.

The Inset factory seems to be missing from the API.

I made a printout of MoI Command Reference, and the API factories, and started checking off the ones which seem to have the same factories in common.
But a Command is not a factory, but (often?) uses a factory in its .js code.
I started to get slightly confused. The API does not cross reference factories with commands.
Some Commands have a few types. The API does not show any grouping of related types...
For example, the Offset command includes curve offset, shell, and inset.

- Brian
From: bemfarmer
21 Sep 2022   [#17]
The Moi.idl file is no longer used, as of MoI4:
https://moi3d.com/forum/index.php?webtag=MOI&msg=10518.5

The old, (but latest?) (2015) Moi.idl file is here:
https://moi3d.com/forum/index.php?webtag=MOI&msg=7262.2

- Brian
From: Michael Gibson
21 Sep 2022   [#18] In reply to [#15]
Hi Peer,

re:
> Are you up for providing something like an updated moi.idl and a list of all factories?

Eventually yes but not all right now. Since v4 with the transition to a cross platform code base MoI itself does not use any moi.idl file anymore unlike v3 and earlier. I can help you with specific areas though.

re: sceneBrowser

The base scene browser object is at moi.ui.sceneBrowser, it has read-only properties for

sceneBrowser.objects - root scene browser item for objects section
sceneBrowser.types - root scene browser item for types section
sceneBrowser.styles - root scene browser item for styles section
sceneBrowser.rootItems - list of all root scene browser items


re: sceneBrowser items,

item.name
item.expandable
item.expanded
item.parent
item.children
item.find( 'name' ); - recursive search for child item with given name
item.alterStatus( 'show', true ); - First arg one of 'show', 'hide', 'lock', 'unlock', default if not given is 'show'. Second arg = true for right click behavior.
item.select( 'toggle' ); - // One of 'toggle', 'select', 'deselect', 'filteron', 'filteroff'. Default if not given is 'toggle'.


re: DXF export,

moi.geometryDatabase.fileExport( 'FileName', 'options_string' );

DXF export function parameter options (semi-colon delimited):

NoUI=true
ExportType=2d | 3d
ProjectionView=top | 3d | front | right
WriteCurvesAs=splines | cubicsplines | polylines
PolylineAngleDegrees=10.0
UseSimpleEntities=true
NumDecimalPlaces=12

GenerateHiddenLines=false
HiddenLineLayerMode=fromstyle | custom
HiddenLineLayerName=Hidden lines (layer name to use when layer mode = custom)
HiddenLineLayerPrefixSuffix=prefix | suffix (controls dropdown for which of "prefix" or "suffix" inputs is shown in the UI)
HiddenLineLayerPrefix=prefix_ (prefix to prepend to style name when layer mode = fromstyle)
HiddenLineLayerSuffix=_suffix (suffix to append to style name when layer mode = fromstyle)
IgnoreTangentEdges=false
Resolution=25.0


re: SVG export

PDF/AI/SVG export function parameter options:

NoUI=true
ProjectionView=top | 3d | front | right
ScaleType=fit | preserveunits
MoiScale=1.0
PageScale=1.0
PageUnits=mm | cm | in | pt
CenterOnPage=true

PageSize=letter | legal | tabloid | a3 | a4 | a5 | custom
Landscape=false
PageSizeCustomWidth=8.5
PageSizeCustomHeight=11.0
PageSizeCustomUnits=mm | cm | in | pt

GenerateOutlines=true
GenerateSilhouettes=true
GenerateHiddenLines=false
GenerateCrossHatching=false
ShadedBackground=true
IgnoreTangentEdges=false
Resolution=25.0

Line style properties for visible lines:
VisWidth=0.1
VisColorMode=fromstyle | custom
VisColor=0,0,0 (r,g,b color value for lines when color mode = custom)
VisLayerMode=fromstyle | custom
VisLayerName=Visible lines (layer name to use when layer mode = custom)
VisLayerPrefixSuffix=prefix | suffix (which of prefix or suffix are shown in the UI when layer mode = fromstyle)
VisLayerPrefix= (prefix to prepend to the layer name when layer mode = fromstyle)
VisLayerSuffix= (suffix to append to layer name when layer mode = fromstyle)

Line style properties for outlines:
OutWidth=3.0
OutColorMode=fromstyle | custom
OutColor=0,0,0 (r,g,b color value for lines when color mode = custom)
OutLayerMode=fromstyle | custom
OutLayerName=Outlines (layer name to use when layer mode = custom)
OutLayerPrefixSuffix=prefix | suffix (which of prefix or suffix are shown in the UI when layer mode = fromstyle)
OutLayerPrefix= (prefix to prepend to the layer name when layer mode = fromstyle)
OutLayerSuffix= (suffix to append to layer name when layer mode = fromstyle)

Line style properties for silhouettes:
SilWidth=0.4
SilColorMode=fromstyle | custom
SilColor=0,0,0 (r,g,b color value for lines when color mode = custom)
SilLayerMode=fromstyle | custom
SilLayerName=Silhouettes (layer name to use when layer mode = custom)
SilLayerPrefixSuffix=prefix | suffix (which of prefix or suffix are shown in the UI when layer mode = fromstyle)
SilLayerPrefix= (prefix to prepend to the layer name when layer mode = fromstyle)
SilLayerSuffix= (suffix to append to layer name when layer mode = fromstyle)

Line style properties for hidden lines:
HidWidth=0.1
HidColorMode=fromstyle | custom
HidColor=0,0,0 (r,g,b color value for lines when color mode = custom)
HidLayerMode=fromstyle | custom
HidLayerName=Hidden lines (layer name to use when layer mode = custom)
HidLayerPrefixSuffix=prefix | suffix (which of prefix or suffix are shown in the UI when layer mode = fromstyle)
HidLayerPrefix= (prefix to prepend to the layer name when layer mode = fromstyle)
HidLayerSuffix= (suffix to append to layer name when layer mode = fromstyle)

Line style properties for annotations:
AnnWidth=0.1
AnnColorMode=fromstyle | custom
AnnColor=0,0,0 (r,g,b color value for lines when color mode = custom)
AnnLayerMode=fromstyle | custom
AnnLayerName=Annotations (layer name to use when layer mode = custom)
AnnLayerPrefixSuffix=prefix | suffix (which of prefix or suffix are shown in the UI when layer mode = fromstyle)
AnnLayerPrefix= (prefix to prepend to the layer name when layer mode = fromstyle)
AnnLayerSuffix= (suffix to append to layer name when layer mode = fromstyle)

HiddenLinesOpacity=0.75 (opacity only applies to PDF export, not AI export)
HiddenLinesDashed=true
HiddenLinesDashSize=0.75
HiddenLinesGapSize=1.0

UseAICB=true (for AI copy to clipboard on OSX, for going into Adobe Illustrator CS3 or older).


re: getDirs,

moi.filesystem.getDirs( 'dirname', 'filter*' );

Given a directory name and an optional filter string, return a list of sub-directories within that directory.
For example: var dirs = moi.filesystem.getDirs( 'c:\\', 'p*' );
Filter can be a semi-colon delimited list of filters.


re: UpdateViewTab,

Update view tabs customization
Call a function UpdateViewTab( TabButton ) in the UI when a view tab has been reversed, so that it is possible to implement custom UI like having images there instead of text. Requested on the forum by Tim Whiteman here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=9821.1


re: annotation objects,

annotation.annotationType - one of "LinearDimension", "RadialDimension", "AngularDimension", "Leader", "Text"
annotation.annotationFrame - coordinate frame for the annotation object's plane
annotation.arrowheadType - "arrow", "open arrow", "tick", "dot", "barb"
annotation.arrowLength - pixel arrowhead size when using Scaling: By screen size mode.
annotation.arrowLengthModelUnits - model units arrowhead size when using Scaling: By model units mode.
annotation.arrowWidthFactor - value for aspect ratio to generate width from height
annotation.arrowGap - gap at point of arrow in Scaling by screen size mode
annotation.arrowGapModelUnits - gap at point of arrow in scaling by model units mode
annotation.openArrowLength - length for open arrowhead size in By screen size mode
annotation.openArrowLengthModelUnits - length for open arrowhead in model units mode
annotation.openArrowWidthFactor - same as arrowWidthFactor but for Open arrowheads
annotation.tickLength - size of tick type arrowhead in by screen size mode
annotation.tickLengthModelUnits - size of tick type arrowhead in by model units mode
annotation.tickLineWidth - display line width for tick arrowheads
annotation.reverseTick - reverse tick direction
annotation.dotSize - size of dot arrowhead type in screen size scaling mode
annotation.dotSizeModelUnits - size of dot arrowhead in by model units scaling mode
annotation.extensionLength - length of extension lines in screen size scaling mode
annotation.extensionLengthModelUnits - length of extension lines in model units scaling mode
annotation.extensionGap - gap for extension lines in screen mode
annotation.extensionGapModelUnits - gap for extension lines in model units mode
annotation.arrowLineExtension - arrow line extension in screen mode
annotation.arrowLineExtensionModelUnits - arrow line extensoin in model units mode.
annotation.textAlign - "Left", "Center", "Right", "Justified"
annotation.scaleMode - "By screen size", "By model units"
annotation.height - Text height for By model units mode.
annotation.textBoxPaddingX - left/right text box padding for screen size scaling mode
annotation.textBoxPaddingY - top/bottom text box padding for screen size scaling mode
annotation.textBoxPaddingXModelUnits - left/right text box padding for model units scaling mode
annotation.textBoxPaddingYModelUnits - top/bottom text box padding for model units scaling mode
annotation.textBoxOutline - "None", "Rect", "Bracket"
annotation.textBoxOutlineWidth - width to use for bracket outline in screen size scaling mode
annotation.textBoxOutlineWidthModelUnits - width to use for bracket outline in model units scaling mode
annotation.textMode - "Above", "Inline", "Screen"
annotation.text - text value for annotation, for dims it can contain <> which will be replaced by numeric dimension length
annotation.fontName
annotation.fontPtSize
annotation.fontStyleName
annotation.fontWeight
annotation.fontStyle
annotation.fontUnderline
annotation.fontStrikeout
annotation.distanceDisplay - "Decimal", "Feet & Inches"
annotation.numDecimalPlaces );
annotation.showTrailingZeros
annotation.fractionalDisplayPrecision
annotation.rotateArrowheadPlaneTowardsViewer



re: and SaveAs

moi.geometryDatabase.saveAs( 'FileName', 'OptionsString' );


- Michael
From: pressure (PEER)
22 Sep 2022   [#19] In reply to [#17]
Brian,

Yes I've been going off of the 2015 idl, or rather Tudor's javascript translation of it.
From: pressure (PEER)
22 Sep 2022   [#20] In reply to [#18]
Thanks Michael! What you wrote is even better than what I was hoping for. Thanks for putting it all into human-readable format with comments.

I forgot to ask about trackpadgesture events.

Show messages:  1-20  21-40  41-47