Copy and paste it into a text file, save it as any name you want then hit F6 and select it, or in a command line type @pathtofile\filename
Share your Macros and Layouts
In the info panel I can grab the coordinates of this vertex then use it with workplane.edit [][][]…But it doesnt work the workplane doesnt move to the correct position. Acutally it moves correctly if I enter 0 for the orientation part of the workplane.edit command.
Unfortunately, I discovered a similar bug in workplane.edit when I was trying to create a Center on Workplane script this morning. Because of this bug, it is not currently possible to get or set the workplane position or orientation numerically.
– Joe
Here’s some cleaner versions of the 0 bevel and 0 extrude tools. These will bevel/extrude by 0 and then return to your last mode (transform, selection, etc) as well as keep your previous action center.
Quick Bevel:
#perl
my $seltype;
if( lxq( “tool.set actr.select ?”) )
{
$seltype = “actr.select”;
}
elsif( lxq( “tool.set actr.selectauto ?”) )
{
$seltype = “actr.selectauto”;
}
elsif( lxq( “tool.set actr.element ?”) )
{
$seltype = “actr.element”;
}
elsif( lxq( “tool.set actr.screen ?”) )
{
$seltype = “actr.screen”;
}
elsif( lxq( “tool.set actr.origin ?”) )
{
$seltype = “actr.origin”;
}
elsif( lxq( “tool.set actr.local ?”) )
{
$seltype = “actr.local”;
}
elsif( lxq( “tool.set actr.pivot ?”) )
{
$seltype = “actr.pivot”;
}
elsif( lxq( “tool.set actr.auto ?”) )
{
$seltype = “actr.auto”;
}
else
{
$seltype = “actr.auto”;
}
lx( “tool.makePreset name:tool.previous” );
lx( “tool.set tool.previous off” );
lx( “bevel yes” );
lx( “tool.setAttr poly.bevel shift [0 m]” );
lx( “tool.setAttr poly.bevel inset [0 m]” );
lx( “tool.doapply” );
lx( “tool.set poly.bevel off” );
lx( “tool.setPreset preset:tool.previous” );
lx( “tool.set {$seltype} on” );
Quick Extrude:
#perl
my $seltype;
if( lxq( “tool.set actr.select ?”) )
{
$seltype = “actr.select”;
}
elsif( lxq( “tool.set actr.selectauto ?”) )
{
$seltype = “actr.selectauto”;
}
elsif( lxq( “tool.set actr.element ?”) )
{
$seltype = “actr.element”;
}
elsif( lxq( “tool.set actr.screen ?”) )
{
$seltype = “actr.screen”;
}
elsif( lxq( “tool.set actr.origin ?”) )
{
$seltype = “actr.origin”;
}
elsif( lxq( “tool.set actr.local ?”) )
{
$seltype = “actr.local”;
}
elsif( lxq( “tool.set actr.pivot ?”) )
{
$seltype = “actr.pivot”;
}
elsif( lxq( “tool.set actr.auto ?”) )
{
$seltype = “actr.auto”;
}
else
{
$seltype = “actr.auto”;
}
lx( “tool.makePreset name:tool.previous” );
lx( “tool.set tool.previous off” );
lx( “select.edge remove poly less 2” );
lx( “tool.set edge.extend on” );
lx( “tool.attr edge.extend offZ [0 m]” );
lx( “tool.attr edge.extend offX [0 m]” );
lx( “tool.attr edge.extend offY [0 m]” );
lx( “tool.doapply” );
lx( “tool.set edge.extend off 0” );
lx( “tool.setPreset preset:tool.previous” );
lx( “tool.set {$seltype} on” );
my @selEdges = lxq(qq(query layerservice edges ? selected));
@selEdges always empty with or without selected edges.
Is it a bug or I do something wrong ?
This script moves down the selected (or all if none selected) vertices so that the lowest one is resting on the ground plane.
#!perl
my @verx = lxq("query layerservice verts ? selection");
if($#verx < 0)
{
@verx = lxq("query layerservice verts ? all");
}
my @pos = lxq("query layerservice vert.pos ? $verx[0]");
my $dist = $pos[1];
foreach my $vert (@verx)
{
@pos = lxq("query layerservice vert.pos ? $verx[$vert]");
if($pos[1] < $dist)
{
$dist = $pos[1];
}
}
$dist = -$dist;
lx("tool.set xfrm.move on");
lx("tool.setAttr \"xfrm.move\" \"Y\" $dist");
lx("tool.doApply");
lx("tool.set xfrm.move off");
Hey Griffon any news on the workplane problems?
Any chance to see the Set value command work in the active Workplane CS?
I can use scale to align components with the axis center at the origin but its a workaround…
there’s really some inconsitances because when you get a primitive the position is related to the current workplane.
Hi … I was trying to create a macro or script for Modo that I can link to a key for selecting the next or previous layer (or going to the first and last layer) …
Created a very very simple macro … >
#LXMacro#
select.layer [256] “set” [0] [0] [-1]
Now I was wandering if you could replace the layer number (256) by a instructions something like “currentLayer + 1” … Somebody knows if that is possible ? Or does somebody know the instructions to access layers in Perl script ?
many thanks,
{eƒ}
Posted this to another thread, but didn’t want it to get lost
It aligns points to the last point selected on the specified axis.
The arguements are any combo of XYZ. ie:
alignToPoint.pl XY
alignToPoint.pl Z
alignToPoint.pl XYZ
#----------cut-----------------------
#!perl
if($#ARGV < 0)
{
lxout(“Arguement missing. Needs Axis. ie. “XY””);
return;
}
my @verx = lxq(“query layerservice verts ? selection”);
if($#verx < 0)
{
@verx = lxq(“query layerservice verts ? all”);
}
my @pos = lxq(“query layerservice vert.pos ? $verx[$#verx]”);
if($ARGV[0] =~ /x/i)
{
lxout(“X”);
lx(“vert.set X $pos[0]”);
}
if($ARGV[0] =~ /y/i)
{
lxout(“Y”);
lx(“vert.set Y $pos[1]”);
}
if($ARGV[0] =~ /z/i)
{
lxout(“Z”);
lx(“vert.set Z $pos[2]”);
}
#----------cut-----------------------
I’m sure i’v just not found the spin tri’s yet.
But how about this …
- You press the triple key to triple a polygon.
- But woops it’s made the edge of the two tri’s
in the opposite direction you wanted it to go.
3.You press the same triple key and it spins the tri.
“This would have to call on a selected poly that has already
been tripled and if true spin tri or some thing like that . I really
don’t know.”
Modo Is a very cool software and been camping out at a friends
to use his copy. lol
P.S. I found Spin Edge "If your in poly mode you select the edge
mode then select the edge then spin edge then return to poly mode
if that’s the tool you were using in the first place.
…but would still be nice with both options.
I would like a triple key …but when pressed a second time it spins the tri.
15min later
I’v made a hack to do this"it only works on one poly at a time"
-once assigning this macro to a key pressing it will-
1.Take a polygon that you have selected and it will triple it.
2.Pressing the same key will spin it’s tri’s
Anyone out there go right ahead do what yeh like with this. A nice clean scrip
would be nice. If you take a look at the macro you can see it’s a mess and only
works on one poly at a time.
Butt it dose the trick for me now and I’m already using it so i’m happy.
here it is! Just copy it to a wordpad and give it the .LXM extension
I’v named it
“TripleOrSpin.LXM”
#LXMacro#
poly.triple
select.convert “edge”
select.contract
edge.spinQuads
select.expand
select.convert “polygon”
select.typeFrom “edge;vertex;polygon;item” [1]
select.contract
select.contract
select.typeFrom “polygon;edge;vertex;item” [1]
Hi !
Following script works like Bridge in LW.
Now it works only with two polygons selected.
#!perl
#This script creates a “bridge” between 2 selected polygons
my @fg_layers;
my @polyEdges;
my $polyIndex;
#lxout("Bridge 0.4.0 started
");
sub getFGLayer
{
@fg_layers = lxq(qq(query layerservice layers ? fg));
( @fg_layers ) or die "Foreground layers didn’t found
";
}
sub detectPolyEdges
{
my ( $polygon ) = @_;
my @verts = lxq(qq(query layerservice poly.vertList ? $polygon));
foreach my $i ( 0..$#verts - 1)
{
push @{$polyEdges[$polyIndex]}, [$verts[$i], $verts[$i + 1],1];
}
push @{$polyEdges[$polyIndex]}, [$verts[$#verts], $verts[0], 1];
$polyIndex++;
}
sub getCenter
{
my ( $edge ) = @_;
my @pos1 = lxq(qq(query layerservice vert.pos ? @{$edge}[0]));
my @pos2 = lxq(qq(query layerservice vert.pos ? @{$edge}[1]));
my @center;
$center[0] = ($pos2[0] - $pos1[0]) * 0.5;
$center[1] = ($pos2[1] - $pos1[1]) * 0.5;
$center[2] = ($pos2[2] - $pos1[2]) * 0.5;
$center[0] += $pos1[0];
$center[1] += $pos1[1];
$center[2] += $pos1[2];
return @center;
}
sub getDistance
{
my ( $edge1, $edge2 ) = @_;
my @center1 = getCenter($edge1);
my @center2 = getCenter($edge2);
my $distance = sqrt(($center1[0]-$center2[0])**2+($center1[1]-$center2[1])**2+($center1[2]-$center2[2])**2);
return $distance;
}
sub getVector
{
my ( $edge, $direction ) = @_;
my @pos1 = lxq(qq(query layerservice vert.pos ? @{$edge}[0]));
my @pos2 = lxq(qq(query layerservice vert.pos ? @{$edge}[1]));
my @vector;
if ( $direction )
{
@vector = map {$pos1[$_] - $pos2[$_]} 0..$#pos1;
}
else
{
@vector = map {$pos2[$_] - $pos1[$_]} 0..$#pos1;
}
return @vector;
}
sub getMod
{
my @vec = @_;
my $res;
foreach my $i ( 0…$#vec )
{
$res += $vec[$i] ** 2;
}
return sqrt($res);
}
sub createPoly
{
my ( $edge1, $edge2, $direction ) = @_;
lx(“select.drop vertex”);
lx(“select.element layer:$fg_layers[0] type:vertex mode:set index:@{$edge1}[0]”);
lx(“select.element layer:$fg_layers[0] type:vertex mode:set index:@{$edge1}[1]”);
if ( $direction )
{
lx("select.element layer:$fg_layers[0] type:vertex mode:set index:@{$edge2}[1]");
lx("select.element layer:$fg_layers[0] type:vertex mode:set index:@{$edge2}[0]");
}
else
{
lx("select.element layer:$fg_layers[0] type:vertex mode:set index:@{$edge2}[0]");
lx("select.element layer:$fg_layers[0] type:vertex mode:set index:@{$edge2}[1]");
}
lx("poly.make type:face");
}
sub getNormal
{
my ( $x1, $y1, $z1, $x2, $y2, $z2, $x3, $y3, $z3 ) = @_;
my @norm_vector = ( $y1*$z2 - $y2*$z1, $x2*$z1 - $z2*$x1, $x1*$y2 - $x2*$y1 );
return @norm_vector;
}
sub calcNormalAngles
{
my ( $edge1, $edge2, $direction ) = @_;
my @norm1;
my @norm2;
if ( $direction )
{
@norm1 = getVector ( $edge1, 0 );
@norm2 = getVector ( $edge2, 1 );
}
else
{
@norm1 = getVector ( $edge1, 0 );
@norm2 = getVector ( $edge2, 0 );
}
my $cos_fi;
foreach my $i ( 0..$#norm1 )
{
$cos_fi += $norm1[$i]*$norm2[$i];
}
$cos_fi /= ( getMod(@norm1) * getMod(@norm2));
return $cos_fi;
}
sub markEdges
{
my ( $mEdge, $ec, @mPolyEdges ) = @_;
my $mark_count = 0;
my $edge_index;
foreach $edge_index ( 0..$#mPolyEdges )
{
if ( $mPolyEdges[$edge_index] == $mEdge )
{
if ( $ec > 0 )
{
@{$mEdge}[2] = 0;
}
my $mark_index;
my $mi;
foreach $mark_index (( $edge_index + 1)..( $#mPolyEdges ))
{
$mi = $mark_index;
if ( @{$mPolyEdges[$mark_index]}[2] == 0 )
{
return ($edge_index, $mark_count);
}
if ( $ec > 0 )
{
@{$mPolyEdges[$mark_index]}[2] = $ec;
}
$mark_count ++;
}
if (($edge_index == $#mPolyEdges) ||
(( $mi == $#mPolyEdges ) && ( @{$mPolyEdges[$mi]}[2] != 0)))
{
foreach $mark_index ( 0..( $edge_index - 1))
{
if ( @{$mPolyEdges[$mark_index]}[2] == 0 )
{
return ( $edge_index, $mark_count );
}
if ( $ec > 0 )
{
@{$mPolyEdges[$mark_index]}[2] = $ec;
}
$mark_count ++;
}
}
return ( $edge_index, $mark_count );
}
}
return ( $edge_index, $mark_count );
}
sub getNextEdge
{
my ( $edge_index, $edge_shift, @mPolyEdges ) = @_;
my $next_index;
if ( $edge_index + $edge_shift <= $#mPolyEdges )
{
$next_index = $edge_index + $edge_shift;
}
else
{
$next_index = $edge_shift - ( $#mPolyEdges - $edge_index ) - 1;
}
return $mPolyEdges[$next_index];
}
sub createBridge
{
my ( $polyIndex1, $polyIndex2 ) = @_;
my @polyEdges1 = @{$polyEdges[$polyIndex1]};
my @polyEdges2 = @{$polyEdges[$polyIndex2]};
( $#polyEdges1 == $#polyEdges2 ) or die "Now works only for polygons with the same count of vertices";
my @distances1, @distances2;
foreach my $edge ( @polyEdges1 )
{
foreach my $edge2 ( @polyEdges2 )
{
my $distance = getDistance( $edge, $edge2);
my $angle1 = calcNormalAngles( $edge, $edge2, 0 );
my $angle2 = calcNormalAngles( $edge, $edge2, 1 );
push @distances1, [ $edge, $edge2, $distance, $angle1, 0, 0, 0 ];
push @distances2, [ $edge, $edge2, $distance, $angle2, 1, 0, 0 ];
}
}
@distances1 = sort { ( @{$a}[3] <=> @{$b}[3] ) ||
( @{$a}[2] <=> @{$b}[2] )
} @distances1;
@distances2 = sort { ( @{$a}[3] <=> @{$b}[3] ) ||
( @{$a}[2] <=> @{$b}[2] )
} @distances2;
my @distances = ( @distances1, @distances2 );
foreach my $index ( reverse ( 0..$#distances ))
{
@{$distances[$index]}[5] = $index;
}
@distances = sort { @{$a}[2] <=> @{$b}[2] } @distances;
foreach my $index ( reverse ( 0..$#distances ))
{
@{$distances[$index]}[6] = $index;
}
@distances = sort {( @{$a}[5] + @{$a}[6] ) <=> ( @{$b}[5] + @{$b}[6] ) } @distances;
my $edge_counter = 1;
while ( @distances )
{
my $created;
EDGE : foreach my $edgeMeasure ( @distances )
{
my $edge1 = @{$edgeMeasure}[0];
my $edge2 = @{$edgeMeasure}[1];
if (( @{$edge1}[2] != @{$edge2}[2] ) && ( $#distances > 1 ))
{
next EDGE;
}
my $angle_normal = @{$edgeMeasure}[4];
createPoly( $edge1, $edge2, @{$edgeMeasure}[4] );
@distances = grep { (@{$_}[0] != $edge1) && (@{$_}[1] != $edge2) } @distances;
my ( $edge1_index, $edge1_shift ) = markEdges( $edge1, $edge_counter, @polyEdges1 );
my ( $edge2_index, $edge2_shift ) = markEdges( $edge2, $edge_counter, reverse @polyEdges2 );
if ( $edge1_shift == $edge2_shift )
{
foreach my $edge_shift ( 1..$edge1_shift )
{
my $edge1 = getNextEdge ( $edge1_index, $edge_shift, @polyEdges1 );
my $edge2 = getNextEdge ( $edge2_index, $edge_shift, reverse @polyEdges2 );
createPoly( $edge1, $edge2, $angle_normal );
@distances = grep { (@{$}[0] != $edge1) && (@{$}[1] != $edge2) } @distances;
}
}
$edge_counter ++;
$created = 1;
last EDGE;
}
return unless defined $created;
}
}
getFGLayer;
my @polygons = lxq(qq(query layerservice polys ? selected));
$#polygons == 1 or die (“now only 2 polygons supported”);
foreach my $polygon ( @polygons )
{
detectPolyEdges($polygon);
}
createBridge(0, 1);
lx(“select.drop polygon”);
foreach my $polygon ( @polygons )
{
lx(“select.element layer:$fg_layers[0] type:polygon mode:set index:$polygon”);
}
lx(“poly.remove”);
A quick question, if I may?
Shy of using vertMap.applyMorph and then using vert.pos, how would one go about retrieving the value of a vmap (type:morph) for any given vert? I’ve tried using select.vertexMap and then vert.pos… but that still only returns pos for the base.
Thanks in advance.
-Rob
This may seem like a very stupid question…but I need help anyway.
How would I go about writing a macro that simply saves a mesh and changes its name by increasing the number at the end.
I’ve programmed before, so I see the logic in my head (I could do ti in VB, C or Java :P) but I know nothing about the syntax that would be required for modo. I do not need someone to write it for me, just to explain a couple of commands. Any help would be appreicated.
thank you