Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Having trouble with opExtrude on skText

jason_bennett190jason_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

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,671
    Try qSketchRegion instead of qCreatedBy
    Senior Director, Technical Services, EMEAI
  • jason_bennett190jason_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>
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,671
    There is more than 1 sketch region so try qNthElement(qSketchRegion(id + "sketch1"), 0)
    Senior Director, Technical Services, EMEAI
  • jason_bennett190jason_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}}

  • lanalana Onshape Employees Posts: 704
    @jason_bennett190
    You want to use qSketchRegion() as a query that you pas to opExtrude, not to opPlane - just to make sure.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,671
    • 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, EMEAI
  • jason_bennett190jason_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>


  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,671
    Yes, so actually you shouldn't need qNthElement at all, qSketchRegion(id + "sketch1", true) should work
    Senior Director, Technical Services, EMEAI
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    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_bennett190jason_bennett190 Member, Developers Posts: 17
    Using qSketchRegion(id + "sketch1", true) works

    Thanks!
  • neil_jackson795neil_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_vietinghoffgeorg_von_vietinghoff Member Posts: 9 ✭✭
    great, that works!!
Sign In or Register to comment.