Hi PV,
I was able to recreate the error with the VB project. (provided privately)
The solution I found was to change the code so that context.Type was set correctly. With these changes the error went away ant the PRT file was opened in Inventor.
Also one of the main differences between VBA and VB is the use of Set statements to instantiate an object. (VB.NET does not use Set statements)
Friend Class ButtonOneCmd
Inherits Command
Dim strCLSld As String
'WB commented
' Private Property kDataDropIOMechanism As IOMechanismEnum
Public Overrides Sub StartCommand()
' call base command button's StartCommand (to also start interaction)
' MyBase.StartCommand()
'MsgBox("Inventor Sample Prog. This is for NX Import Issue")
'MessageBox.Show("Starting NX File Import")
ImportNXFile()
End Sub
Public Overrides Sub SelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View)
MsgBox("Please select an object.")
End Sub
Sub ImportNXFile()
Try
' Set NX translator's CLSID and the NX file name.
' Dim strCLSID As String
Dim strFileName As String
' The following statement is throwing error
' 'strCLSld' is not declared. It may be inaccessible due to its protection level.
' So allowed Visual Studio to add the declaration in line 8 and commented line 33
strCLSld = "{93D506C4-8355-4E28-9C4E-C2B5F1EDC6AE}"
' Please set the full file name here, such as "C:\Part1.prt"
strFileName = "C:\Temp\AssyCrane.prt"
If (Not (System.IO.File.Exists(strFileName))) Then
MessageBox.Show("Component File >" + strFileName + "< does not exist")
Return
End If
Dim oAddIns As ApplicationAddIns
oAddIns = InventorApplication.ApplicationAddIns
' Find the NX translator, get the CLSID and activate it.
Dim oTransAddIn As TranslatorAddIn
oTransAddIn = oAddIns.ItemById(strCLSld)
oTransAddIn.Activate()
' Get the transient object and take it as a factory to produce other objects.
Dim transientObj As TransientObjects
transientObj = InventorApplication.TransientObjects
' Prepare the first parameter for Open(), the file name.
' MessageBox.Show("NX File Import --- First Parameter")
Dim file As DataMedium
file = transientObj.CreateDataMedium
file.FileName = strFileName
' Prepare the second parameter for Open(), the open type.
' MessageBox.Show("NX File Import --- Second Parameter")
Dim context As TranslationContext
context = transientObj.CreateTranslationContext
'context.Type = kDataDropIOMechanism
'WB added
context.Type = IOMechanismEnum.kDataDropIOMechanism
' Prepare the third parameter for Open(), the options.
' MessageBox.Show("NX File Import --- Third Parameter")
Dim options As NameValueMap
options = transientObj.CreateNameValueMap
options.Value("SaveComponentDuringLoad") = False
options.Value("SaveLocationIndex") = 0
options.Value("ComponentDestFolder") = ""
options.Value("SaveAssemSeperateFolder") = False
options.Value("AssemDestFolder") = ""
options.Value("ImportSolid") = True
options.Value("ImportSurface") = True
options.Value("ImportWire") = True
options.Value("ImportWorkPlane") = True
options.Value("ImportWorkAxe") = True
options.Value("ImportWorkPoint") = True
options.Value("ImportPoint") = True
options.Value("ImportAASP") = False
options.Value("ImportAASPIndex") = 0
options.Value("CreateSurfIndex") = 1
options.Value("GroupNameIndex") = 0
options.Value("GroupName") = ""
options.Value("ImportUnit") = 0
options.Value("CheckDuringLoad") = False
options.Value("AutoStitchAndPromote") = True
options.Value("AdvanceHealing") = False
options.Value("CHKSearchFolder") = True
'100 is the search folder maximum that you can specify.
'Assign separate search folder one by one.
Dim searchFolder(3) As String
searchFolder(0) = "C:\Temp\"
'searchFolder(1) = "C:\Folder2\"
options.Value("SearchFolder") = searchFolder
'Prepare the fourth parameter for Open(), the final document
MessageBox.Show("NX File Import --- Fourth Parameter")
Dim sourceObj As Object
'Open the NX file.
oTransAddIn.Open(file, context, options, sourceObj)
MessageBox.Show("NX File Import --- Successfully Imported")
Catch ex As Exception
MessageBox.Show("Exception StackTrace To String" + ex.StackTrace.ToString)
MessageBox.Show("Exception Current Exception " + ex.ToString)
MessageBox.Show("Exception Message " + ex.Message)
MessageBox.Show("Exception Source " + ex.Source)
MessageBox.Show("Exception StackTrace " + ex.StackTrace)
MessageBox.Show("Exception Targetsite " + ex.TargetSite.ToString)
MessageBox.Show("Exception Targetsite Name " + ex.TargetSite.Name)
End Try
End Sub
Thanks,
Wayne
Wayne Brill
Developer Technical Services
Autodesk Developer Network