auto naming function

Next
 From:  noskule
5701.1 
hi all
when building stuff in moi I allways keep the construction elements, like profile and rail when using the sweep command for later modification. Before I do the construction command (like sweep) I name the constrution elements something like "Module:Name.CE" . "CE "means Construction-Element.

What I would like to achieve is that if construction elements have a name the name will be passed on to the newly created object automatically but without the CE ending. Means the objects name would be "Module:Name".

Has anyone an idea how to do this?
Thanks for any hints
nos
  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
5701.2 In reply to 5701.1 
Hi nos, I don't think there is any way to set that up right now - it would involve something like having a custom script run at the end of every command to do some processing of the objects. Right now there is not any mechanism set up to call scripts in that way.

I could set up a script for you that would just strip off the "CE" at the end of the name of whatever objects you have selected, would that be of any help?

- 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:  Luis (LGRIJALVA)
5701.3 In reply to 5701.1 
I think that what you are looking for is in here:

http://moi3d.com/forum/messages.php?webtag=MOI&msg=3830.1

the topic is "add elements to an object", but there is an "Assignpressetname" plugin on the 8th post

and for mac:
http://moi3d.com/forum/index.php?webtag=MOI&msg=3830.59

Hope this help

Luis G.

EDITED: 6 Feb 2013 by LGRIJALVA

  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
5701.4 In reply to 5701.2 
hi michael
Yes that would help. So after running the command like sweep the curves are still selected. I could run the naming command with a shortcut which would ask me to select the object which I would like to name.

About strip off the "CE" ending. Instead of strip ".CE" it would be better to strip a point be following 2 uppercase letters. This would allow having other endings as well.


One more thing nice would be to have a command which toggles the visabillity of the object or its corresponding construction elements.

Case: toggle visibillity of construction elements
1. select the object, press the shortcut and the construction elements will be hidden or shown

Case: toggle visibillity of object
1. select a construction element, press the shortcut and the object will be hidden or shown

So if you could set up such a script to I would be very happy :)

Currently what I do is that I give construction elements a style, so I can show/hide all the construction elements. But the downside of this is that is (A) it hides just all the construction elements and (B) I would like to use the syles for assemblies to visually support the representation of the functionallity. So the construction elements would get the same color as there corresponding object.


~nos
  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
5701.5 In reply to 5701.4 
Hi Nos, here is a script for the first one, this one will strip off the last 2 upper case letters from the names of the selected objects:

script: /* Strip last 2 upper case letters from the names of the selected objects */ var objs = moi.geometryDatabase.getSelectedObjects(); function isupper(str,i) { var code = str.charCodeAt(i); return code >= 65 && code <= 90; } for ( var i = 0; i < objs.length; ++i ) { var obj = objs.item(i); var name = obj.name; if ( isupper(name,name.length-2) && isupper(name,name.length-1) ) obj.name = name.substr(0,name.length-2); }

- 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:  Michael Gibson
5701.6 In reply to 5701.4 
Hi Nos, here are some scripts for the other ones:


> Case: toggle visibillity of construction elements
> 1. select the object, press the shortcut and the construction elements will be hidden or shown

script: /* Toggle hide/show of generators of selected objects */ var objs = moi.geometryDatabase.getSelectedObjects(); for ( var i = 0; i < objs.length; ++i ) { var parents = objs.item(i).getHistoryParents(); if ( parents.length == 0 ) continue; parents.setProperty( 'hidden', !parents.item(0).hidden ); }

> Case: toggle visibillity of object
> 1. select a construction element, press the shortcut and the object will be hidden or shown

script: /* Toggle hide/show of descendents of selected objects */ var objs = moi.geometryDatabase.getSelectedObjects(); for ( var i = 0; i < objs.length; ++i ) { var children = objs.item(i).getHistoryChildren(); if ( children.length == 0 ) continue; children.setProperty( 'hidden', !children.item(0).hidden ); }


These methods will only be able to figure things out where the history mechanism is still active though, like if you do an extrusion there is still a history relation from the curve to extruded result, but if you then do some other operations like a boolean on the extrusion it won't be able to keep the history connected.


Hope these help,

- Michael

EDITED: 17 Feb 2013 by MICHAEL GIBSON

  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
5701.7 In reply to 5701.5 
hi michael, thanks for the script. Could the script be modified so that it takes the name of an already selected object and ask me to select the object which should get the striped name? So the workflow would be as follows (taking the sweep example):


Profile and rail are named Pipe.CE

I perform the sweep, the pipe object will be created and the profile and rail are still selected

I call the strip-ending command and the script takes the name of the selected element, strips the ending and ask me to choose the element which should get the name

I choose the pipe.


This way I only have to perform one action, if the script only strips the ending I still have to name it manualy ore use another script to apply the name of the construction elements first.
~nos
  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
5701.8 In reply to 5701.7 
Hi Nos, that's getting pretty complicated to also incorporate object picking into a kind of one-line shortcut key script like that.

For something that involves object picking it would probably need to be redone as a plug-in command instead of as a direct shortcut key script.

Is the object that you would pick for receiving the name always the one that was created by the last run command?

Because if that's the case I think it should be possible for the script to find that object automatically and so not have any separate object picking stage needed.

- 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
5701.9 In reply to 5701.8 
Yes its always the last object. So if the script would find the object automatically its even better. So I only could perform a construction command, press the shortcut and the newly created object gets the name of the construction elements striped from the ending.
~nos
  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
5701.10 In reply to 5701.6 
hi Michael
I tried the scripts and as you mentioned they working as long a the history is intact. Is there a reason for using the history instead of searching for the names? Cause searching for names with/without the ".CE" Ending would work interdependently form an intact history.
~nos
  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
5701.11 In reply to 5701.10 
Hi nos,

> Is there a reason for using the history instead of searching for the names?

Because history is the only built in mechanism that matched what you were asking for.

Could you describe in a bit more detail exactly what names would be targeted? I guess I need more details about what you need these scripts to do - the brief descriptions you gave before did not give me enough information to do what I guess you need.

- 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:  Michael Gibson
5701.12 In reply to 5701.9 
Hi nos,

> Yes its always the last object. So if the script would find the object automatically its even better.
> So I only could perform a construction command, press the shortcut and the newly created object
> gets the name of the construction elements striped from the ending.

Give this one a try:

script: /* Apply selected object name to last generated object */ var name = ''; var gd = moi.geometryDatabase; var objs = gd.getSelectedObjects(); for ( var i = 0; i < objs.length; ++i ) { var obj = objs.item(i); var thisname = obj.name; if ( thisname.length > 3 && thisname.charAt(thisname.length-3) == '.' ) { name = thisname.substr( 0, thisname.length-3 ); break; } } if ( name != '' ) { gd.selectLastCreated( true ); gd.getSelectedObjects().setProperty( 'name', name ); }


This way this should work is say you a profile and a path curve both named Pipe.CE. Then you create a sweep from these curves - now with those curves selected, run this script and that should then make the sweep have the name Pipe, it will just look for a name in the current selection with a period and any 2 letters after it and if it finds that it will name the last generated object to be that name with the last 3 letters stripped off.

- 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:  noskule
5701.13 In reply to 5701.12 
Hi Michael, thanks ver y much, this works perferctly.
~nos
  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