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.

Needing some Expert Suggestions or Pointers

eldon_browneldon_brown Member Posts: 41 ✭✭
I think I am doing too many things at once, but that is the way I learn: I am Learning Onshape, Leaning Feature Script, Designing a Resin 3D Cabinet, and playing with alternate ways of creating 3D Solids. I am also trying to learn Onshape Assemblies with "In Context" editing for more complex future projects.

My experiments with Feature Script has led me to the conclusion that almost anything can be created with "A '' simple primitive, it just needs to be stretched and munged into the shape desired.  To that end, I have created and using my "Polygon Pipe Feature Script" to create Solid or Hollow Pipes at any line on the screen.  YES, I know, there are more traditional ways of creating most solids, but this is my way of learning more about Onshape External and Internal workings. I have been using several Solid Modeling tools for about fifteen years and know most standard techniques.

I am currently trying to add a new function to my Polygon Pipe Feature Script. Currently a pipe can be created on any line (short or long) but what I want to do is add functionality: to extend the pipe at either, or both ends, perpendicular to the pipe face. Currently the script will do that, but I wind up with three parts, the middle, and optionally an extension on each end. 




It appears there are two solutions: extrude the extensions, and then do a opBoolean() to form one part, Or, maybe, draw an extended centerline from the user selected line and then run my current "pipe" function on the extended line. which should produce the single desired part. 

I would appreciate it If someone could provide some programming details of these two approaches. I have looked and experimented, but have not YET found the magic.

My Polygon Pipe test bed document is:


My Resin 3D Print booth is:


Note: The Resin 3D Print Booth Design uses a simple circle to create the example Resin Bottles and ONLY three straight lines in one sketch for everything else.  The file contains an "Old Part Studio" of my original design for  comparison review.

Remember, this is not an attempt to learn "proper" 3D Modeling Techniques, but my way of learning more of OnShape and Feature Script Programming.

