• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor Customization

    Reply
    Active Contributor
    Posts: 37
    Registered: ‎03-03-2010

    Any ideas / advice why this macro does not work

    121 Views, 3 Replies
    10-03-2012 01:48 AM

    Hello All, any input would be much apprciated. 

     

    The macro crashes on the second last line:

     

    "Call oSketch.DimensionConstraints.AddOffset(olines(1), oLine2, oDimCoords(1), False, False)"

     

    Here is the full macro code:

     

    Option Explicit
    Dim oDoc As PartDocument
    Dim oDef As PartComponentDefinition
    Dim oApp As Inventor.Application

    ' CONSTANT SIZES FOR MYLAR CREATION
    Const Mylar_X_Length = 80 'mm
    Const Mylar_Y_Length = 80 'mm
    Const Mylar_Thickness = 20 'mm
    Const Mylar_Width = 20 'mm
    Const Mylar_Fillet = 6 'mm
    Const Mylar_MCAllow = 3 'mm

     

    Public Sub L_Mylar()

    Dim oSketch As PlanarSketch

    Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject, "Z:\TEMPLATES\INVENTOR\Sheet Metal (mm).ipt", True)
    Dim oTransGeom As TransientGeometry
    Set oTransGeom = ThisApplication.TransientGeometry
    Dim oCoords(1 To 8) As Point2d
    Dim oDimCoords(1 To 5) As Point2d
    Dim oArc As SketchArc
    Dim oLine As SketchLine
    Dim olines(1 To 6)
    Dim oLine2 As SketchLine

    Set oDef = oDoc.ComponentDefinition

    Set oCoords(1) = oTransGeom.CreatePoint2d(0, 0)
    Set oCoords(2) = oTransGeom.CreatePoint2d(0, Mylar_Y_Length / 10)
    Set oCoords(3) = oTransGeom.CreatePoint2d(Mylar_X_Length / 10, Mylar_Y_Length / 10)
    Set oCoords(4) = oTransGeom.CreatePoint2d(Mylar_X_Length / 10, (Mylar_Y_Length - Mylar_Thickness) / 10)
    Set oCoords(5) = oTransGeom.CreatePoint2d((Mylar_Thickness + Mylar_Fillet) / 10, (Mylar_Y_Length - Mylar_Thickness) / 10)
    Set oCoords(6) = oTransGeom.CreatePoint2d((Mylar_Thickness + Mylar_Fillet) / 10, (Mylar_Y_Length - Mylar_Thickness - Mylar_Fillet) / 10)
    Set oCoords(7) = oTransGeom.CreatePoint2d((Mylar_Thickness) / 10, (Mylar_Y_Length - Mylar_Thickness - Mylar_Fillet) / 10)
    Set oCoords(8) = oTransGeom.CreatePoint2d((Mylar_Thickness) / 10, 0)

    Set oSketch = oDef.Sketches.Add(oDef.WorkPlanes.Item("XY Plane"))
    oSketch.Name = "SK_00 - PROFILE"

    oSketch.Edit
    Set olines(1) = oSketch.SketchLines.AddByTwoPoints(oCoords(1), oCoords(2))
    Set olines(2) = oSketch.SketchLines.AddByTwoPoints(olines(1).EndSketchPoint, oCoords(3))
    Set olines(3) = oSketch.SketchLines.AddByTwoPoints(olines(2).EndSketchPoint, oCoords(4))
    Set olines(4) = oSketch.SketchLines.AddByTwoPoints(olines(3).EndSketchPoint, oCoords(5))
    Set oArc = oSketch.SketchArcs.AddByCenterStartEndPoint(oCoords(6), olines(4).EndSketchPoint, oCoords(7))
    Set olines(5) = oSketch.SketchLines.AddByTwoPoints(oArc.EndSketchPoint, oCoords(8))
    Set olines(6) = oSketch.SketchLines.AddByTwoPoints(olines(5).EndSketchPoint, olines(1).StartSketchPoint)

    Call oSketch.GeometricConstraints.AddPerpendicular(olines(1), olines(2))
    Call oSketch.GeometricConstraints.AddParallel(olines(1), olines(3))
    Call oSketch.GeometricConstraints.AddParallel(olines(1), olines(5))
    Call oSketch.GeometricConstraints.AddParallel(olines(2), olines(4))
    Call oSketch.GeometricConstraints.AddParallel(olines(2), olines(6))
    Call oSketch.GeometricConstraints.AddTangent(olines(4), oArc)
    Call oSketch.GeometricConstraints.AddTangent(olines(5), oArc)
    Call oSketch.GeometricConstraints.AddGround(olines(1).StartSketchPoint)
    Call oSketch.GeometricConstraints.AddVertical(olines(1))

    Set oDimCoords(1) = oTransGeom.CreatePoint2d(-0.5, oCoords(2).Y / 2)
    Set oDimCoords(2) = oTransGeom.CreatePoint2d(oCoords(3).X / 2, oCoords(3).Y + 0.5)
    Set oDimCoords(3) = oTransGeom.CreatePoint2d(oCoords(3).X + 0.5, oCoords(3).Y - (Mylar_Thickness / 2) / 10)
    Set oDimCoords(4) = oTransGeom.CreatePoint2d(Mylar_Thickness / 10 + 0.5, oCoords(3).Y - (Mylar_Thickness / 2) / 10 - 0.5)
    Set oDimCoords(5) = oTransGeom.CreatePoint2d((Mylar_Thickness / 2) / 10, -0.5)


    Call oSketch.DimensionConstraints.AddOffset(olines(6), olines(2), oDimCoords(1), False, False)
    Call oSketch.DimensionConstraints.AddOffset(olines(1), olines(3), oDimCoords(2), False, False)
    Call oSketch.DimensionConstraints.AddOffset(olines(2), olines(4), oDimCoords(3), False, False)
    Call oSketch.DimensionConstraints.AddRadius(oArc, oDimCoords(4), False)
    Call oSketch.DimensionConstraints.AddOffset(olines(1), olines(5), oDimCoords(5), False, False)

    Dim oCollection As ObjectCollection
    Set oCollection = ThisApplication.TransientObjects.CreateObjectCollection
    oCollection.Add olines(1)
    oCollection.Add olines(2)
    oCollection.Add olines(3)
    oCollection.Add olines(4)
    oCollection.Add oArc
    oCollection.Add olines(5)
    oCollection.Add olines(6)

    Call oSketch.OffsetSketchEntitiesUsingDistance(oCollection, Mylar_MCAllow / 10, False, False, True)
    Set oLine2 = oCollection.Item(1)
    Call oSketch.DimensionConstraints.AddOffset(olines(1), oLine2, oDimCoords(1), False, False)

    oSketch.ExitEdit
    End Sub

     

    Regards
    Rob
    -------------------------------------------
    Windows 7 Pro (X64)
    Intel(R) core (TM) i7-2600 CPU @ 3.40GHz
    16.0 GB RAM
    Nvidia Quadro 600
    Autodesk Inventor 2013 Professional Ultimate Design Suite
    Please use plain text.
    Valued Contributor
    jonbrabbs
    Posts: 76
    Registered: ‎07-26-2007

    Re: Any ideas / advice why this macro does not work

    10-04-2012 06:01 AM in reply to: rvangend

    Hi Rob,

     

    I can help a little. oLine2 = oCollection.Item(1), is refering the your original set of lines, not the offset ones. Therefore you're trying to add a dimension from oLines(1) to oLines(1).

     

    I'm afraid I haven't got any spare time at the moment to look at this further. Hope this gives you a starting point at least.

     

    Kind regards

     

    Jon.

    ///////////////////////////////////////////////////////////////////////////////////////////////////
    If this post helps you, please give kudos.
    \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    Please use plain text.
    Active Contributor
    Posts: 37
    Registered: ‎03-03-2010

    Re: Any ideas / advice why this macro does not work

    10-04-2012 07:14 AM in reply to: rvangend

    Hello Jon,

     

    I realised that after I posted and should probably have deleted the post.

     

    But, Is there any way to iterate the offset group and find the line that matches olines(1) (or oline(2) and so on)  so that I can add a dimension?

     

    Thanks for you input.

     

    Regards

    Rob

    Regards
    Rob
    -------------------------------------------
    Windows 7 Pro (X64)
    Intel(R) core (TM) i7-2600 CPU @ 3.40GHz
    16.0 GB RAM
    Nvidia Quadro 600
    Autodesk Inventor 2013 Professional Ultimate Design Suite
    Please use plain text.
    ADN Support Specialist
    xiaodong.liang
    Posts: 814
    Registered: ‎06-12-2011

    Re: Any ideas / advice why this macro does not work

    10-17-2012 07:23 PM in reply to: rvangend

    Hi,

     

    When you said 'offset group', did you meant by 'oCollection' in the code? A collection can be iterated like below:

     

    Dim oEachObj as Object

    For Each oEachObj in oCollection

       

    Next

     

    If I misunderstood, please feel free to elaborate your question



    Xiaodong Liang
    Developer Technical Services
    Autodesk Developer Network

    Please use plain text.