Monday, October 21, 2013

iLogic: How to learn Inventor's Application Programming Interface (API)

Issue:
You've been somewhat successful using iLogic code examples that you find online, but you'd really like to learn how to create your own code from scratch. So how do these other people find the programming calls to create new code? It seems that there is some missing puzzle piece that you can't seem to locate, something that explains how to get started programming in Inventor. Does something like that exist?  





Solution:
Programming in iLogic involves two different methods, that are often mixed together. The first method is to use "native" iLogic functions, the second is to use "raw" API functions by employing Inventor's Application Programming Interface (API).

  • "Native" iLogic functions are a dictionary of automation functions that deliver the power of Inventor's Application Programming Interface (API) to users by using single-line automation functions. So you can think of iLogic as a collection of the more common programming and automation tasks that the developers have "cleaned" up so that users can create some Rule based automation in their design. This mean that the iLogic dictionary is just a simple subset of the larger API collection. 

  • "Raw" API language can be run using the iLogic tools as well, but will require more knowledge of VB.Net based syntax, and more need to declare and define within the code language. To get started with Inventor's Application Programming Interface (API) you can use the following links. 

**********    **********     **********    **********     **********    **********     **********    **********     **********
This paper provides a brief overview of Inventor’s programming interface and illustrates this with examples using iProperties:

**missing link**
VBA & Inventor API Introduction (zip file - 11.2 MB)

**********    **********     **********    **********     **********    **********     **********    **********     **********



**********    **********     **********    **********     **********    **********     **********    **********     **********
The following resource will help you get started with programming Inventor. It assumes familiarity with Autodesk Inventor and general programming concepts:

DevTV: Introduction to Inventor Programming, a self-paced video tutorial demonstrating how to get started developing with Autodesk Inventor.
View online | Download (zip file- 51.8 MB)
**********    **********     **********    **********     **********    **********     **********    **********     **********



**********    **********     **********    **********     **********    **********     **********    **********     **********
The links above as well as additional information concerning the Autodesk Developer Network resources, can be found at this link:

http://usa.autodesk.com/adsk/servlet/index?id=1079044&siteID=123112

**********    **********     **********    **********     **********    **********     **********    **********     **********

Monday, August 5, 2013

Use 3D Solid Edges for Frame Generator Selection

Issue:
You use the Frame Generator tools in Autodesk Inventor all of the time, but you find that creating the base 3D sketch is tedious, time consuming, and doesn't always take edits well. Is there another way to do this?



Solution:
There are some times when a creating a 3D sketch is required, but often time it's helpful to know that you can use the edges of  a 3D base part to place Frame Generator members. When you select a part edge, Frame Generator automatically projects the geometry into the Frame Reference Model that it creates using the selected edges.

For instance you could create a basic 3D solid part model such as the one shown, and place it into an assembly file:

If you need more edges to use for the frame selection you can edit the base part model, and sketch on the faces of the solid:


 There are times where you might want to create a 3d Sketch based upon 2D sketch geometry. Here a 3D sketch is created and the 2D sketch is projected to the face pf the part to provide more edges to use in the frame. This is done using the 3D Project to Surface tool:
http://wikihelp.autodesk.com/Inventor/enu/2012/Help/3320-Show_Me_3320/3321-Show_Me_3321/3538-3D_Sket...


Often it's helpful to make the base part a clear color so you can see all of the edges to be used for selection:
 In order to prevent the base model from impacting the mass of your assembly, you can set it to Reference:


 Once you are finished selecting edges, you can just turn off the Visibility setting of the base part file, leaving only the frame showing:

Monday, July 29, 2013

Ilogic - Add Standard Virtual Parts From an Excel File

Issue:
You have a number of standard Virtual parts that you find yourself adding over and over. You'd like to have the ability to add them based on a predefined list.

You saw the post about adding these parts from a text file, but you'd like to be able to add standard iProperties for these virtual parts also. This way your Bill of Materials information for the virtual parts can be set when the virtual part is created. So you were wanting to read data from an XLS file that contains all of the information that you typically add for virtual parts.




