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

How to collinear constrain a line?

Discussion in 'Alibre Script' started by albie0803, Jul 6, 2019.

  1. albie0803

    albie0803 Alibre Super User

    I define points and create a polyline starting at 0,0 and ending at 0,0, the first 2 points defining what becomes a vertical line from 0,0. How do I then use the constraint command to collinear constrain this line to the Y axis?
     
  2. NateLiqGrav

    NateLiqGrav Alibre Super User

    Hmmm, It seems PolylinePoints can not be used for constraints (according to the error "Exception: Only sketch figures can be passed to AddConstraint" and I'm not sure how to get line segments from the polyline. I also don't see a way to constrain directly to an axis or anything projected from 3d - yet.

    My best suggestion is to create it as individual lines instead of polyline and then add the horizontal or vertical constraints directly to them.

    Code:
    MyPart = Part('My Part')
    MySketch = MyPart.AddSketch('SomeName', MyPart.XYPlane)
    
    p1 = [0, 0]
    p2 = [0, 10]
    p3 = [10, 10]
    p4 = [10, 5]
    
    line1 = MySketch.AddLine(p1, p2, False)
    line2 = MySketch.AddLine(p2, p3, False)
    line3 = MySketch.AddLine(p3, p4, False)
    
    MySketch.AddDimension(line1.Start, line1.End)
    MySketch.AddDimension(line2.Start, line2.End)
    MySketch.AddDimension(line3.Start, line3.End)
    
    result = MySketch.AddConstraint([line1],Sketch.Constraints.Vertical)
    print(result)
    result = MySketch.AddConstraint([line2],Sketch.Constraints.Horizontal)
    print(result)
    result = MySketch.AddConstraint([line3],Sketch.Constraints.Vertical)
    print(result)
     
  3. NateLiqGrav

    NateLiqGrav Alibre Super User

    Note: AddDimension and AddConstraint are 2019 beta features.
     
  4. ajayre

    ajayre Alibre Super User

    You can eliminate a line with:

    Code:
    result = MySketch.AddConstraint([line1, line3],Sketch.Constraints.Vertical)
    print(result)
    Andy
     
    NateLiqGrav likes this.
  5. idslk

    idslk Alibre Super User

    :eek:
    and i tried and tried and tried:mad::mad:
    :D
     
  6. NateLiqGrav

    NateLiqGrav Alibre Super User

    ;) I did that originally and thought it may be clearer to others separate.

    You need to let the dust settle on my posts more. :D
     
  7. albie0803

    albie0803 Alibre Super User

    @NateLiqGrav Thanks! I came to the same conclusion thinking about it last night in bed that I would have to use individual lines rather than a polyline for constraining. Being able to add constraints and dimensions will help immensely in scripts. At the moment scripted sketches are great unless you need to manually edit them.
     
  8. albie0803

    albie0803 Alibre Super User

    I load variables into polyline points from an excel file. The file has 2 columns: diameter and length. I start by measuring a shaft and entering all the steps in it. I did one shaft that had 15 steps in it. The point being I will never have a set amount of variables.

    From looking at the above discussion, I need to define lines to use dimension or constrain.

    How do I define the name of a variable on the fly?


    line1 = MySketch.AddLine(p1, p2, False)
    line2 = MySketch.AddLine(p2, p3, False)
    line3 = MySketch.AddLine(p3, p4, False)
    etc
    linex = MySketch.AddLine(py, pz, False)

    or will I have to have twenty or so pre defined and have the code drop out when all values have been imported?
     
    Last edited: Jul 8, 2019
  9. idslk

    idslk Alibre Super User

    Hello colleagues,

    isn't that valid in 2019?
    if it is still valid, trying to assign a line to a variable won't be successful...
    if it is overhauled in V2019 in some kind, try this:
    Code:
    cp = CurrentPart()
    mysketch = cp.AddSketch('MySketch', cp.XYPlane)
    
    lines = []
    p = [[10,13],[24,10],[18,26],[44,36]]
    #Fill p with values from whereever, using some analogous like p.append(excelcells) or so
    
    for i in range(0,len(p),2):
      print p[i]
      lines.append(mysketch.AddLine(p[i], p[i+1], False))
    
    print lines
    print 'done'
    
    Regards
    Stefan
     
  10. ajayre

    ajayre Alibre Super User

    Code:
    MyLines = []
    MyLines.append(MySketch.AddLine(...))
    for Line in MyLines:
      ...
    
    Andy
     
  11. NateLiqGrav

    NateLiqGrav Alibre Super User

    When I said this it was prior to having that ability in the 2019 beta. But the point I was trying to make still stands: We need to look at the reference to see what is expected to be returned (or if anything is at all).
     
  12. albie0803

    albie0803 Alibre Super User

    @ajayre Can we get a list of constraint types that work please?

    I want to be able to constrain a line end/start to the origin point. To anchor the sketch but still have it flexible (if that makes sense)

    Profile.AddConstraint([Line.Start, Profile.Origin],Sketch.Constraints.Concentric)

    Thanks to all for your input. Except for this last line I have the script now doing what I want. Now just have to wait for 2019 to be released.
     
  13. ajayre

    ajayre Alibre Super User

    That's a question for Alibre not me. Unless I am misunderstanding something?

    Andy
     
  14. NateLiqGrav

    NateLiqGrav Alibre Super User

    From my post in the Beta forum:

    The (AlibreScript) documentation however does not list the options and only says:
     
  15. NateLiqGrav

    NateLiqGrav Alibre Super User

    For now this should give the list:
    Code:
    print(dir(Sketch.Constraints))
     
    ajayre likes this.
  16. ajayre

    ajayre Alibre Super User

    This is fixed for the next beta (or full release) of AD. But that's a documentation issue rather than what works or doesn't as you found out with the ordering of adding constraints.

    Andy
     
    NateLiqGrav likes this.
  17. albie0803

    albie0803 Alibre Super User

    ['Coincident', 'Collinear', 'CompareTo', 'Coradial', 'Equal', 'Equals', 'Fix', 'Format', 'GetHashCode', 'GetName', 'GetNames', 'GetType', 'GetTypeCode', 'GetUnderlyingType', 'GetValues', 'HasFlag', 'Horizontal', 'Intersection', 'IsDefined', 'MemberwiseClone', 'Midpoint', 'Normal', 'Parallel', 'Parse', 'Perpendicular', 'ReferenceEquals', 'Symmetric', 'Tangent', 'ToBoolean', 'ToByte', 'ToChar', 'ToDateTime', 'ToDecimal', 'ToDouble', 'ToInt16', 'ToInt32', 'ToInt64', 'ToObject', 'ToSByte', 'ToSingle', 'ToString', 'ToType', 'ToUInt16', 'ToUInt32', 'ToUInt64', 'TryParse', 'Vertical', '__and__', '__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__invert__', '__le__', '__lt__', '__ne__', '__new__', '__nonzero__', '__or__', '__rand__', '__reduce__', '__reduce_ex__', '__repr__', '__ror__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__xor__', 'value__']

    So Concentric is not an option so

    is not possible. I would have thought that being able to anchor a line end or circle centre to the origin would have been one of the first thing to be done. :confused: Oh well. :(
     
  18. albie0803

    albie0803 Alibre Super User

    Why does this line

    Code:
     
    Profile = P.AddSketch("Profile", P.GetPlane("XY-Plane"))
    Profile.AddConstraint([Line, Profile.YAxis],Sketch.Constraints.Collinear)
    throw the following error?

    Code:
    AttributeError: 'Sketch' object has no attribute 'YAxis'
     
    Last edited: Jul 16, 2019 at 1:47 AM
  19. ajayre

    ajayre Alibre Super User

    The axes don't really exist in sketches when looking at the AD API. What you want to do is not supported in the AD API as far as I can tell - submit a request to support.

    Also if you want concentric constraints then submit a request to support... Andy
     
  20. NateLiqGrav

    NateLiqGrav Alibre Super User

    The new beta does list available options in the reference. No need to print that anymore.

    Neither of those objects are circles or arcs. They are sketchpoints. Try Coincident instead.

    Concentric is just a shortcut to make arcs and circles have the same center point. So internally it gets the centers and does a Coincident constraint with some makeup of a different icon.
     

Share This Page