Hi @HaiderAlghifary. My guess is that the solution that @ryan.rittenhouse posted may work just fine for you, but I have not tried it myself, because I rarely use positional representations, and pretty much never use OBJ files. However, below is another possible code for this task. The Sub main area is laid out mostly the same, but this uses the TranslatorAddIn object specifically for exporting OBJ files, and gives you the opportunity to specify those 'Options' when exporting those files. This is very similar to the old code I posted at the link above, but with the mistake fixed, and more documentation included for each of the individual options, to make it easier to specify what you want. It also includes a small block of code that will check if that file (it is about to export to) already exists. And if it does, it will let you know, and ask you if you want to overwrite it or not.
Sub Main
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
Dim oRepsMgr As RepresentationsManager = oADoc.ComponentDefinition.RepresentationsManager
Dim oPosReps As PositionalRepresentations = oRepsMgr.PositionalRepresentations
Dim oAPosRep As PositionalRepresentation = oRepsMgr.ActivePositionalRepresentation
Dim sPathAndName As String = ThisDoc.PathAndFileName(False)
For Each oPosRep As PositionalRepresentation In oPosReps
oPosRep.Activate
Dim sOBJ_File As String = sPathAndName & oPosRep.Name & ".obj"
ExportToOBJ(oDoc, sOBJ_File)
Next 'oPosRep
End Sub
Sub ExportToOBJ(oDoc As Inventor.Document, sNewFullFileName As String)
Dim sOBJ_Exporter_TranslatorAddIn_ClientID As String = "{F539FB09-FC01-4260-A429-1818B14D6BAC}"
Dim oOBJ As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById(sOBJ_Exporter_TranslatorAddIn_ClientID)
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oDataMedium As DataMedium = oTO.CreateDataMedium
'<<< check if that exported file already exists, if so, notify user & ask if it should be overwritten >>>
If System.IO.File.Exists(sNewFullFileName) = True Then
Dim oAns As MsgBoxResult = MsgBox("The following file already exists." & vbCrLf & _
sNewFullFileName & vbCrLf & _
"Do you want to overwrite it?", vbYesNo + vbQuestion + vbDefaultButton2, "File Already Exists")
If oAns = MsgBoxResult.No Then Exit Sub
End If
'set output file's full path, file name, and file extension here
oDataMedium.FileName = sNewFullFileName
If oOBJ.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
'Inch = 2 ; Foot = 3 ; Centimeter = 4 ; Millimeter = 5 ; Meter = 6 ; Micron = 7
oOptions.Value("ExportUnits") = 0 '(I assume 0 = 'Source Units')
'One File = 0 ; One File Per Part Instance = 1
oOptions.Value("ExportFileStructure") = 0
'High = 0 ; Medium = 1 ; Low = 2 ; Custom = 3 ; BREP = 4
oOptions.Value("Resolution") = 0
'<<< the following 4 options will be ignored if the 'Resolution' is NOT set to 3 (Custom) >>>
'Range 0 to 100, with precision to 0.0001 (percentage)
oOptions.Value("SurfaceDeviation") = 0
'Range 0 to 41 (any value outside of this range will be forced to 14)
oOptions.Value("NormalDeviation") = 0
'Range 0 to 100 (percentage)
oOptions.Value("MaxEdgeLength") = 0
'Range 0 to 21.5
oOptions.Value("AspectRatio") = 0
Try
oOBJ.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
Logger.Error("Exported following document:" & vbCrLf & _
oDoc.FullDocumentName & vbCrLf & _
"to the following OBJ file:" & vbCrLf & _
sNewFullFileName)
Catch
Logger.Error("Error exporting following document:" & vbCrLf & _
oDoc.FullDocumentName & vbCrLf & _
"to the following OBJ file:" & vbCrLf & _
sNewFullFileName)
End Try
End If
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)