• Blog posts

    Bio

    by Luke Davenport

    Hello again,

     

    I’ve been spending a fair amount of time with some architectural CAD friends recently, and thinking about best practices for using Inventor in construction. Quite frequently there has been a need to create architectural gridlines that need to be referenced both in the model and the drawing environment. Work planes would be the obvious choice for this, but it can be a little tiresome to create and name dozens of workplanes, as well as the parameters that control their offsets.

     

    Architects don’t always use regularly spaced gridlines you see, so a pattern/array of planes won’t do the job…..

     

    So I thought I’d invest a happy hour to write a quick iLogic macro to automate this for anyone in the same boat.

     

    Just click on the picture above to see a quick video of this in action. Here is the iLogic code:

     

    (As always be careful not to add new lines when copying and pasting this code into a new iLogic rule)

     

    Enjoy!

     

    ' Start of iLogic code - remember to subscribe to Luke Davenport's blog

    ' http://www.cadlinecommunity.co.uk/Blogs/LukeDavenport/Default.aspx

    ' And why not follow him on twitter @LukeCadline

     

    Imports Inventor.SelectionFilterEnum

     

    Sub Main

     

    Dim Title As String = "Cadline iLogic"

    Dim Cont As Boolean = True

    Dim Counter As Integer = 1

     

    oDoc = ThisDoc.Document

    If oDoc.DocumentType = kAssemblyDocumentObject OrElse oDoc.DocumentType = kDrawingDocumentObject Then

        MessageBox.Show("This tool can only be used in a part file!", Title, _

        MessageBoxButtons.Ok,MessageBoxIcon.Exclamation, _

        MessageBoxDefaultButton.Button1)

        Return

    End If

     

    Dim oPartCompDef As PartComponentDefinition = oDoc.ComponentDefinition

    Dim oWorkPlanes As WorkPlanes = oPartCompDef.WorkPlanes

    Dim oFilter As SelectionFilterEnum

    oFilter = kWorkPlaneFilter

     

    ' Turn origin planes on

    For a = 1 To 3

        oWorkPlanes.Item(a).Visible = True

    Next

     

    ' Get start plane from user

    oStartPlane = ThisApplication.CommandManager.Pick(oFilter, "Select Start Plane")

    GridlineName = InputBox("Enter Name of Grid Planes", Title, "GL")

     

    If GridlineName = "" Then

    Cleanup(oWorkPlanes)

    Return

    End If

     

    Call MakePlane(oStartPlane, oWorkPlanes, GridlineName, Counter, Title, False,1000)

    Cleanup(oWorkPlanes)

     

    End Sub

     

    Sub MakePlane(ByVal oPlane As WorkPlane, _

                  ByRef oWorkPlanes As WorkPlanes, _

                  ByVal GridlineName As String, _

                 ByRef Counter As Integer, _

                  ByVal Title As String, _

                  ByRef Finish As Boolean, _

                  ByRef StartNo As Double)

               

    Do While Finish = False

    CountString = Counter.ToString("D4")

     

    Offset = InputBox("Enter Plane Offset in mm (From Previous)" & vbLf & vbLf & _

    "Hit cancel to finish", Title, StartNo)

     

    If Offset = "" Then

        Exit Sub

        Else If Not IsNumeric(Offset) Then

        Exit Sub

    End If

     

    ' Create work plane

    Dim oNewWorkPlane As WorkPlane

    oNewWorkPlane = oWorkPlanes.AddByPlaneAndOffset(oPlane, GridlineName & CountString & " = " & CDbl(Offset))

    Try

    oNewWorkPlane.Name = GridlineName & CountString

    Catch

    End Try

    ' Increment counter

    Counter += 1

    MakePlane(oNewWorkPlane, oWorkPlanes, GridlineName, Counter, Title, False, Offset)

    Return

     

    Loop

     

    End Sub

     

    Sub Cleanup(ByVal oWorkPlanes As WorkPlanes)

    ' Turn origin planes off

    For a = 1 To 3

        oWorkPlanes.Item(a).Visible = False

    Next

    End Sub

     

    ' ********************** End of iLogic code **********************