port ilogic code to vb.net

port ilogic code to vb.net

hozz__
Enthusiast Enthusiast
881 Views
5 Replies
Message 1 of 6

port ilogic code to vb.net

hozz__
Enthusiast
Enthusiast

I'm trying to port this function to vb.net and  get "Type not defined errors" when I try to declare the Asset and Asset Library object variables. My thought was that adding "Imports Inventor" to the header would be sufficient to get past the error, but no luck...apparently I'm missing a step that is likely right in my face, but I can't see it. Any guidance would be appreciated

 

Private Function GetAsset(oDoc As PartDocument, anAssetName As String) As Asset
	Try
	    GetAsset = oDoc.Assets.Item(anAssetName)
    
	Catch
        
        ' Failed to get the appearance in the document, so import it.
        
        ' Get an asset library by name.  Either the displayed name (which
        ' can changed based on the current language) or the internal name
        ' (which is always the same) can be used.
	Dim assetLib As AssetLibrary 'Type "AssetLibrary" defined error here
        assetLib = ThisApplication.AssetLibraries.Item("MG_Material")
        
        ' Get an asset in the library.  Again, either the displayed name or the internal
        ' name can be used.
        Dim libAsset As Asset 'Type "Asset" defined error here
        libAsset = assetLib.AppearanceAssets.Item(anAssetName)
        
        ' Copy the asset locally.
         GetAsset = libAsset.CopyTo(oDoc)
		 oWrite.WriteLine(vbTab & vbTab & Now & " -SUCCESS- Assigning asset """ & anAssetName & """")
    End Try	
End Function

 

0 Likes
Accepted solutions (2)
882 Views
5 Replies
Replies (5)
Message 2 of 6

JamieVJohnson2
Collaborator
Collaborator

I copied your code into my VB development environment.  There are only 2 errors:

ThisApplication - replace with Inventor.Application acquired via some other method (such as invApp = Marshal.GetActiveObject("Inventor.Application"))

oWrite.WriteLine - this is a iLogic IDE exclusive tool, you can use 

Debug.Print("some string value") or msgbox("some string value") instead.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 6

JamieVJohnson2
Collaborator
Collaborator
    Private Function GetAsset(oDoc As PartDocument, anAssetName As String) As Asset
        Try
            GetAsset = oDoc.Assets.Item(anAssetName)

        Catch

            ' Failed to get the appearance in the document, so import it.

            ' Get an asset library by name.  Either the displayed name (which
            ' can changed based on the current language) or the internal name
            ' (which is always the same) can be used.
            Dim assetLib As AssetLibrary 'Type "AssetLibrary" defined error here
            assetLib = invApp.AssetLibraries.Item("MG_Material")

            ' Get an asset in the library.  Again, either the displayed name or the internal
            ' name can be used.
            Dim libAsset As Asset 'Type "Asset" defined error here
            libAsset = assetLib.AppearanceAssets.Item(anAssetName)

            ' Copy the asset locally.
            GetAsset = libAsset.CopyTo(oDoc)
            Debug.Print(vbTab & vbTab & Now & " -SUCCESS- Assigning asset """ & anAssetName & """")
        End Try
    End Function
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 4 of 6

hozz__
Enthusiast
Enthusiast

My bad, I posted the iLogic code that I started with instead of the Vb.net code that doesn't work. I've already dealt with the issues you noted...

Private Function GetAsset(oDoc As PartDocument, anAssetName As String) As Asset
    Try
	    GetAsset = oDoc.Assets.Item(anAssetName)
    
    Catch
        
        ' Failed to get the appearance in the document, so import it.
        
        ' Get an asset library by name.  Either the displayed name (which
        ' can changed based on the current language) or the internal name
        ' (which is always the same) can be used.
 
 
 	Dim assetLib As AssetLibrary
		
	assetLib = App.AssetLibraries.Item("MG_Material")
        
        ' Get an asset in the library.  Again, either the displayed name or the internal
        ' name can be used.
            
Dim libAsset As Asset libAsset = assetLib.AppearanceAssets.Item(anAssetName) ' Copy the asset locally. GetAsset = libAsset.CopyTo(oDoc) End Try End Function

 

The only code giving me errors in the IDE are the following two lines

 

	Dim assetLib As AssetLibrary

        Dim libAsset As Asset

Both the "Asset" and "AssetLibrary" declarations give me "Type is not defined" errors. My assumption is that I missed a reference in the header...

 

Imports System.Windows.Forms
Imports Inventor
Imports Inventor.UnitsTypeEnum

 

 

 

0 Likes
Message 5 of 6

JamieVJohnson2
Collaborator
Collaborator
Accepted solution

Imports Inventor is the correct item to have (you have it), if that is failing check project references for Autodesk.Inventor.Interop (Autodesk Inventor Object Library) (see my screen shot - using Inventor 2020.2.1).

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 6 of 6

hozz__
Enthusiast
Enthusiast
Accepted solution

That got me to where I needed to be...I ended up removing and re adding the reference to Autodesk.Inventor.Interop and the errors went away...i expect I was likely referencing an old version of the assembly. thanks for your help Jamie!