Cant figure out TransientObjects.DataMedium.string

Cant figure out TransientObjects.DataMedium.string

Louie_Harvey
Participant Participant
419 Views
5 Replies
Message 1 of 6

Cant figure out TransientObjects.DataMedium.string

Louie_Harvey
Participant
Participant

Hi All, 

I am trying  to figure out a way to export a inventor file as a obj, but just the string of it I don't want it to actually save a file. I'm pretty sure it is related to DataMedium but i cant find examples of people using anything except or file name and when i run the bellow code in ilogic it throws out an error. i might be missing something obvious but if anyone could help it would be great

 

thanks

Sub main()
    ' Get the STEP translator Add-In.
    Dim oOBJ  As TranslatorAddIn
	For Each oAppAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
		If oAppAddin.DisplayName = "Translator: OBJ Export" Then
			oOBJ = oAppAddin
		End If
	Next
	
    If oOBJ Is Nothing Then

        Exit Sub
    End If


    Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    If oOBJ.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
        ' Set application protocol.
        ' 2 = AP 203 - Configuration Controlled Design
        ' 3 = AP 214 - Automotive Design
        oOptions.Value("ApplicationProtocolType") = 3

        oContext.Type = kFileBrowseIOMechanism
		Dim d As String = ""
        Dim oData As DataMedium
        oData = ThisApplication.TransientObjects.CreateDataMedium
		oData.MediumType = MediumTypeEnum.kStringMedium
		oData.String = d


        oOBJ.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData.String)
		
		MessageBox.Show(d)
    End If
End Sub

 

0 Likes
420 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @Louie_Harvey.  This is an odd scenario, because I have never seen anyone attempt to just get a String from a TranslatorAddIn.SaveCopyAs method, and I am not that familiar with Obj type files either, but I think I see something that might help.

Try changing that last line from:

MessageBox.Show(d)

...to this:

MessageBox.Show(oData.String)

I am just assuming that the method filled in a value for that property, but I am not sure.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Louie_Harvey
Participant
Participant
Thankyou for the response, I tried what you suggested but it seems to be erroring on
"oOBJ.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData.String)"
I have also tried
"oOBJ.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)"
but no luck

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

Hi @Louie_Harvey.  The second one looks like the correct way to do it.  Just use oData, not oData.String, as the last input into that SaveCopyAs method.  I don't know why I didn't think of this earlier, but the Options you are specifying will not work.  That one option looks like one you might use if exporting something to the STEP file type, but that will not apply to the TranslatorAddIn for exporting OBJ type files.  When I go to export either a part or an assembly out as an OBJ type file, when I click on the Options button, I see the following pop-up dialog.

WCrihfield_0-1678970259769.png

As you can see, that option you are specifying is not present on this dialog.  So, I used one of my code utilities to extract the names and current values of that TranslatorAddIn's options.

Below is the list I got in return:

Option Name = ExportUnits

Option Value = 0
Option Name = Resolution
Option Value = 4
Option Name = SurfaceDeviation
Option Value = 16
Option Name = NormalDeviation
Option Value = 1500
Option Name = MaxEdgeLength
Option Value = 100000
Option Name = AspectRatio
Option Value = 2150
Option Name = ExportFileStructure
Option Value = 0

As you can see, not all of the values make immediate sense, so you may have to play around with it a bit to get them set the way you want them.  Usually those settings will be stored from the last time you used them, but I don't know if that is always true.  So, I would suggest that you export something to OBJ manually first, to get the settings the way you want them, then you can capture their settings after that point for use in your code.  I will attach my code utility for TranslatorAddIn Options extraction as a text file, so you can use it later.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

Louie_Harvey
Participant
Participant

I have tried the code bellow but still no luck, I might be going about this the wrong way.

I am trying to import an inventor file into a wpf form with a 3d addin that allows files like obj's or System.Windows.Media.Media3D.Model3DGroup's to be imported and simply saving out the file to a temp folder take too much time hence me trying to get an obj as a string.

Sub main()
    ' Get the STEP translator Add-In.
    Dim oOBJ  As TranslatorAddIn
	For Each oAppAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
		If oAppAddin.DisplayName = "Translator: OBJ Export" Then
			oOBJ = oAppAddin
		End If
	Next
	
    If oOBJ Is Nothing Then

        Exit Sub
    End If


    Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    If oOBJ.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
        oOptions.Value("ExportUnits") = 0
		oOptions.Value("Resolution") = 4
		oOptions.Value("SurfaceDeviation") = 16
		oOptions.Value("NormalDeviation") = 1500
		oOptions.Value("MaxEdgeLength") = 100000
		oOptions.Value("AspectRatio") = 2150
		oOptions.Value("ExportFileStructure") = 0

        oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
		Dim d As String = ""
        Dim oData As DataMedium
        oData = ThisApplication.TransientObjects.CreateDataMedium
		oData.MediumType = MediumTypeEnum.kStringMedium
		oData.String = d

        oOBJ.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
		
		MessageBox.Show(d)
    End If
End Sub

 

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

I am not even sure it is possible to use DataMedium where its MediumType is set to String.  These translators are generally used to produce a file on disk that is a different type than the original file, but other outcomes may be possible, I'm not sure.  The TranslatorAddIn object itself has a few properties that will return an Array of String containing the file types that it will work with, in one way or another.  I don't know if looking into those properties may shed some light on your situation or not, since you are not planning on actually producing a new file on disk though.  You may have to ask someone at Autodesk directly about what you are trying to do, and see if it is possible.  Often times, when it comes to controlling Inventor by code, if you can not do it manually, you will usually not be able to do it by code either, but that is obviously not true for every situation.  If you do figure it out, one way or another, please post back here and let us know what you found out.  Good luck.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes