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

Referencing a face in an assembly

Discussion in 'Alibre Script' started by albie0803, Jun 11, 2019.

  1. albie0803

    albie0803 Alibre Super User

    I was playing with Oldfox's latest metric screw script and modified it to add the created part to an open assembly. The default command values inserts the new part at 0,0,0 which was and most likely will always be in the middle of an existing part.
    I considered offsetting the insertion point but how to know how much is enough.
    I then wondered if I could insert it and then move it by creating a constraint between the YZ plane of the screw and a face on the assembly as chosen in a dialog box. I know you can do this with a part (I do so in my keyway script) but is it possible to select a face in an assembly? I'm pretty sure this was looked at but I can't find any reference to it.
    I realise there is a 50/50 chance that the orientation will be wrong but I don't care. It will be where I can easy get to it and fix/complete the constraints.
     
  2. idslk

    idslk Alibre Super User

    Hello albie0803,

    fresh avatar...
    I've tried this some times ago... faces "can" be selected but i haven't had success using them...
    Code:
    win = Windows()
    options = []
    values = []
    own_face = None
    options.append(['select an face' , WindowsInputTypes.Face , None])
    values = win.OptionsDialog( 'Test', options , 180 )
    own_face = values[0]
    print own_face
    You can use the snipplet as it is in an assembly...
    In the input box the "complete name" including the part is shown.
    In the printed output the part of the selected face "gets lost"...and i didn't found a way to get the partname recovered.
    Maybe Andy can shed a little light on this...

    Regards
    Stefan
     
  3. albie0803

    albie0803 Alibre Super User

    I think this might be the current answer. We will have to see what Andy has added to the next version and how it actually works.
     
  4. oldfox

    oldfox Alibre Super User

    Always that old bugaboo when you insert common parts into an assembly. (or build the part in the wrong orientation in the first place:()
     
  5. albie0803

    albie0803 Alibre Super User

    The 50/50 I was referring to was whether you need a mate or an align.
     
  6. oldfox

    oldfox Alibre Super User

    Yep. That one usually results in my choosing of the wrong "50". :oops:
     
  7. idslk

    idslk Alibre Super User

    Hey colleagues,
    if you align 2 faces with 4 eyes on them, the will be looking at you at the same level (except you've inputted an offset)
    If you mate the 2 faces with 4 eyes on them, the faces will lay face on face
    Will this help to get 49/51?
    upload_2019-6-11_15-34-0.png

    Regards
    Stefan
     
  8. oldfox

    oldfox Alibre Super User

    Cool graphical explanation. Maybe even 25/75. :cool:

    What I have noticed in my own work when I have this confusion is that the "free" part will flip 180 from how I want it. I think I may have caught
    onto the hint. If it can be either mate or align. then I probably need to mate. If Mate is greyed out, then that only leaves Align.
     
  9. NateLiqGrav

    NateLiqGrav Alibre Super User

    This should work in the 2019 release.
     
  10. ajayre

    ajayre Alibre Super User

    I just tried it in the 2019 beta and it seems to be working. Am I missing something I should be aware of?

    EdgeSelection.gif

    Andy
     
  11. NateLiqGrav

    NateLiqGrav Alibre Super User

    I'm assuming they are waiting for 2019 official release. It worked good for me in beta.
     
  12. albie0803

    albie0803 Alibre Super User

    Ok, I seem to be getting what I want, I just need help with the syntax for the constraint statement.

    I want to constrain a plane from the script added bolt to a face in the assembly but keep getting an error on the last bit.

    #Get the face and partname from the clicked on face
    F1 = own_face #Face
    P1 = own_face.GetPart() #Part

    Assy.AddMateConstraint(0, Screw, Screw.GetPlane("YZ-Plane"), P1, P1.GetFace(F1))

    it keeps throwing AttributeError: 'str' object has no attribute 'GetFace'

    Thanks in advance
     
  13. NateLiqGrav

    NateLiqGrav Alibre Super User

    A)
    Part.GetFace() requires a string and you are passing a face object.
    You would need to force it to pass as a string by wrapping in str() function like so:
    Part.GetFace(str(F1))

    B)
    Why do a Face.GetPart() and then do Part.GetFace() anyways? - You have both things already after doing the Face.GetPart().

    Assy.AddMateConstraint(0, Screw, Screw.GetPlane("YZ-Plane"), P1,F1)


    This works in the 2019 beta:
    Code:
    Win = Windows()
    Options = []
    Options.append(['Part1', WindowsInputTypes.Part, None])
    Options.append(['Part2 Face', WindowsInputTypes.Face, None])
    Values = Win.OptionsDialog("Constrain Part To Face",Options, 400)
    Part1 = Values[0]
    Part2Face = Values[1]
    Part2 = Part2Face.GetPart()
    # this example doesn't do any error checking.
    
    Assy = CurrentAssembly()
    Assy.AddMateConstraint(0, Part1, Part1.YZPlane, Part2, Part2Face)
    # note I switched to the language independent Part1.YZPlane instead of Part1.GetPlane("YZ-Plane")
     
    ajayre likes this.
  14. albie0803

    albie0803 Alibre Super User

    Thankyou to all involved in helping me achieve my goal.

    With your help I have been able to modify Oldfox's excellent screw program so that screws can be inserted directly into an existing assembly and then mate them to an selected external face so that I don't have to go digging for it to correctly position it
     
    NateLiqGrav and oldfox like this.
  15. oldfox

    oldfox Alibre Super User

    Glad to see it was of some help in your work. I sure would like to see the additions. Well done.
     
  16. albie0803

    albie0803 Alibre Super User

    Oldfox, here is my final script.
    Changes I made:
    Remove the Save location option as I use M-Files
    Add reference to Assembly and change New Part to New Assembly Part
    Ask for face to mate to
    Create Mate Constraint so that the fastener is where I can find it

    I have in mind to now look at creating a bolt/washer/washer/nut sub assembly and inserting it mated to a face in the same way
     

    Attached Files:

    oldfox likes this.
  17. oldfox

    oldfox Alibre Super User

    Good 'next step' choice. Mate the nut/washer and align that to bolt and you will be ready to torque it down.:cool:
    And maybe the 'second next step' would be to make the bolt to length and then make the assembly and then place that in the final appropriate
    assembly, constrained exactly where it should go. All with one monster, humongus script. :D
     
  18. albie0803

    albie0803 Alibre Super User

    That's the idea!
     

Share This Page