lenght of a curve
All  1-2  3-7

Previous
Next
 From:  noskule
5205.3 
cool, so I try show the number on the ui but I get an error, do you see whats wrong? And whats the catch(e) for, is it needed?

script:/* Calculate length of selected curves and copy to the clipboard as text */ var crvs = moi.geometryDatabase.getSelectedObjects().getCurves(); var len = 0.0; for ( var i = 0; i < crvs.length; ++i ) len += crvs.item(i).getLength(); moi.copyTextToClipboard( len ); if ( !window["_crvdistlabel"] ) { document.body.insertAdjacentHTML( "beforeEnd", "
" ); } _crvdistlabel.innerText = len.toFixed(4);', 250 ); } catch(e) {}
  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
5205.4 In reply to 5205.3 
Hi nos - an inline script like that executes inside of its own individual script context, it's not inside of an actual HTML document when run in that way so global variables like "document" which are part of the HTML environment are not in there. But there is a global variable "moi" set for all script contexts and you can access the MoI object model through that and one of the things you can do through there is find one of the UI Panels which does have HTML in it and then interact with that.

I think you're trying to copy some code from the "CurveLengthBeingDrawn" script? The difference is that other script injects its script code into a HTML document by the first part of the script: moi.ui.commandUI.setInterval( 'script code in here' ); - that's why it works in that case to access stuff like document.body since the code is running in a timer handler there and the script context which the timer hander is running in is one that comes from an HTML page and so it has the HTML environment in it with stuff like "document", etc... in it.

The moi.ui.commandUI document is the document that holds the content for the options of the current running command - it's only actually visible on screen while a command is running.

You can get the HTML window object of the UI panels by calling moi.ui.getUIPanel('panel url') - like for example: moi.ui.getUIPanel('moi://ui/CommandBar.htm') will get you the HTML window for the bottom toolbar, you could then call document.body.insertAdjacentHTML() on that to inject HTML that will show up in the bottom toolbar.

So anyway things like "document" are not actually part of raw JavaScript itself, those things are added by the HTML environment and so they're only there for script contexts that are created as part of an HTML frame instance.


> And whats the catch(e) for, is it needed?

The catch(e) was needed for the "CurveLengthBeingDrawn" script to conclude the try { } block - you don't need that in your case since you have different code than that the "CurveLengthBeingDrawn" script and yours does not set up a try { } block in the start of it.

- 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:  noskule
5205.5 
> I think you're trying to copy some code from the "CurveLengthBeingDrawn" script?

Yes, I did try both scripts. So I took the CurveLength script and added the "insert len variable into html" part from the CurveLengthBeingDrawnV2 . However I haven't any programming skills so its more than less try and error.
But it seams not to work cause of the moi.get.ui part. So how should it look like? I tried the following but it don't doing anything:

/* Calculate length of selected curves and copy to the clipboard as text */
var crvs = moi.geometryDatabase.getSelectedObjects().getCurves();
var len = 0.0;
for ( var i = 0; i < crvs.length; ++i ) {
len += crvs.item(i).getLength();
moi.copyTextToClipboard( len );
}

/* Put var len somewhere into the ui */

moi.ui.getUIPanel('moi://ui/CommandBar.htm');

if ( !window["_crvdistlabel"] ) { document.body.insertAdjacentHTML( "beforeEnd", "
" ); } _crvdistlabel.innerText = len.toFixed(4);



And instead of the "CommandBar.htm" what would be the name of the ui-block which displays the element name, style, and dimension? Cause I would like to display the value there.
  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
5205.6 In reply to 5205.5 
Hi nos,

> But it seams not to work cause of the moi.get.ui part. So how should it look
> like? I tried the following but it don't doing anything:

The moi.ui.getUIPanel() part returns back a variable that you would then use as the place to insert HTML into.

Right now you're calling it and not actually doing anything with the returned variable, you'd need to do something more like:

var panel = moi.ui.getUIPanel( '...' );

panel.document.body.insertAdjacentHTML( .... )



> And instead of the "CommandBar.htm" what would be the name of the ui-block which
> displays the element name, style, and dimension?

That's inside of the Side pane - that can be retrieved by:
moi.ui.getUIPanel('moi://ui/SidePane.htm')


Then the part that displays the object properties is an element nested a fair ways down inside the side pane, the container of it has id="PropertiesPanel".


It will be kind of difficult to make a properly behaving readout in there though with just some shortcut key code doing it, because if you display the value by modifying the HTML your modifications are going to be stuck there all the time after that, and having old values stick there could be bad since it could pretty easily lead to you thinking that some old value was actually the length of the current selection. The "CurveLengthBeingDrawn" script basically avoided that problem because it put its stuff into the command UI document, which is a document that is created fresh when a command is run and destroyed when the command exits (it holds all the UI specific to each individual command), so it sort of automatically clears out. The place you're wanting to add stuff to only gets hidden and shown, not actually cleared out and so you'll have the problem of whatever you put in there sticking around.

- 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:  Michael Gibson
5205.7 In reply to 5205.5 
Hi Nos, so really instead of trying to set up a script that will modify the UI like that, I'd instead recommend installing the UnwrapCurve plugin from here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=5136.1

Then when you want to know the length of a curve, select it and trigger your shortcut for UnwrapCurve, that will generate a line of that length and if you want to know the numeric length just select the line and for lines the length of the line is displayed in the properties panel size line already.

- 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-2  3-7