Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create a Macro

5 REPLIES 5
Reply
Message 1 of 6
kalpesh_43
3081 Views, 5 Replies

How to create a Macro

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

5 REPLIES 5
Message 2 of 6
chrisrodway
in reply to: kalpesh_43

Message 3 of 6
jtylerbc
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. 

Message 4 of 6
chrisrodway
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
Message 5 of 6
jtylerbc
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

 

Message 6 of 6

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report