View Full Version : Need a script...
Jorge Arango 09-23-2010, 04:16 PM That does two things:
1) sets the modeling axis to the center of all points, just like Axis Center, but this is for hundreds of objects.
2) Sets the y axis in the same orientation of a cylinder that has a height bigger than the diameter (if that matters). For this, see attachment.
Thanks in advance.
|
|
Scott Ayers
09-23-2010, 07:04 PM
This isn't the greatest solution. But if nobody else posts a better way to do this at least you'll have something.;)
I used the Axis Center tool in this script.
But since there is no documentation(that I can find) for that tool's settings. You'll have to set up that tool by hand first before running the script.: //This script uses the Axis Center tool. So it needs to be prepared before running this script
//Make sure that you enable the Axis Center "Alignment" option
//Make sure you also set the Alignment option to "Selected Edge"
op = doc->GetActiveObject(); //start the align loop on this object
if(!op)return; // error handeling if no object was selected
while(true) //Loop through the OM
{
op->SetBit(BIT_ACTIVE); //Select the object
CallCommand(16351); // Enable Edge Mode
CallCommand(12112); // Select All edges
CallCommand(1011982); // Align Axis(make sure the Alignment options are set first)
CallCommand(12113); // Deselect All
op->DelBit(BIT_ACTIVE);//De-Select the object
CallCommand(12298); // Enable Model Mode
op = op->GetNext(); //Get the next object and align it's axis
if(!op)break; // if no next object is found. End the script
}
You didn't say how the objects will be selected in the OM. So this loop is a very simple get->next kind of loop.
-ScottA
Jorge Arango
09-23-2010, 07:24 PM
Thanks Scott, I'll try it. Where did you get info about this:
CallCommand(1011982); // Align Axis(make sure the Alignment options are set first)
Scott Ayers
09-23-2010, 07:44 PM
If I remember correctly. I snagged that one from the Command Manager.
Once in a great while you can find some things in there that aren't documented anyplace else.
-ScottA
Jorge Arango
09-23-2010, 08:40 PM
The script works for part 1 removing the enable edge mode line (I guess it would work even in model mode, as the tool works in model mode).
The problem for part two is that the cylinders have caps and a lot of edges there. Removing the caps makes it better but not quite, because it takes into account the short end edges, if I unselect these manually, it works. Is there a way to tell the script to only select each edge if it's more than a certain length?
Then comes the question of removing all these cap polygons which aren't needed...
Thank you!
Scott Ayers
09-23-2010, 09:38 PM
I'm not getting any issues with caps. On cylinders it seems to work fine for me.
But the axis won't always point straight down the center of some objects. For example on a capsule the axis is always slightly skewed a bit.
Here's what I'm doing with that script:
The Axis Center Tool has the option to align the axis of an object based on it's normals. But it doesn't work unless the polygons of the object are selected.
But... the problem is that there seems to be a major bug in the tool. Because every time you click the "Execute" button. The axis shifts around wildly and never figures out how to align the axis properly.
So using the normals option is useless.
But if you select all of the edges of the object and then use the "Selected Edges" option. That one seems to align the axis a lot better. And you can even use the various "Axis" options too.
So knowing that the tool has a major problem with the "Normals" option.
What I did through the script was change to edge mode and then select all of the object's edges. Then execute the Axis Tool. Then deselect everything and switch back to Model mode so the user had no idea any of that switching took place.
Then do the same process to the next object until no more objects were found.
I just scripted what I was doing with the Axis Center tool.
Since the Axis Center tool is so flakey and the "Normals" mode doesn't work properly. And since things like capsules don't align the axis properly even using edges. I'm afraid the tool has some major bugs in it.
And since all I'm doing is executing that tool through a script. This is probably a very limited method.
I'm not advanced enough to build my own Axis pointer from scratch.
-ScottA
Jorge Arango
09-23-2010, 09:49 PM
I'm not getting any issues with caps. On cylinders it seems to work fine for me.
But the axis won't always point straight down the center of some objects. For example on a capsule the axis is always slightly skewed a bit.
-ScottA
Maybe because you're using c4d cylinders that have polygon caps that meet neatly at the center, but check the attached file. Anyway, if I manually select the long edges that go from top to bottom and manually apply the align tool, it works as expected. This is also working with the capsule tool (deselecting the caps edges). This is why I ask if there's a way to only select the long edges, is there an edge length parameter there?
Thank you for your efforts Scott. I've learned a great deal with you!
Scott Ayers
09-23-2010, 10:45 PM
I see what you mean.
It also works if you select one of the cap polygons and use the Normals option for the Axis tool.
I'm afraid I mispoke before about the tool having a bug. After I played around with it some more I came to realize that the Normals option merely points towards any selected polygons.
I don't think it was meant to be used with all polygons selected like I was using it.
That does bring up an issue though like you've said.
That means that you've got have the proper polygons selected on all of your objects before you can use this method. And that could be a big problem if your objects are all different.
If all of the objects are the same. I suppose it's possible to iterate through the array of points and look for a distance that's a certain length. Then Select them.
Then execute the axis tool. And do that to all the objects. But that would be very limiting too.
I'll have to think about it some more. I can't really think of a good way to do this yet.
-ScottA
Jorge Arango
09-23-2010, 11:01 PM
That means that you've got have the proper polygons selected on all of your objects before you can use this method. And that could be a big problem if your objects are all different.
If all of the objects are the same. I suppose it's possible to iterate through the array of points and look for a distance that's a certain length. Then Select them.
Then execute the axis tool. And do that to all the objects. But that would be very limiting too.
-ScottA
That's the way I was thinking to do it, remove the select all line and preselect the edges before running the script. This is a pedestrian bridge that has 3 ramps and a horizontal part. I divided the objects in parts and am about to try it this way.
Thanks again
Jorge Arango
09-23-2010, 11:04 PM
I suppose it's possible to iterate through the array of points and look for a distance that's a certain length. Then Select them.
-ScottA
Maybe converting each edge to a spline and reading the spline's length?
Jorge Arango
09-23-2010, 11:27 PM
Worked like a charm.
Scott Ayers
09-23-2010, 11:54 PM
Here's another way.
But it's a little bit limited because I'm picking a specific polygon to use as a target for the axis to point at for all of the objects. So the objects have to have similar vertice layouts.
But this way the Axis Tool will work in "Normals" mode: //This script uses the Axis Center tool. So it needs to be prepared before running this script
//Make sure that you enable the Axis Center Alignment option
//Make sure you also set the Alignment option to "Normals"
op = doc->GetActiveObject(); //start the align loop here
if(!op)return; // error handeling if no object was selected
while(true) //Loop through the OM
{
op->SetBit(BIT_ACTIVE);
var bs = new(BaseSelect); // create a new BS container
var selected = bs->Select(11); //Select this polygon in memory--->Edit this line as needed
op->SetPolygonSelection(bs);// makes the polygon selected in the main scene window
CallCommand(1011982); // Align Axis(make sure the Alignment options are set first)
CallCommand(12113); // Deselect All
op = op->GetNext(); //Get the next object and align it's axis
if(!op)break; // if no next object is found. End the script
}
-ScottA
Jorge Arango
09-24-2010, 12:28 PM
Looks like a good approach. We have a good arsenal of tools for different situations.
Scott Ayers
09-24-2010, 03:21 PM
I can't picture what you're doing with the splines.
Do you have an example of that?
-ScottA
Jorge Arango
09-24-2010, 04:12 PM
I can't picture what you're doing with the splines.
Do you have an example of that?
-ScottA
If you mean what I say in post 10, it's that to find if an edge is longer than a certain length, you iterate through all the edges, convert them to splines and read the spline's length (if xpresso has a way giving the spline's length, I suppose coffee does too).
If you mean what I'm doing with these scripts, I got this bridge modeled by someone else in sketchup and its very heavy polygonwise, so as it has very few objects but repeated many times, some of them thousands of times, I'm replacing them with the ones modeled by myself and this helps me locating them in the exact position and orientation.
CGTalk Moderation
09-24-2010, 04:12 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.