Add Facets/Vertices to Selection Set via script?

I'm wondering what the command is to add a specific facet (or vertex) to a Selection Set?

I know addSelectedFacetsToGroup("[group name]") works only if I have previously selected geometry in the viewport. I want a way where I bypass that and add certain facets to a group without having to select them in the viewport. A workaround would be to make a selection of a facet via script but I don't know how to do that either. I tried the getFacet() command but when used with the addSelectedFacetsToGroup() it does nothing.

Comments

  • PraxisPraxis Posts: 250
    edited August 2021

    Faux2D said:

    I'm wondering what the command is to add a specific facet (or vertex) to a Selection Set?

    I know addSelectedFacetsToGroup("[group name]") works only if I have previously selected geometry in the viewport. I want a way where I bypass that and add certain facets to a group without having to select them in the viewport. A workaround would be to make a selection of a facet via script but I don't know how to do that either. I tried the getFacet() command but when used with the addSelectedFacetsToGroup() it does nothing.


    These work for me:
    (Similar for Facet, Edge, Vertex)

    //---------------------------------------function uty_GetOrCreateFacetSelection    ( P_Node        // : DzNode, e.g. DzFigure    , P_SelID       // : String    )               // : DzSelectionGroup{  var result            = undefined;  if( P_Node ) {    var Obj             = P_Node.getObject();    if( Obj ) {      var Shape         = Obj.getCurrentShape();      // e.g. For G8F this is a DzGraftingFigureShape      if( Shape ) {        // true = Create it if it does not already exist:        result          = Shape.findFacetSelectionGroup( P_SelID, true );        // See Note ###_DzShape below      } // Got Shape    } // Got Object  } // Got Node  return result;};  // uty_GetOrCreateFacetSelection()//---------------------------------------function uty_BuildFacetSelection    ( P_Node            // : DzNode, e.g. DzFigure    , P_SelID           // : String    , P_FacetNumArr     // : Array of Facet Index #s into P_Nodes mesh    )                   // : DzSelectionGroup{  var Sel = uty_GetOrCreateFacetSelection( P_Node, P_SelID );  if( Sel ) {    Sel.clear();    // Discard any current entries    for( var J = 0; J < P_FacetNumArr.length; J++ ) {      Sel.addIndex( P_FacetNumArr[ J ] );    }    // See Note ###_DzSelectionGroup below  } // Got Selection  return Sel;};  // uty_BuildFacetSelection()//---------------------------------------// Note ###_DzShape:// -----------------//  To find undocumented properties and functions of DzShape://    a) Load and Select e.g. a G8F Figure.//    b) In the Script IDE execute://      var obj = Scene.getPrimarySelection().getObject().getCurrentShape();//      print( obj.className() );       // DzShape//      print( Object.keys( obj ) );// Note ###_DzSelectionGroup:// --------------------------//  To find undocumented properties and functions of DzSelectionGroup://    a) Load and Select e.g. a G8F Figure.//    b) If none exist yet, use the Geometry Editor to create a Facet Selection Set.//    c) In the Script IDE execute://      var obj = Scene.getPrimarySelection().getObject().getCurrentShape().getFacetSelectionGroup( 0 )//      print( obj.className() );       // DzSelectionGroup//      print( Object.keys( obj ) );

    Edited 2021-08-27 to correct missing ')'s in ### Notes, and incorrect 'function' declarations.

    Post edited by Praxis on
  • Faux2DFaux2D Posts: 452

    Praxis said:

    Faux2D said:

    I'm wondering what the command is to add a specific facet (or vertex) to a Selection Set?

    I know addSelectedFacetsToGroup("[group name]") works only if I have previously selected geometry in the viewport. I want a way where I bypass that and add certain facets to a group without having to select them in the viewport. A workaround would be to make a selection of a facet via script but I don't know how to do that either. I tried the getFacet() command but when used with the addSelectedFacetsToGroup() it does nothing.


    These work for me:
    (Similar for Facet, Edge, Vertex)

    //---------------------------------------function uty_GetOrCreateFacetSelection = function    ( P_Node        // : DzNode, e.g. DzFigure    , P_SelID       // : String    )               // : DzSelectionGroup{  var result            = undefined;  if( P_Node ) {    var Obj             = P_Node.getObject();    if( Obj ) {      var Shape         = Obj.getCurrentShape();      // e.g. For G8F this is a DzGraftingFigureShape      if( Shape ) {        // true = Create it if it does not already exist:        result          = Shape.findFacetSelectionGroup( P_SelID, true );        // See Note ###_DzShape below      } // Got Shape    } // Got Object  } // Got Node  return result;};  // uty_GetOrCreateFacetSelection()//---------------------------------------function uty_BuildFacetSelection = function    ( P_Node            // : DzNode, e.g. DzFigure    , P_SelID           // : String    , P_FacetNumArr     // : Array of Facet Index #s into P_Nodes mesh    )                   // : DzSelectionGroup{  var Sel = uty_GetOrCreateFacetSelection( P_Node, P_SelID );  if( Sel ) {    Sel.clear();    // Discard any current entries    for( var J = 0; J < P_FacetNumArr.length; J++ ) {      Sel.addIndex( P_FacetNumArr[ J ] );    }    // See Note ###_DzSelectionGroup below  } // Got Selection  return Sel;};  // uty_BuildFacetSelection()//---------------------------------------// Note ###_DzShape:// -----------------//  To find undocumented properties and functions of DzShape://    a) Load and Select e.g. a G8F Figure.//    b) In the Script IDE execute://      var obj = Scene.getPrimarySelection().getObject().getCurrentShape();//      print( obj.className() );       // DzShape//      print( Object.keys( obj ) );// Note ###_DzSelectionGroup:// --------------------------//  To find undocumented properties and functions of DzSelectionGroup://    a) Load and Select e.g. a G8F Figure.//    b) If none exist yet, usethe Geometry Editor to create a Facet Selection Set.//    c) In the Script IDE execute://      var obj = Scene.getPrimarySelection().getObject().getCurrentShape().getFacetSelectionGroup( 0 )//      print( obj.className() );       // DzSelectionGroup//      print( Object.keys( obj ) );

    Edited 2021-08-27 to correct missing ')'s in ### Notes.

    Many thanks! Very useful! 

Sign In or Register to comment.