Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using Linq with Inventor iLogic

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
AlexFielder
894 Views, 2 Replies

Using Linq with Inventor iLogic

This seems like it should be easy, but I can't get the following piece of iLogic to run even with "Imports System.Linq" at the top:

 

'AddReference "System.Web"
AddReference "System.Linq"
Imports System.Linq
Imports System.IO
Imports System.Collections.Generic

Sub Main()
Call BeginCreateAssemblyStructure
End Sub

Sub BeginCreateAssemblyStructure
'define the parent assembly
Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument
Dim filename As String = System.IO.Path.GetFileNameWithoutExtension(ThisApplication.ActiveDocument.Displayname)
Dim filetab As String = InputBox("Which project?", "4 Letter Project Code", "ABCD") + "-MODELLING-BASELINE"
Dim PartsList As List(Of SubObjectCls)
PartsList = New List(Of SubObjectCls)
'debug
MessageBox.Show(PartsList.Count, "Parts List Count")
Dim FilesArray As New ArrayList 
Dim tr As transaction

tr = ThisApplication.TransactionManager.StartTransaction( _
    ThisApplication.ActiveDocument, _
    "Create Standard Parts From Excel")
'this is to simply set the excel values to the correct file/tab- nothing more!
FileArray = GoExcel.CellValues("C:\VAULT WORKING FOLDER\Designs\Project Tracker.xlsx", filetab , "A3" , "A4") ' sets excel to the correct sheet!

'Data collection:
For MyRow = 3 To 5000 ' max limit = 5000 rows for debugging purposes
	Dim SO As SubObjectCls 
	SO = New SubObjectCls
	If GoExcel.CellValue("A"& MyRow) = "" Then Exit For 

	SO.Partno = GoExcel.CellValue("B" & MyRow)
	SO.LegacyDescr = GoExcel.CellValue("K" & MyRow)
	SO.LegacyRev = GoExcel.CellValue("L" & MyRow)
	SO.LegacyDrawingNo = GoExcel.CellValue("M" & MyRow)
	SO.ParentAssembly = GoExcel.CellValue("I" & MyRow)
	
	PartsList.Add(SO)
Next
MessageBox.Show(PartsList.Count, "Parts List Count")
'sort our list of parts
PartsList.Sort()

Dim r = From a As SubObjectCls In PartsList Where a.PartNo.StartsWith("AS-") And a.ParentAssembly = filename Select a '<-- ERROR IS AT THIS LINE

For i = 0 To r.Count -1
	MessageBox.Show(r(i).PartNo + vbCrLf + r(i).ParentAssembly,"Info in part #" + i.ToString())
Next i										 
For i = 0 To PartsList.Count - 1
	'MessageBox.Show(PartsList(i).PartNo,"Part No in part: " + i.ToString())
Next

End Sub

Public Class SubObjectCls
	Public PartNo As String
	Public LegacyDescr As String
	Public LegacyRev As String
	Public LegacyDrawingNo As String
	Public ParentAssembly As String
	
	Public Sub Init(m_partno As String,
					m_legacydescr As String,
					m_legacyrev As String,
					m_legacydrawingno As String,
					m_parentassy As String)
		PartNo = m_partno
		LegacyDescr = m_legacydescr
		LegacyRev = m_legacyrev
		LegacyDrawingNo = m_legacydrawingno
		ParentAssembly = m_parentassy
	End Sub
End Class

 Does anyone have any ideas why this isn't working? (The error message I receive is: 

 

"Error on Line 64 : Expression of type 'System.Collections.Generic.List(Of LmiRuleScript.SubObjectCls)' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider."

 

Thanks,

 

Alex.

Tags (2)
2 REPLIES 2
Message 2 of 3

Hi Alex,

 

Try that: http://msdn.microsoft.com/en-us/library/bb763092.aspx

 

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 3

Hi Philippe,

 

That's the exact same link I ended up at yesterday- I have now added a "CompareTo" function to my class so that it now looks like this:

 

Public Class SubObjectCls
        Implements IComparable(Of SubObjectCls)
        Public PartNo As String
        Public LegacyDescr As String
        Public LegacyRev As String
        Public LegacyDrawingNo As String
        Public ParentAssembly As String
        Public HasChildren As Boolean
        Public Children As List(Of SubObjectCls)

        Public Sub Init(m_partno As String,
                        m_legacydescr As String,
                        m_legacyrev As String,
                        m_legacydrawingno As String,
                        m_parentassy As String,
                        m_haschildren As Boolean,
                        m_children As List(Of SubObjectCls))
            PartNo = m_partno
            LegacyDescr = m_legacydescr
            LegacyRev = m_legacyrev
            LegacyDrawingNo = m_legacydrawingno
            ParentAssembly = m_parentassy
            HasChildren = m_haschildren
            Children = m_children
        End Sub
        Public Function CompareTo(other As SubObjectCls) As Integer Implements IComparable(Of SubObjectCls).CompareTo
            Return Me.CompareTo(other)
        End Function
    End Class

 And Linq is quite happy doing it's stuff.

 

That's not to say of course that my iLogic subroutine is working how I'd like however- I still have a few bugs to iron out with creating sub-assemblies/parts...

 

I will update the other post I made yesterday when I have something that works 100% of the time using the above class.

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

Post to forums  

Autodesk Design & Make Report