auto naming function
All  1-4  5-13

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

 

 
 
Show messages: All  1-4  5-13