5
$\begingroup$

I need to select a solid body in ANSYS Design Modeler, with script, in a design with multiples bodies. With the following command I select all the solid bodies, but this is not what I need.

ag.bodyPick;
ag.gui.SelectAll();

I'm creating a script to model two spur gears engaged, first creating one tooth then making circular pattern to create the entry gear, with the following script I create the pinion but when I'm going to make the circular pattern for the gear, the pattern command give me an error, because I select all the solid bodies including the pinion, and I need to pick only the solid of the gear tooth to make the circular pattern them.

This is my script:

ag.m.ClearAllErrors();
ag.gui.setUnits(ag.c.UnitMillimeter, ag.c.UnitDegree, ag.c.No);

var p = new Object();

//Plane
p.Plane  = agb.GetActivePlane();
p.Origin = p.Plane.GetOrigin();
p.XAxis  = p.Plane.GetXAxis();
p.YAxis  = p.Plane.GetYAxis();

p.Sk1 = p.Plane.NewSketch();
p.Sk1.Name = "Pinion";
p.Sk2 = p.Plane.NewSketch();
p.Sk2.Name = "Wheel";

//PINION
with (p.Sk1)
{
p.Sp1 = SplineBegin();
with(p.Sp1)
{
    SplineFlexibility = agc.Yes;
    SplineXY(-1.76564478418, 24.6869398366);
    SplineXY(-1.51020858813, 24.7038816792);
    //......... spline coordinates of the pinion profile
    //......... removed because character limit
    SplineXY(5.26099091644, 24.1843849328);

    SplineFitPtEnd();
    }
    p.Ln2 = Line(-1.76564478418, 24.6869398366, -1.24843570599,17.4554120057);
    p.Ln3 = Line(3.71989256718, 17.1000701545, 5.26099091644, 24.1843849328);
    p.Cr4 = ArcCtrEdge(
              0, 0,
              3.71989256718, 17.1000701545,
              -1.24843570599, 17.4554120057);
    p.Ext1 = agb.Extrude(agc.Add, p.Sk1, agc.DirNormal, agc.ExtentFixe, 34.0, agc.ExtentFixed, 0.0, agc.No, 0.0, 0.0);
}
agb.Regen();



var PF1 = ag.gui.CreateSpot();
ag.listview.ActivateItem("Type");
ag.listview.ItemValue = "Construction Point";
ag.listview.ActivateItem("Definition");
ag.listview.ItemValue = "Manual Input";
ag.listview.ActivateItem("FD8, X Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD9, Y Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD10, Z Coordinate");
ag.listview.ItemValue = "0";
agb.Regen();

var PF2 = ag.gui.CreateSpot();
ag.listview.ActivateItem("Type");
ag.listview.ItemValue = "Construction Point";
ag.listview.ActivateItem("Definition");
ag.listview.ItemValue = "Manual Input";
ag.listview.ActivateItem("FD8, X Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD9, Y Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD10, Z Coordinate");
ag.listview.ItemValue = "34.0";
agb.Regen();

var LF1 = agb.LinePt();
LF1.AddSegment(PF1.GetPoint(1, 0),PF2.GetPoint(1, 0), 0);
agb.Regen();


var Pat = ag.gui.CreatePattern();
ag.listview.ActivateItem("Pattern Type");
ag.listview.ItemValue = "Circular";

ag.listview.ActivateItem("Geometry");
ag.bodyPick;
ag.gui.PickFilter(5, true);
ag.gui.PickFilter(11, false);
ag.gui.PickFilter(11, false);
ag.gui.SelectAll();
ag.listview.ItemValue = "Apply";

ag.listview.ActivateItem("Axis");
ag.edgePick;
ag.gui.SelectAll();
ag.listview.ItemValue = "Apply";
ag.listview.ActivateItem("FD2, Angle");
ag.listview.ItemValue = "16.3636363636";
ag.listview.ActivateItem("FD3, Copies (>0)");
ag.listview.ItemValue = "21.0";
agb.Regen();

//GEAR    
with (p.Sk2)
{
  p.Sp1 = SplineBegin();
  with(p.Sp1)
  {
    SplineFlexibility = agc.Yes;
    SplineXY(1.9304744152, 30.2623156532);
    //......... spline coordinates of the gear profile
    //......... removed because character limit
    SplineXY(-5.79031304774, 30.3548985987);

    SplineFitPtEnd();
  }
  p.Ln2 = Line(1.9304744152, 30.2623156532, 0.209834175566,173.751999593);
  p.Ln3 = Line(-0.629381853016, 173.762062957, -5.79031304774, 30.3548985987);
  p.Cr4 = ArcCtrEdge(
              0, 191.250741537,
              -0.629381853016, 173.762062957,
              0.209834175566, 173.751999593);
  p.Ext2 = agb.Extrude(agc.Add, p.Sk2, agc.DirNormal, agc.ExtentFixe, 34.0, agc.ExtentFixed, 34.0, agc.No, 0.0, 0.0);
}

