Scale multiple nodes |
|
|
| Posted: 29 July 2010 10:51 AM |
|
|
|
Newbie
Total Posts: 22
Joined 2008-12-31
|
I’ve looked around Creator & the unsupported plugins, and I searched the forum, but so far I can’t find an answer to this… doesn’t mean I missed the obvious though! 
I have a selection that consists of a large number of nodes… this could be polys, objects,groups, etc. but always the same node type in the selection. I need to scale every node exactly the same amount, around the center of each individual node, treating it such that it doesn’t get scaled disproportionally.
For a selection of polygons this would be like setting the trackplane to each individual face simultaneously, and scaling each polygon where it exists in relationship to “its own trackplane” so to speak, and this would be done all with one input from the modeler.
For a selection of objects or groups it would work the same way, but scaling around the individual centers of each object/group, rather than the collective center of all objects/groups.
I can see making this even more fun by maybe telling the tool to scale each node from the lowest or highest Z-value in each node, and possibly other options to make it more difficult… but I would be happy with just scaling about the centers.
I’d call this tool Scale About Multiple Centers© or perhaps simply Multi-Scale© in keeping with the heritage of Multigen. 
Or maybe I’ve just identified my personal point-of-entry into the world of scripting for Creator?
|
|
|
|
|
|
| Posted: 29 July 2010 12:53 PM |
[ # 1 ]
|
|
|
Moderator
Total Posts: 208
Joined 2008-07-03
|
This sounds like an interesting tool. Your right that it would be a good script to write, but perhaps not the best first script to write. If I were you I would definately attempt it. You won’t regret it because when you become good at scripting, all the doors open up to you and you become a very powerful creator user. Here is a little description of the tasks you need to do for the script.
1) prompt user for a double value to scale by
2) iterate the selected nodes
3) for each selected node do:
a) walk the vertices under the selected node and calculate an average position for center
b) use this center point to build a matrix that will scale any vertex about that point.
c) walk the vertices under the selected node and apply the matrix to them
3,b is the tricky math part. It is tricky because you have to know two things about scaling/matrices.
The first thing you need to know is, the basic scale operation scales around the origin of the db (0,0,0). To scale around an arbitrary point, you need to translate the object you want to scale to the origin, scale it, then translate it back. All of this can be stored in a single matrix so don’t worry too much about it.
The last thing you need to know is that when you combine matrices, you have to do so in reverse order. For example, to scale around the center point, start with an identity matrix, translate it AWAY from the origin towards center point, scale by the value entered by the user then translate TOWARDS the origin. Remember it has to be in reverse order.
Ok, I hope that will give you all you need to implement this script. If you get stuck along the way post your question on this thread. If you give up, I’ll post my version of the script.
|
|
|
|
|
|
| Posted: 29 July 2010 01:04 PM |
[ # 2 ]
|
|
|
Moderator
Total Posts: 208
Joined 2008-07-03
|
I case you need some help getting started, I stripped out some of the parts of my script and added TODO comments to tell you what is missing. This should give you the basic structure and get you going.
here is the script: just copy and paste this code into the Script Editor.
db = mgGetCurrentDb()
#TODO: Prompt the user for a scale value (should be one line of code)
def scalenode (db, parent, rec, data): if (mgGetCode(rec) == fltVertex): #TODO: Get the current vertex position, apply the scale matrix to it # then set the new value as the current vertex position return MG_TRUE selectList = mgGetSelectList (db) num = mgGetRecListCount (selectList) if (num == 0): mgSendMessage (MMSG_ERROR, "Nothing Selected:") else: for i in range (0, num): rec,m = mgGetNextRecInList (selectList) #TODO: Get the bounding box of the node rec and use it to calculate a center #TODO: Build a scale matrix from the value entered by the user and the center point mgWalk (rec, scalenode, None, None, MWALK_NORDONLY|MWALK_VERTEX)
print "Done"
|
|
|
|
|
|
| Posted: 29 July 2010 02:47 PM |
[ # 3 ]
|
|
|
Sr. Member
Total Posts: 311
Joined 2009-03-17
|
ok, scale_value = mgPromptDialogDouble ( None, 1, "Scale Value" , 1.00000)
This would be a pretty cool tool to have. Even if it is just at the group or object level. I could see how you could extend it to scale differently in the separate axes as an option, lock the z value of the scale center to 0.0, and other nifty options.
In the interim, and easier path, at least at the group node level, would be to select all the groups (nicely named, of course), make-externals (unsupported plugin) selecting either the geometry center or the center at z=0, and have a mo-simple script scale each external file WRT its local origin, then go back in to the master and reread and convert externals.
|
|
|
|
|
|
| Posted: 02 August 2010 08:32 AM |
[ # 4 ]
|
|
|
Jr. Member
Total Posts: 48
Joined 2008-12-11
|
This sounds like it would be great, thought about this one myself on more then one occasion when I have a database and all of the instances have been converted to geometry as our vega prime based system doesn’t support standard presagis object types
Is there a guide somewhere on scripting in creator? I mean Kent’s last response makes perfect sense when I read it but if you asked me to come up with most of the jargon I’d still never be able to figure out how to make a dialog box.
|
|
|
|
|
|
| Posted: 02 August 2010 10:15 AM |
[ # 5 ]
|
|
|
Sr. Member
Total Posts: 311
Joined 2009-03-17
|
I have not found a guide - there is a “User’s Guide” to the API that explains a lot of the internal constructs, and an API Reference Guide, which tells you what the functions do. But unless you already know the names of the functions, it is difficult to find a specific capability. And the categories are not all that helpful either.
I also recommend, if you are not Python versant, “Python for Dummies” or something similar to teach you about tuples and sting compares and that sort of thing in this particular scripting language, it is very different than PERL or CSH.
|
|
|
|
|
|
| Posted: 02 August 2010 11:48 AM |
[ # 6 ]
|
|
|
Moderator
Total Posts: 319
Joined 2008-07-02
|
Is there a guide somewhere on scripting in creator?
Note that OpenFlight Script (the language you use to “script in creator”) is just a Python language wrapper to the existing OpenFlight API C Language functions. As such, it does not have a separate guide. The “guide” is that for the OpenFlight API. If you know the function there, you know the function in OpenFlight script (since they are the same).
Note there are some language differences between C and Python, so some of the function parameters are slightly different between the two sets but when that is the case, the difference is clearly explained in the OpenFlight Reference Manual.
To get started, I would recommend installing the OpenFlight API (it comes on the Creator install disk). Although you don’t need the API to run scripts in Creator, when you install the API, you get all the help files Kent mentions. There are several “help” links in the OpenFlight Script Editor that will get hooked up when the API help files are on your computer.
And finally, if you have any questions, ask on the forum. We often post entire scripts to help you achieve what you are after.
|
|
|
|
|
|
| Posted: 02 August 2010 12:20 PM |
[ # 7 ]
|
|
|
Moderator
Total Posts: 208
Joined 2008-07-03
|
There is definately a guide. It is the OpenFlight API Users Guide. The basics of how to access and manipulate an OpenFlight hiearrchy are covered in volume 1. (You must install the OpenFlight API to access these help files) Scripting is simply a new interface to the existing API that is much more accessible. (you don’t need to purchase or set up compilers. You don’t need projects and it is simply far easier to start). With that said, when you are writing a script, you are just using the OpenFlight API. Most of the time, any knowledge you have for one will apply to the other. In many occasions the syntax of the commands changes slightly due to limitations in the languages.
For example in OpenFlight API Users Guide Vol2, Chapter 14 has a section on Convenience Dialogs. Here is an excerpt from that section:
Convenience dialogs come in two styles, Message Dialogs and Prompt Dialogs. Message
dialogs contain a message and title, plus any combination of predefined icons and push
buttons. They can be used to pose simple yes/no/cancel type questions. They can also be
used to display important messages that require user attention before processing can
continue.
Prompt dialogs also come in two styles, Simple Prompt Dialogs and System Prompt
Dialogs. Simple Prompt Dialogs contain a message, a text field, and two push buttons “Ok”
and “Cancel”. They are used to prompt the user to enter a numeric or text value. System
Prompt Dialogs are used to prompt the user to select a file, folder or color.
mgPromptDialogDouble, as Kent Pointed out was the solution to the first TODO, is part of this larger class of convienence dialogs. It is very easy to ask the user for input, and to post messages to the user using these convienence dialogs. The user guides will tell you what can be done, and once you understand those basics, you can look up exactly how each thing is done using the OpenFlight API Reference Manual. This document shows the syntax for every single function in the API. This is the document that helps to know what you are looking for before you open it. The user guides will provide you with enough information to understand what questions to ask, and the reference manual will answer those questions. It also shows code examples for both c and python where applicable. Here is an example of the python code sample for mgPromptDialogDouble section of the reference manual.
PYTHON EXAMPLE
status,number = mgPromptDialogDouble (None, “Enter Number”, 4.0)
if (MSTAT_ISOK (status)):
print number
I would recommend reading volume 1 and 2 of the users guide to get a high level overview of how the API works. (Python doesn’t allow creation of plugins/tools yet so you can skip all the information about that.) Once have the high level overview you should know the names of functions that need to be used to accomplish certain tasks (or at least enough of the name to be able to search for it). You can then look these functions up in the Reference to find out exactly how to use them.
|
|
|
|
|
|
| Posted: 02 August 2010 12:51 PM |
[ # 8 ]
|
|
|
Sr. Member
Total Posts: 311
Joined 2009-03-17
|
yes, yes, and yes, but it is still difficult sometimes to find a specific function in the ref manual even with the user’s guide too. And there many semantical differences with the Python and C versions. And the actual construction of a Python script is very different than a piece of C-Code.
So - it would be useful to the user base to have a “how to” guide that laid out some simple scripting constructs to get a taste for it, then users could get some python tutorials and the reference manual to go further.
|
|
|
|
|
|
| Posted: 02 August 2010 01:38 PM |
[ # 9 ]
|
|
|
Moderator
Total Posts: 319
Joined 2008-07-02
|
We appreciate your feedback and will take this all into account for next version.
FYI… We have already designed a FAQ that will be included with OpenFlight API 4.2. This hopefully will provide a bit of a bridge between the User’s Guide and the Reference Manual. It answers several “How do I…” type questions.
...and in the meantime, note that included in the API SDK are sample scripts for many common Creator tools. This is a good place to see scripts that might be similar to what you want to do. If you have the API SDK installed, goto the OpenFlight Script Editor and File>Browse Creator Scripts. In the folder you should see familiar names that will match Creator Tool names. For example the script code for the “Shift Far Left” command is found in shiftfarleft.py.
Have fun browsing…
|
|
|
|
|
|
| Posted: 02 August 2010 01:46 PM |
[ # 10 ]
|
|
|
Sr. Member
Total Posts: 311
Joined 2009-03-17
|
Hmmmm. Most excellent, master scriptor. I did not know of these examples, some interesting stuff to browse, or import into my function library for use.
|
|
|
|
|
|
| Posted: 02 August 2010 04:35 PM |
[ # 11 ]
|
|
|
Moderator
Total Posts: 319
Joined 2008-07-02
|
...and all show you how to do Undo/Redo too…
hmmm that rhymes too too mu——cho
|
|
|
|
|
|
| Posted: 02 August 2010 08:40 PM |
[ # 12 ]
|
|
|
Sr. Member
Total Posts: 311
Joined 2009-03-17
|
and pork moo shoo
choo choo
frou frou
poo poo
and much ado too
|
|
|
|
|