Solution:
Here is an example iLogic rule that will read a *.xls file and present the contents to the user in an input box list. The user is then asked to enter a quantity for the virtual part, and then the virtual part occurrences are added to the assembly. If one or more occurrences of the virtual part exist in the assembly, the iLogic rule deletes them and just adds back the total number needed.

As the virtual parts are added, the iProperty information found in the *.xls file is added also. 
In this example the parts are placed by using the A column, which is the description. Then the other columns are read in and used to populate the virtual part's iProperties.

An example XLS file list with iProperty information.




Dim MyArrayList As New ArrayList
MyArrayList = GoExcel.CellValues("U:\iLogic examples\Virtual Part List.xls", "Sheet1", "A2", "A1000")
Dim sVirtPart As String
'get user input from list
sVirtPart = InputListBox("Select a virtual part to add.", _
MyArrayList, MyArrayList.Item(0), "iLogic", "Standard Virtual Parts")
'check for empty input in the case where the user cancels out of the input box
If sVirtPart = "" Then
Return 'end rule
Else
End if

'get iProperties from the XLS file
For MyRow = 2 To 1000 'index row 2 through 1000
                'find the cell in column A that matches the user selection
                 If sVirtPart = (GoExcel.CellValue("A" & MyRow)) Then
            'get the iProperty from the XLS file for each column
                oProp1 = GoExcel.CellValue("A" & MyRow )
            oProp2 = GoExcel.CellValue("B" & MyRow )
            oProp3 = GoExcel.CellValue("C" & MyRow)
            oProp4 = GoExcel.CellValue("D" & MyRow)
            oProp5 = GoExcel.CellValue("E" & MyRow)
            Exit For
            End If
Next

'get quantity from user
iQTY = InputBox("Enter the TOTAL number of:" _
& vblf & "        ''" & sVirtPart & "''" _
& vblf & "to place in the assembly." _
& vblf &  vblf & "Note: Enter 0 to delete all existing instances.", "iLogic", "1")
'check for empty input in the case where the user cancels out of the input box
If iQTY = "" Then
Return 'end rule
Else
End if

'define assembly
Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument
'define assembly Component Definition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences in the assembly
Dim asmOcc As ComponentOccurrence
For Each asmOcc  In oAsmCompDef.Occurrences
                'get name of occurence only (sees only everything left of the colon)
                Dim oOcc As Object
            oOcc = asmOcc.name.Split(":")(0)
            'look at only virtual components
                If TypeOf asmOcc.Definition Is VirtualComponentDefinition Then
                        'compare name selected from list to the
                                'existing virtual parts
                                If oOcc = sVirtPart Then
                        'delete existing virtual parts if name matches
                                asmOcc.delete
                                Else
                        End if
            Else
            End If
Next
 
Dim occs As ComponentOccurrences
occs = asmDoc.ComponentDefinition.Occurrences
 
Dim identity As Matrix
identity = ThisApplication.TransientGeometry.CreateMatrix

'create first instance of the virtual part
Dim virtOcc As ComponentOccurrence
if  iQTY >= 1 Then
virtOcc = occs.AddVirtual(sVirtPart, identity)
            Try
            iProperties.Value(sVirtPart & ":1", "Project", "Description") = oProp1
                Catch 'catch error when oProp1 = nothing
                End Try
            Try
            iProperties.Value(sVirtPart & ":1", "Project", "Part Number") = oProp2
                Catch 'catch error when oProp2 = nothing
                End Try
            Try
            iProperties.Value(sVirtPart & ":1", "Project", "Revision Number") = oProp3
                Catch 'catch error when oProp3 = nothing
                End Try
            Try
            iProperties.Value(sVirtPart & ":1", "Project", "Vendor") = oProp4
                Catch 'catch error when oProp4 = nothing
                End Try
            Try
            iProperties.Value(sVirtPart & ":1", "Summary", "Comments") = oProp5
                Catch 'catch error when oProp5 = nothing
                End Try
Else
Return
End if

'add next instance starting at instance2 (if applicable)
Dim index As Integer
index = 2
Do While index <= iQTY
occs.AddByComponentDefinition(virtOcc.Definition, identity)
index += 1
Loop