var PF3 = ag.gui.CreateSpot();
ag.listview.ActivateItem("Type");
ag.listview.ItemValue = "Construction Point";
ag.listview.ActivateItem("Definition");
ag.listview.ItemValue = "Manual Input";
ag.listview.ActivateItem("FD8, X Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD9, Y Coordinate");
ag.listview.ItemValue = "77.5";
ag.listview.ActivateItem("FD10, Z Coordinate");
ag.listview.ItemValue = "0";
agb.Regen();

var PF4 = ag.gui.CreateSpot();
ag.listview.ActivateItem("Type");
ag.listview.ItemValue = "Construction Point";
ag.listview.ActivateItem("Definition");
ag.listview.ItemValue = "Manual Input";
ag.listview.ActivateItem("FD8, X Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD9, Y Coordinate");
ag.listview.ItemValue = "77.5";
ag.listview.ActivateItem("FD10, Z Coordinate");
ag.listview.ItemValue = "34.0";
agb.Regen();

var LF2 = agb.LinePt();
LF2.AddSegment(PF3.GetPoint(1, 0),PF4.GetPoint(1, 0), 0);
agb.Regen();

var Pat = ag.gui.CreatePattern();
ag.listview.ActivateItem("Pattern Type");
ag.listview.ItemValue = "Circular";

ag.listview.ActivateItem("Geometry");
ag.gui.PickFilter(5, true);
ag.gui.PickFilter(11, false);
ag.gui.PickFilter(11, false);
ag.bodyPick;          //<- Here is where I need to select only the gear body
ag.gui.SelectAll();
ag.listview.ItemValue = "Apply";

ag.listview.ActivateItem("Axis");
ag.edgePick;         //<- Here is where I need to select only the gear rotation axis for the circular pattern
ag.gui.SelectAll();
ag.listview.ItemValue = "Apply";
ag.listview.ActivateItem("FD2, Angle");
ag.listview.ItemValue = "2.74809160305";
ag.listview.ActivateItem("FD3, Copies (>0)");
ag.listview.ItemValue = "130.0";
agb.Regen();
$\endgroup$
2
$\begingroup$

You can select a single body by this code:

agb.AddSelect(agc.TypeBody, bodyname);

Here is the script:

(Key ideas: First, assign name "GEAR" to the gear body ag.fm.Body(2).Name = "GEAR";. Second, creat gear object by gear = selectNode("GEAR"); where the function selectNode(target) is at the end. Third, use agb.AddSelect(agc.TypeBody, gear); after ag.bodyPick;)

ag.m.ClearAllErrors();
ag.gui.setUnits(ag.c.UnitMillimeter, ag.c.UnitDegree, ag.c.No);

var p = new Object();

//Plane
p.Plane  = agb.GetActivePlane();
p.Origin = p.Plane.GetOrigin();
p.XAxis  = p.Plane.GetXAxis();
p.YAxis  = p.Plane.GetYAxis();

p.Sk1 = p.Plane.NewSketch();
p.Sk1.Name = "Pinion";
p.Sk2 = p.Plane.NewSketch();
p.Sk2.Name = "Wheel";

//PINION
with (p.Sk1)
{
    p.Sp1 = SplineBegin();
    with(p.Sp1)
    {
        SplineFlexibility = agc.Yes;
        SplineXY(-1.76564478418, 24.6869398366);
        SplineXY(-1.51020858813, 24.7038816792);
        //......... spline coordinates of the pinion profile
        //......... removed because character limit
        SplineXY(5.26099091644, 24.1843849328);

        SplineFitPtEnd();
    }
    p.Ln2 = Line(-1.76564478418, 24.6869398366, -1.24843570599,17.4554120057);
    p.Ln3 = Line(3.71989256718, 17.1000701545, 5.26099091644, 24.1843849328);
    p.Cr4 = ArcCtrEdge(
              0, 0,
              3.71989256718, 17.1000701545,
              -1.24843570599, 17.4554120057);
    p.Ext1 = agb.Extrude(agc.Add, p.Sk1, agc.DirNormal, agc.ExtentFixe, 34.0, agc.ExtentFixed, 0.0, agc.No, 0.0, 0.0);
}
agb.Regen();


var PF1 = ag.gui.CreateSpot();
ag.listview.ActivateItem("Type");
ag.listview.ItemValue = "Construction Point";
ag.listview.ActivateItem("Definition");
ag.listview.ItemValue = "Manual Input";
ag.listview.ActivateItem("FD8, X Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD9, Y Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD10, Z Coordinate");
ag.listview.ItemValue = "0";
agb.Regen();

