Having trouble with opExtrude on skText

jason_bennett190
jason_bennett190 Member, Developers Posts: 17 ✭
Hello,

I am trying to make 3D text via a Feature script, but having trouble with the "holes" being filled upon opExtrude.

How do I get ride of the extra material?

Thanks


Section of Code:
<div>opPlane(context, id + "plane1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "plane" : plane(planeOrigin, planeNormal)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; });</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; var sketch1 = newSketch(context, id + "sketch1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "sketchPlane" : qCreatedBy(id + "plane1", EntityType.FACE)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; });</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const textItem = skText(sketch1, "text1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "text":definition.label,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "fontName" : "OpenSans-Bold.ttf"</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; skSolve(sketch1);</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; const textOrigin = vector(0*meter,0*meter,planeOrigin[2]);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; const textMove = vector(minPoint[0]+textHeight,maxPoint[1]-2*textHeight,0*meter);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; opTransform(context, id + "transform1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "bodies" : qCreatedBy(id + "sketch1", EntityType.BODY),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "transform" : transform(textMove)*scaleUniformly(textScale,textOrigin)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; });</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; opExtrude(context, id + "extrude1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "entities" : qCreatedBy(id + "sketch1", EntityType.FACE),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "direction" : planeNormal*-1,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endBound" : BoundingType.BLIND,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endDepth" : 3 * millimeter</div><div>&nbsp; &nbsp; &nbsp; &nbsp; });</div>

Results:

Comments

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    Try qSketchRegion instead of qCreatedBy
    Senior Director, Technical Services, EMEA
  • jason_bennett190
    jason_bennett190 Member, Developers Posts: 17 ✭
    Same results from using qSketchRegion. I thought maybe the transform was doing something, but the debug also highlights the holes in the letters.

     
    <div> &nbsp; &nbsp; &nbsp; opPlane(context, id + "plane1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "plane" : plane(planeOrigin, planeNormal)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; });</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; var sketch1 = newSketch(context, id + "sketch1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "sketchPlane" : qCreatedBy(id + "plane1", EntityType.FACE)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; });</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const textItem = skText(sketch1, "text1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "text":definition.label,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "fontName" : "OpenSans-Bold.ttf"</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; skSolve(sketch1);</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; const textOrigin = vector(0*meter,0*meter,planeOrigin[2]);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; const textMove = vector(minPoint[0]+textHeight,maxPoint[1]-2*textHeight,0*meter);</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; debug(context, qSketchRegion(id + "sketch1"));</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; opTransform(context, id + "transform1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "bodies" : qCreatedBy(id + "sketch1", EntityType.BODY),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "transform" : transform(textMove)*scaleUniformly(textScale,textOrigin)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; });</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; opExtrude(context, id + "extrude1", {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "entities" : qSketchRegion(id + "sketch1"),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "direction" : planeNormal*-1,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endBound" : BoundingType.BLIND,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endDepth" : 3 * millimeter</div><div>&nbsp; &nbsp; &nbsp; &nbsp; });</div>
  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    There is more than 1 sketch region so try qNthElement(qSketchRegion(id + "sketch1"), 0)
    Senior Director, Technical Services, EMEA
  • jason_bennett190
    jason_bennett190 Member, Developers Posts: 17 ✭
    qNthElement(qSketchRegion(id + "sketch1"), 0) returns one of the numbers. Each X (0->15) in qNthElement(qSketchRegion(id + "sketch1"), X) returns one of the letters or letter holes. Unfortunately there is no pattern in the element order.

    If there is no quick fix or minor thing that I am missing, I think I could build a sorting function. Maybe:

    • Cycle through qNthElement(qSketchRegion(id + "sketch1"), X)
    • if (query adjacent face == 0) {add X to var facesToExtrude}
    • else { if(area of X > area adjacent) {add X to var facesToExtrude}}

  • lana
    lana Onshape Employees Posts: 782 image
    @jason_bennett190
    You want to use qSketchRegion() as a query that you pas to opExtrude, not to opPlane - just to make sure.
  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    • Cycle through qNthElement(qSketchRegion(id + "sketch1"), X)
    • if (query adjacent face == 0) {add X to var facesToExtrude}
    • else { if(area of X > area adjacent) {add X to var facesToExtrude}}

    That seems reasonable - you could also use evBox3d to see if one region is totally inside another.

    qSketchRegion also has an innerloop filter which may work - 

    qSketchRegion (featureId is Id, filterInnerLoops is boolean) returns Query

    A query for all fully enclosed, 2D regions created by a sketch with the specified feature id.

    ParameterTypeAdditional Info
    filterInnerLoopsboolean

    Optional

    Specifies whether to exclude sketch regions fully contained in other sketch regions. Default is false.

    Senior Director, Technical Services, EMEA
  • jason_bennett190
    jason_bennett190 Member, Developers Posts: 17 ✭
    Yes. I am passing the qSketchRegion() to the opExtrude.

    As a work around, I wrote a filter to remove the internal regions, which is below.

    I would still like to see a simpler solution.

    Thanks for the feedback so far.

    <div>//Filter out character flaws
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; const sketchFaces = qSketchRegion(id + "sketch1");
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; const faceCount = size(evaluateQuery(context, sketchFaces));
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; var extrudeFaces = qNothing();</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; for (var i = 0; i < faceCount; i += 1)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const item = qNthElement(sketchFaces, i);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const adjacentItem = qEdgeAdjacent(item, EntityType.FACE);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println(size(evaluateQuery(context, adjacentItem)));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(size(evaluateQuery(context, adjacentItem))!=1){
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extrudeFaces = qUnion([extrudeFaces,item]);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (evArea(context, {"entities" : item})>evArea(context, {"entities" : adjacentItem}))</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extrudeFaces = qUnion([extrudeFaces,item]);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }<br></div>


  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    Yes, so actually you shouldn't need qNthElement at all, qSketchRegion(id + "sketch1", true) should work
    Senior Director, Technical Services, EMEA
  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    Yup, filterInnerLoops on qSketchRegion is a flag designed for exactly this kind of thing. No need for additional custom filtering.

    @NeilCooke
    It looks like filterInnerLoops used to default to "true" in older versions of std, which is likely why you don't remember needing to specify the flag before.
  • jason_bennett190
    jason_bennett190 Member, Developers Posts: 17 ✭
    Using qSketchRegion(id + "sketch1", true) works

    Thanks!
  • neil_jackson795
    neil_jackson795 Member Posts: 3 ✭
    edited July 2017

    Unfortunately, filterInnerLoops does not properly handle the case where there is more than one level of nested loops.

    As an example, make a sketchText containing Unicode character 0x0298 (LATIN LETTER BILABIAL CLICK): ʘ  (Use the Tinos font). This character is topologically equivalent to an "O" character with a dot in the middle of the "O". Extrude the sketch with filterInnerLoops, and in the resulting solid, you will see that the middle dot is missing.

  • georg_von_vietinghoff
    georg_von_vietinghoff Member Posts: 9 ✭✭
    great, that works!!