1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Stymied once again!

Discussion in 'Alibre Script' started by albie0803, Sep 26, 2020.

  1. albie0803

    albie0803 Alibre Super User

    Warning! [Rant]

    Once again, scripting has frustrated me. I have a 'keyway in a shaft' script that requires the origin face (which needs to be collinear to the origin point) to be selected in order to get a distance (as I can measure from face to face but not face to plane) to put a keyway from a selected face.
    I recently read the section on face and plane mapping and thought great! I can map points off the end faces of the cylinder I want the key in but map plane needs XYZ positions of points to work, not an actual point! ARRRRGH!!!:mad:

    If a script can identify a face and a point and a vertex, why can't it read where they are?

    My point being, if I knew where the points were, I wouldn't be trying to establish a zero point to sketch from.
    [/Rant]

    I DO appreciate all the effort that has gone into creating scripting, but things like this that scuttle scripting ideas just drives me nuts. Helicals is the other big one.


    I had an idea for cutting a thread in any hole perpendicular to a flat face via script.
    1 Select hole face > add axis
    2 Select flat face > add plane1
    3 Add plane2 thread depth distance below plane1
    4 Create Point1 at intersection of axis and plane1
    5 Create Point2 at intersection of axis and plane2
    6 Create Above Axis Point
    7 Use 3 points to Create Plane3 > Create sketch
    8 Plane Map sketch using above 3 generated points
    9 Draw tooth shape and Helical cut to depth

    Steps 8&9 are not possible.
     
    Last edited: Sep 26, 2020
  2. Lew_Merrick

    Lew_Merrick Alibre Super User

    Hi Albie -- My takes is that you need an "easy way" to determine what is the "positive direction" with respect to the "face" you are "selecting." -- Lew
     
  3. NateLiqGrav

    NateLiqGrav Alibre Super User

    It can - just not always a direct path.
    For example:
    Every face has edges and vertices.
    Every edge has vertices.
    Every 3d point and vertex has x, y, & z components.

    There are some complex examples scripts on the support page for ideas. Specifically these:
    https://support.alibre.com/support/solutions/articles/27000057884-joint-creator
    https://support.alibre.com/support/solutions/articles/27000057889-pocket-hole-creator
     
  4. albie0803

    albie0803 Alibre Super User

    What about dealing with Cylinders? I mainly deal with gears and shafts. Round things without corners.
     
  5. NateLiqGrav

    NateLiqGrav Alibre Super User

    You got me there. I'll have to look again at what info Alibre makes available with round faces and their edges. Maybe it gives center point, plane and radius - from which any point you want on the edge can be calculated.
     
  6. idslk

    idslk Alibre Super User

    If you imagine the axis is your flagpole, and the missing third point is the wind...
    Means, you can place your third point wherever you want (except on the axis) and you will get a plane "through" the axis. The direction (from where the wind blows) is normally not from interest for a thread.
    Sadly the "biggest proplem" persists - the API let's you modify a helix (access to all variables...), but it is not a public function to create one
    Regards
    Stefan

    Edit:
    Added a sample part with sample script to play with (ends with the "Threadsketchplane")...
     

    Attached Files:

    Last edited: Sep 27, 2020
    NateLiqGrav likes this.
  7. albie0803

    albie0803 Alibre Super User

    I repent of my rant. :oops: I have been shown a better way. :) I should have asked first.
     
  8. NateLiqGrav

    NateLiqGrav Alibre Super User

    @idslk That is one way to figure out that axis and plane to which to build the sketch on but if the axis is in line with the origin it fails.

    @albie0803 I was right in remembering that Alibre DOES give the circular faces a single vertex. So every face will have at least 1 vertex.

    So if you don't mind what direction the plane is then you could use the first vertex of the flat face regardless face shape. Replace the last two lines with:
    Code:
    P3 = enviroment.AddPoint('P3',startface.Vertices[0].X,startface.Vertices[0].Y,startface.Vertices[0].Z)
    tsp = enviroment.AddPlane('Threadsketchplane',[P1.X,P1.Y,P1.Z],[P2.X,P2.Y,P2.Z],[P3.X,P3.Y,P3.Z])
    Further to start mapping you can use those 3 points:
    Code:
    ts = enviroment.AddSketch("ThreadSketch", tsp)
    ts.StartMapping([P1.X,P1.Y,P1.Z],[P2.X,P2.Y,P2.Z],[P3.X,P3.Y,P3.Z])
    ts.AddRectangle(0, 0, 5, 10, False)
    ts.StopMapping()
    
     
    Last edited: Sep 27, 2020
  9. NateLiqGrav

    NateLiqGrav Alibre Super User

    You may want to verify that the user selected a flat face for the start face and a cylinder for the cylinder face.
    You may also want to know the radius of the cylinder.
    Then you can put this code before the line:
    startplane = enviroment.AddPlane('Startplane',startface,0)
    Code:
    if not str(startface._Face.Geometry.SurfaceType) == 'AD_PLANE':
        sys.exit('Exited: Selected Start Face is not flat.')
    if not str(cylinderface._Face.Geometry.SurfaceType) == 'AD_CYLINDER':
        sys.exit('Exited: Selected Cylinder Face is not a Cylinder.')
    radius = cylinderface._Face.Geometry.Radius # This will be in CM units by default
    radius = radius * 10 # Convert to MM units to match the rest of the script. Change this if you are using a different UnitType
    
    But as @idslk said the API does not let us make Helical features yet. I'm working on that.
     
  10. albie0803

    albie0803 Alibre Super User

    It was getting the mapping points from the axis crossing the cylinder faces that got me irate. In my limited knowledge it seemed unworkable. Cooler, wiser heads have kindly steered me in the right direction and I have it working. It will allow me to modify some scripts of mine that required Origin faces to work that will now have a more "user logical" flow to them.
    Thanks Nate for the code snippets, I will experiment!
     
  11. NateLiqGrav

    NateLiqGrav Alibre Super User

    @albie0803 @idslk
    I got Helical Cuts working by using simulated keyboard key presses. I hope Stefan is ok with me adding this on to his script. :D

    I assume this will be dependent of the language of the menus so you may have to edit TUH to fit a non-English menu. Let me know how it works for you.
     

    Attached Files:

  12. NateLiqGrav

    NateLiqGrav Alibre Super User

    Well on a different pc with v21 it gives an error when trying to select the axis with AlibreScript while the dialog is open. Worked on v22 beta o_O
     
  13. idslk

    idslk Alibre Super User

    you're right. It might (you have to consider a lot of languages...) work, is an interesting and creative idea, but not a really clean solution for me as long as i pay maintainance and alibre is alive..., sorry.:(
    Here i like to say: Alibre please complete (better: extend) the API.
    That means, if i can tweak an object using the API, i should also be able to create it.
    Regards
    Stefan
     
  14. NateLiqGrav

    NateLiqGrav Alibre Super User

    I DEFINITELY AGREE. I've asked support to extend the API to include many things that can only be manually done. Matter of fact I asked them to just go ahead and add ALL manual abilities at once to save me time of asking for them as I need them.

    This was only done in an attempt (exercise of futility) to see if it could be done (and it did work great on my testing machine).
     
  15. idslk

    idslk Alibre Super User

    "only for you" on my computer:
    "It" selects the axis, but fails on the transfer to the input window.

    Regards
    Stefan
     
  16. NateLiqGrav

    NateLiqGrav Alibre Super User

    Yes, that was the same error (only in English) on my pc with v21. Perhaps I'll just try running a compiled AutoHotkey script with parameters instead of attempting to do it all in AlibreScript. With AutoHotkey I won't have any COM issues.
     
  17. albie0803

    albie0803 Alibre Super User

    I did get it to run on V22 with the supplied values. I did have to change the thread direction though.
     
    NateLiqGrav likes this.
  18. NateLiqGrav

    NateLiqGrav Alibre Super User

    Yeah, I still can't figure out what Alibre uses to determine direction. I first thought it had to do with only the origin however further testing showed that wasn't the only cause. But I still don't know what the other thing is. I did about 50 helical cuts in a row to test and couldn't find a reason to direction for them all.

    Some other things:
    As noted in the script I didn't do any realistic thread sketch. I just did a square for testing.

    Radius could be used to narrow down the possible threads for the user to pick from. Since I wasn't doing that I just added thread pitch to the dialog for testing.

    I haven't figured out how to determine if it's interior or exterior cylinder face. I'll probably have to test normal direction?

    I noticed that it doesn't work in assemblies. I hadn't tested in assembly prior to posting it. It's unlikely that I will go through the trouble of fixing it for assemblies.
     

Share This Page