var PF2 = ag.gui.CreateSpot();
ag.listview.ActivateItem("Type");
ag.listview.ItemValue = "Construction Point";
ag.listview.ActivateItem("Definition");
ag.listview.ItemValue = "Manual Input";
ag.listview.ActivateItem("FD8, X Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD9, Y Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD10, Z Coordinate");
ag.listview.ItemValue = "34.0";
agb.Regen();

var LF1 = agb.LinePt();
LF1.AddSegment(PF1.GetPoint(1, 0),PF2.GetPoint(1, 0), 0);
agb.Regen();

var Pat = ag.gui.CreatePattern();
ag.listview.ActivateItem("Pattern Type");
ag.listview.ItemValue = "Circular";

ag.listview.ActivateItem("Geometry");
ag.bodyPick;
ag.gui.PickFilter(5, true);
ag.gui.PickFilter(11, false);
ag.gui.PickFilter(11, false);
ag.gui.SelectAll();
ag.listview.ItemValue = "Apply";

ag.listview.ActivateItem("Axis");
ag.edgePick;
ag.gui.SelectAll();
ag.listview.ItemValue = "Apply";
ag.listview.ActivateItem("FD2, Angle");
ag.listview.ItemValue = "16.3636363636";
ag.listview.ActivateItem("FD3, Copies (>=0)");
ag.listview.ItemValue = "21";
agb.Regen();

//GEAR
with (p.Sk2)
{
  p.Sp1 = SplineBegin();
  with(p.Sp1)
  {
    SplineFlexibility = agc.Yes;
    SplineXY(1.9304744152, 30.2623156532);
    //......... spline coordinates of the gear profile
    //......... removed because character limit
    SplineXY(-5.79031304774, 30.3548985987);

    SplineFitPtEnd();
  }
  p.Ln2 = Line(1.9304744152, 30.2623156532, 0.209834175566,173.751999593);
  p.Ln3 = Line(-0.629381853016, 173.762062957, -5.79031304774, 30.3548985987);
  p.Cr4 = ArcCtrEdge(
              0, 191.250741537,
              -0.629381853016, 173.762062957,
              0.209834175566, 173.751999593);
  p.Ext2 = agb.Extrude(agc.Add, p.Sk2, agc.DirNormal, agc.ExtentFixe, 34.0, agc.ExtentFixed, 34.0, agc.No, 0.0, 0.0);
}

var PF3 = ag.gui.CreateSpot();
ag.listview.ActivateItem("Type");
ag.listview.ItemValue = "Construction Point";
ag.listview.ActivateItem("Definition");
ag.listview.ItemValue = "Manual Input";
ag.listview.ActivateItem("FD8, X Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD9, Y Coordinate");
ag.listview.ItemValue = "77.5";
ag.listview.ActivateItem("FD10, Z Coordinate");
ag.listview.ItemValue = "0";
agb.Regen();
ag.fm.Body(2).Name = "GEAR";

var PF4 = ag.gui.CreateSpot();
ag.listview.ActivateItem("Type");
ag.listview.ItemValue = "Construction Point";
ag.listview.ActivateItem("Definition");
ag.listview.ItemValue = "Manual Input";
ag.listview.ActivateItem("FD8, X Coordinate");
ag.listview.ItemValue = "0";
ag.listview.ActivateItem("FD9, Y Coordinate");
ag.listview.ItemValue = "77.5";
ag.listview.ActivateItem("FD10, Z Coordinate");
ag.listview.ItemValue = "34.0";
agb.Regen();

var LF2 = agb.LinePt();
LF2.AddSegment(PF3.GetPoint(1, 0),PF4.GetPoint(1, 0), 0);
agb.Regen();

var Pat = ag.gui.CreatePattern();
ag.listview.ActivateItem("Pattern Type");
ag.listview.ItemValue = "Circular";

ag.listview.ActivateItem("Geometry");
ag.gui.PickFilter(5, true);
ag.gui.PickFilter(11, false);
gear = selectNode("GEAR");
ag.bodyPick;
agb.AddSelect(agc.TypeBody, gear);
ag.listview.ItemValue = "Apply";
ag.listview.ActivateItem("Axis");
ag.edgePick;
ag.gui.SelectAll();
ag.listview.ItemValue = "Apply";
ag.listview.ActivateItem("FD2, Angle");
ag.listview.ItemValue = "2.74809160305";
ag.listview.ActivateItem("FD3, Copies (>=0)");
ag.listview.ItemValue = "130";
agb.Regen();

function selectNode (target)
{
    var DM = ag.wb.AppletList.Applet( "AGApplet" ).App;
    var Nodes = DM.Script.ag.tree.Nodes;
    var count = Nodes.Count;
    var name, current;
    for (var i =1; i <= count; i++)
    {
        current = Nodes(i);
        name = current.Text.toLowerCase();
        if (name == target.toLowerCase())
        {
            DM.Script.agTree_LeftClick(current, false);
            var obj = ag.listviewSelectedObject;
            return obj;
        }
    }
}
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.