Thanks,
--Eldonb

Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,680
    Try opMoveFace.
    Senior Director, Technical Services, EMEAI
  • eldon_browneldon_brown Member Posts: 41 ✭✭
    NeilCooke said:
    Try opMoveFace.
    If I am reading and understanding the documentation correctly, opMoveFace would move the face using the World Coordinates, and I need it to be move perpendicular to the face regardless of the direction.

    Eventually, I want to provide options to move the face via: Blind, Upto Next, or User Specified Face, etc.

    I just need to find examples and learn a lot more Feature Script functions and their parameters. Note: "opMoveFace" is only mentioned 12 times in the "std" lib documentation (not much help for a new Feature programmer).


    From the Online Doc's:

    The transform to apply to the face.

    EXAMPLE

    transform(vector(0, 0, 1) * inch) will translate the face 1 inch along the world's z-axis.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,680
    Well you can get the normal vector a number of ways either from the original curve or from the end face. 
    Senior Director, Technical Services, EMEAI
  • eldon_browneldon_brown Member Posts: 41 ✭✭
    Here is the code snippet that I am trying to get to work to produce one part from an opSweep() and two end extensions. In the middle of the code there are some commented examples of my tries to use opMoveFace() and/or opOffsetFace() to effect the desired one part solution. The opExtrude() section, which works, but they produce a second part.  There is something that I do not understand or missing to make this work as desired.  Any help would be welcome - Thanks.


    ###########################################

         // Execution/Main ###############
            {
                var paths = constructPaths(context, definition.path);
                var counter = 0;
                definition.nShellAlt = (definition.PipeType == PipeType.arc)?definition.nShellAlt:false;
                
                // makeBaseSketch(context, id, plane, definition)Sketch(context, id + "sketch0", plane(startLine.origin, startLine.direction), definition);
                    
                for (var path in paths)
                {
                    counter += 1;
                    var id = mainId + unstableIdComponent(counter);
                    setExternalDisambiguation(context, id, path.edges[0]);
                    var startLine = evPathTangentLines(context, path, [definition.placeSketchPercent]).tangentLines[0];
                    var nearLine =  evPathTangentLines(context, path, [0]).tangentLines[0];
                    var farLine  =  evPathTangentLines(context, path, [1]).tangentLines[0];
        
                    makeSketch(context, id + "sketch1", plane(startLine.origin, startLine.direction), definition);
                    
                    // For User Debug and Feedback
                    if (definition.placeSketch && definition.showSketch) {
                        debug(context, qCreatedBy(id + "sketch1", EntityType.VERTEX ), DebugColor.GREEN);
                        debug(context, qCreatedBy(id + "sketch1", EntityType.EDGE   ), DebugColor.GREEN);
                    }
                    
                    
                    opSweep(context, id + "sweep1", {
                                "profiles" : qFarthestAlong(qCreatedBy(id + "sketch1", EntityType.FACE), perpendicularVector(startLine.direction)),
                                "path" : qUnion(path.edges)
                            });
                       
                    // Shell does not work with Extend Ends YET      
                    if (definition.extEnds) {
                        var Near = (definition.extFlipEnds?definition.extFarEnd:definition.extNearEnd);
                        var Far  = (definition.extFlipEnds?definition.extNearEnd:definition.extFarEnd);
                        if(Far > 0 ) {
                            opExtrude(context, id + "extrude1", {
                                    "entities"  : qCapEntity(id + "sweep1", CapType.END),
                                    "direction" : farLine.direction,
                                    "endBound"  : BoundingType.BLIND,
                                    "endDepth"  : Far
                            });
                            
                            // opMoveFace(context, id + "moveFace1", {
                            //         "moveFaces" : qCapEntity(id + "sweep1", CapType.END),
                            //         "transform" : vector(0, 0, 1) * inch
                            // });
                            
                            // opMoveFace(context, id + "moveFace1", {
                            //         "moveFaces" : qCapEntity(id + "sweep1", CapType.END),
                            //         "transform" : transform(vector(0, 0, 1) * inch)
                            // });
                                                    
                            // opMoveFace(context, id + "moveFace1", {
                            //         "moveFaces" : qCreatedBy(id + "sweep1", EntityType.FACE),
                            //         "transform" : transform(vector(0, -10, 0) * millimeter)
                            // });
                            
                            // opMoveFace(context, id + "moveFace1", {
                            //         "moveFaces" : qCreatedBy(id + "sweep1", EntityType.FACE),
                            //         "transform" : transform(vector(10, 0, 0) * millimeter)
                            // });
                            
                            // opOffsetFace(context, id + "offsetFace1", {
                            //         "moveFaces" : qCapEntity(id + "sweep1", CapType.END),
                            //         "offsetDistance" :  1 * inch
                            // });
                            
                            // opOffsetFace(context, id + "offsetFace1", {
                            //         "moveFaces" : qCreatedBy(id + "sweep1", EntityType.FACE),
                            //         "offsetDistance" :  2 * inch
                            // });
                            
                        }
                        if(Near > 0 ) {
                            opExtrude(context, id + "extrude2", {
                                    "entities"  : qCapEntity(id + "sweep1", CapType.START),
                                    "direction" : -nearLine.direction,
                                    "endBound"  : BoundingType.BLIND,
                                    "endDepth"  : Near
                            });
                            
                            
                        }
                        
                        
                    }
                             
                    if (definition.nShell && definition.nWall > 0 && !definition.nShellAlt) {
                        try silent 
                        {
                             opShell(context, id + "shell1", {
                                     "entities" : qCapEntity(id + "sweep1", CapType.EITHER),
                                     "thickness" : (definition.nFlipWall?1:-1) * definition.nWall
                             });
                        }
                    }
                     
                    // For User Debug and Feedback
                    if (!definition.placeSketch || !definition.showSketch) {
                        opDeleteBodies(context, id + "deleteBodies1", {
                                    "entities" : qCreatedBy(id + "sketch1", EntityType.BODY)
                        });
                    }
                    // // Not working as expected
                    // else {
                    //     //debug(context, vector(0,0)*millimeter,vector(10,15)*millimeter, DebugColor.RED);
                    //     debug(context, qCreatedBy(id + "sketch1", EntityType.VERTEX ), DebugColor.RED);
                    //     debug(context, qCreatedBy(id + "sketch1", EntityType.EDGE   ), DebugColor.RED);
                    // }
                }
                
                // Merge NOT WORKING
                // merge scope: merge all or not?
                // const mergeScope = definition.merge ? qBodyType(qEverything(EntityType.BODY), BodyType.SOLID) : definition.mergeScope;
            
            
            }
        );
  • eldon_browneldon_brown Member Posts: 41 ✭✭
    After many hours of Reading and Experimentation, I have a working solution, it is now simple but is was very elusive to me.

    It is now in my "Polygon Pipe FeatureScript" - V3.05.02 EXP


                    // Extend Ends    
                    if (definition.extEnds) {
                        var Near = (definition.extFlipEnds?definition.extFarEnd:definition.extNearEnd);
                        var Far  = (definition.extFlipEnds?definition.extNearEnd:definition.extFarEnd);
                        if(Near > 0 ) {  
                            opOffsetFace(context, id + "offsetFace1", {
                                    "moveFaces" : qCapEntity( id + "sweep1", CapType.START, EntityType.FACE),
                                    "offsetDistance" : Near
                            });
                        }
                        if(Far > 0 ) {
                            opOffsetFace(context, id + "offsetFace2", {
                                    "moveFaces" : qCapEntity( id + "sweep1", CapType.END, EntityType.FACE),
                                    "offsetDistance" : Far
                            });
                        }
                    }
Sign In or Register to comment.