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

    Autodesk Inventor

    Reply
    Member
    Posts: 3
    Registered: ‎01-03-2013

    How to create a Macro

    212 Views, 5 Replies
    01-16-2013 01:24 AM

    Hello Guys,

    I am using inv2011. I have to create rec. blocks very often and in inv2011 . I have to constraint it in middle.

    Can i write a Macto that gives me constraint rec block in sketch. This feature already available in Inv12.

     

    Thanks

    Please use plain text.
    Active Contributor
    chrisrodway
    Posts: 34
    Registered: ‎10-11-2012

    Re: How to create a Macro

    01-16-2013 01:33 AM in reply to: kalpesh_43
    Please use plain text.
    *Expert Elite*
    jtylerbc
    Posts: 617
    Registered: ‎09-01-2010

    Re: How to create a Macro

    01-16-2013 06:42 AM in reply to: chrisrodway

    chrisrodway wrote:

    You dont have the ability to write macros in Inventor 2013 but you can automate some of the design process using ilogic.

     

     



    I don't have enough skill with them to be able to help the OP with his request, but VBA macros are still available in Inv 2013. 

    John Tyler
    Inventor 2013
    Windows 7 64 Bit
    Please use plain text.
    Active Contributor
    chrisrodway
    Posts: 34
    Registered: ‎10-11-2012

    Re: How to create a Macro

    01-16-2013 07:02 AM in reply to: kalpesh_43

    Yea sorry I miss spoke, I ment you dont have the abilty to record macros in inventor so i thought ilogic might be the better may to go.

     

    Cheers

    Chris Rodway
    Design Engineer
    Sheffield, UK
    Please use plain text.
    *Expert Elite*
    jtylerbc
    Posts: 617
    Registered: ‎09-01-2010

    Re: How to create a Macro

    01-16-2013 07:15 AM in reply to: chrisrodway

    Yes, that's true, and unfortunately that feature has never existed (would be nice though).

     

    kalpesh_43, I did some digging around.  We used to use a macro that will (I think) do what you want, but took it out of our macro files when we set up 2013 since it had a function that replaces it.  Fortunately I kept an exported copy of it for reference.  This is based on one I found online somewhere a while ago, then modified slightly (mostly to add error catches that didn't exist in the original).  I would give credit to the originator, but don't recall who that is.

     

     

    Sub InitialRectangle()
    
     ' Make sure a part document is active.
        If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then
            MsgBox "Must have a part active", vbOKOnly, "Error"
            
        Else
    
    
    Dim oPartDoc As PartDocument 'for the active part
    Dim oCompDef As PartComponentDefinition
    Dim oSketch As PlanarSketch
    Dim oLines(1 To 4) As SketchLine 'each of the 4 sides of the rectangle
    Dim oRectLines As SketchEntitiesEnumerator
    Dim count As Integer
    Dim XVal As Integer
    Dim YVal As Integer
    Dim bFoundOrigin As Boolean
    Dim oTransGeom As TransientGeometry
    Dim oDiagonalLine As SketchLine 'the diagonal line in the rectangle
    Dim oOriginPoint As SketchPoint
    Dim oOrigin As WorkPoint
    
    Set oPartDoc = ThisApplication.ActiveDocument
    
    
    
    
    If oPartDoc.SketchActive = True Then 'check to ensure you have a sketch active
        Set oCompDef = oPartDoc.ComponentDefinition ' Set a reference to the component definition.
        Set oSketch = oCompDef.Sketches.Item(oCompDef.Sketches.count)
        XVal = 3 'set this to half the horizontal size you want the rectangle to be IN CENTIMETERS
        YVal = 2 'set this to half the vertical size you want the rectangle to be IN CENTIMETERS
        bFoundOrigin = False
        Set oTransGeom = ThisApplication.TransientGeometry 'Set a reference to the transient geometry object.
    If oSketch.SketchPoints.count > 0 Then 'try to find if the origin has been projected already
        For count = 1 To oSketch.SketchPoints.count
            If oSketch.SketchPoints(count).Geometry.X = 0 And oSketch.SketchPoints(count).Geometry.Y = 0 Then
                bFoundOrigin = True 'if you have found the origin, keep a ref to it
                Exit For
            End If
        Next
    End If
    With oTransGeom 'Draw the 2-point rectangle
        Set oRectLines = oSketch.SketchLines.AddAsTwoPointRectangle(.CreatePoint2d(-XVal, -YVal), .CreatePoint2d(XVal, YVal))
        Set oDiagonalLine = oSketch.SketchLines.AddByTwoPoints(.CreatePoint2d(XVal, -YVal), .CreatePoint2d(-XVal, YVal))
        oDiagonalLine.Construction = True
        With oSketch.GeometricConstraints
            Call .AddCoincident(oDiagonalLine.StartSketchPoint, oRectLines(1))
            Call .AddCoincident(oDiagonalLine.StartSketchPoint, oRectLines(2))
            Call .AddCoincident(oDiagonalLine.EndSketchPoint, oRectLines(3))
            Call .AddCoincident(oDiagonalLine.EndSketchPoint, oRectLines(4))
        End With
        If bFoundOrigin = False Then
            Set oOrigin = oCompDef.WorkPoints.Item(1)
            Set oOriginPoint = oSketch.AddByProjectingEntity(oOrigin)
            With oSketch.GeometricConstraints
                Call .AddMidpoint(oOriginPoint, oDiagonalLine)
            End With
        Else
            With oSketch.GeometricConstraints
                Call .AddMidpoint(oSketch.SketchPoints(count), oDiagonalLine)
            End With
        End If
    End With
    Else
        MsgBox "There is no sketch active. Operation Terminated.", vbCritical
    End If
    End If
    End Sub

     

    John Tyler
    Inventor 2013
    Windows 7 64 Bit
    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,944
    Registered: ‎03-08-2006

    Re: How to create a Macro

    01-16-2013 07:35 AM in reply to: kalpesh_43

    Hi kalpesh_43

    Additionally there is this:

    http://www.mcadforums.com/forums/viewtopic.php?f=34&t=11365

     

    I hope this helps.
    Best of luck to you in all of your Inventor pursuits,
    Curtis
    http://inventortrenches.blogspot.com



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.