MoI discussion forum
MoI discussion forum

Full Version: Can "presets" for selecting objects be implemented?

Show messages:  1-13  14-23

From: fcwilt
27 Mar   [#14] In reply to [#12]
Hi Michael,

Just when I think I'm starting to understand this stuff I find I don't.

Using the prefix works great for simplifying object selection.


But I really don't need the prefix in the exported STL files.

So I read about the java script slice function which sounds like what I need to remove the STL_ from the object name when creating the filename for exporting.

I tried an experiment, using the ExportParts command you created for me, but I get an error - cannot find variable "slice".

So I'm guessing to use slice (and others things like it) I need to use something like xxx.slice where xxx is where slice "lives"?

Frederick
From: Michael Gibson
27 Mar   [#15] In reply to [#14]
Hi Frederick,

re:
> So I'm guessing to use slice (and others things like it) I need to use something like xxx.slice
> where xxx is where slice "lives"?

Yes, that's correct. The xxx should be a string object, like this:

var str = 'STL_Test';
// str is a string that contains 'STL_Test'

var str2 = str.slice( 4 );
// str2 contains a chunk of the original string starting at index 4 and through to the end so it contains 'Test'

moi.ui.alert( str2 );

If you're stuck please post your modified ExportParts.js file.

- Michael
From: fcwilt
27 Mar   [#16] In reply to [#15]
Hi Michael,

I was treating it like a "library" function passing it both the string and the index.

Old school.

Thanks much.

Frederick
From: fcwilt
27 Mar   [#17] In reply to [#15]
Hi Michael,

It's working just fine.

I was wondering about a way to display "debug" messages - and it was in the code you posted . Handy.

But something is generating a prompt to select parts to export - even though the code appears to be selecting them correctly before the prompt appears.

The prompt is a good thing because it gives me a chance to cancel the export if I invoked it by mistake.

But what is generating the prompt?

And a related question:

The .HTM file - that provides a user interface if needed?

Is it required?

What invokes that file?

Can you use that file to collect input and feed it into the script?

Thanks.

Frederick

Attachments:
ExportParts.zip


From: Michael Gibson
27 Mar   [#18] In reply to [#17]
Hi Frederick,

re:
> But what is generating the prompt?

It's the call to GetObjects().

The object picker will only target preselected objects if the selection happened before the command started.

Since you want to automatically select stuff instead of having the user pick them you probably don't want to use the object picker there at all.

Instead of calling GetObjects() you could call moi.geometryDatabase.getSelectedObjects(); and to wait at the prompt you could call WaitForDialogDone() instead of GetObjects().


> The .HTM file - that provides a user interface if needed?

Yes the .htm file has the UI for the command which will be loaded into the command options area in the upper right of the main window.


> Is it required?

No, if the command doesn't want to show any UI there the .htm file can be omitted.


> What invokes that file?

It's part of the "command" infrastructure. When you run a command if there is an .htm file present it will get loaded into the command options area before the .js code is run.


> Can you use that file to collect input and feed it into the script?

Yes you can put controls in the .htm and the script can access them.


- Michael
From: fcwilt
27 Mar   [#19] In reply to [#18]
Hi Michael,

Thanks very much for the feedback.

Since you can collect user input from the .HTM file, and I gather there is no real documentation, do you know of a good example, that is simple enough to learn the basics from?

I think I'm getting the hang of this stuff.

Frederick
From: Michael Gibson
27 Mar   [#20] In reply to [#19]
Hi Frederick, I've attached an example here.

- Michael

Attachments:
Example.zip


From: fcwilt
27 Mar   [#21] In reply to [#20]
Hi Michael,

Thank you.

Going back a post or two to where you mentioned this:

-The object picker will only target preselected objects if the selection happened before the command started.

-Since you want to automatically select stuff instead of having the user pick them you probably don't want to use the object picker there at all.

-Instead of calling GetObjects() you could call moi.geometryDatabase.getSelectedObjects(); and to wait at the prompt you could call WaitForDialogDone() instead of GetObjects().

I could not get it to work.

See attached.

Thanks.

Frederick

Attachments:
ExportParts.zip


From: Michael Gibson
27 Mar   [#22] In reply to [#21]
Hi Frederick, almost - so what I meant was get rid of all the objectpicker stuff and you can get the selected objects by the return value of moi.geometryDatabase.getSelectedObjects(), like:

var objs = moi.geometryDatabase.getSelectedObjects();

And now that it's selecting objects by name there won't be any unnamed objects selected so I think you can skip the deselectUnnamedParts part as well.

So maybe just this (untested):

function ExportByPrefix() {
mgd.deselectAll();
mgd.selectNamed(pfix);

WaitForDialogDone();

DoExportParts( mgd.getSelectedObjects() );
}


re:
// what are these 4 lines below supposed to do

Those were updating the prompt (the top line in the command options area) by hiding one line of text and showing the next one.

- Michael
From: fcwilt
28 Mar   [#23] In reply to [#22]
Hi Michael,

That seems simple enough.

I will give it a try shortly.

Thanks.

Frederick

Show messages:  1-13  14-23