DWF Export iLogic help

DWF Export iLogic help

mgeeW7SQV
Participant Participant
377 Views
4 Replies
Message 1 of 5

DWF Export iLogic help

mgeeW7SQV
Participant
Participant

Hi All,

I am trying to run this DWF Creator ilogic.

How do I add to get it to either export with settings as complete or all sheets and first 3d model?

 

oPath = ThisDoc.Path
oName = "DWF"
oRevNum = iProperties.Value("Project", "Revision Number")   
      
	 
'get target folder path from the file's path + DWF
oFolder = "C:\_Vault\WS\TO BE REVIEWED"

'Check for the DWF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
    End If
	
'query user
question = MessageBox.Show("Is this an Initial Release Revision", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

'set condition based on answer
If question = vbNo Then
 'Publish document
    ThisDoc.Document.SaveAs( oFolder & "\" & iProperties.Value("Project", "Part Number") & " - Rev " & iProperties.Value("Project", "Revision Number") & " " & iProperties.Value("Project", "Description") & (".dwf") , True) 
End If

If question = vbYes Then
 'Publish document
    ThisDoc.Document.SaveAs( oFolder & "\" & iProperties.Value("Project", "Part Number") & " " & iProperties.Value("Project", "Description") & (".dwf") , True) 
    
End If
	MessageBox.Show("DWF saved to " &  oFolder)

0 Likes
378 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @mgeeW7SQV.  This may seem a bit more complicated than you had planned on, but if you need to be able to specify options when you export one document type to another by code, then simply using SaveAs will not be adequate.  You will need to access and use the TranslatorAddIn object for the AddIn used for translating that type of document.  Since I have never needed to export to the DWF format, I do not have a finished working example to post for that exact process right now.  However the iLogic code example below will point out to you which TranslatorAddIn you need to be using, and what its available options are that you can specify.  Some folks prefer to find the translator they want by its DisplayName, while others choose to find it by its internal name, which is also called its ClassIdString.  This code shows you how to do it either way.

Sub Main
	Dim oDoc As Document = ThisDoc.Document
	
	'Get the target TranslatorAddIns to process
	Dim oDWF As TranslatorAddIn
	For Each oAppAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
		If oAppAddin.DisplayName = "Translator: DWF" Then
			oDWF = oAppAddin
		End If
	Next
	
	'or you can get it like the following:
	'Dim oDWF As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById( _
	'"{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
	
	'the following line shows you this value, in a way that makes the value selectable/copyable
	a = InputBox("", "DWF Translator ClassIdString", oDWF.ClassIdString)
	
	Dim oDWFOptions As String
	If Not IsNothing(oDWF) Then
		oDWFOptions = GetTranslatorOptions(oDoc, oDWF)
	End If
	Dim oEntries() As String = oDWFOptions.Split(vbCrLf)
	b = InputListBox("", oEntries, "", "DWF Translator Options")
End Sub

Function GetTranslatorOptions(oDocToExp As Document, oTransAddIn As TranslatorAddIn) As String
	Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kUnspecifiedIOMechanism
	Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	Dim oOptionsString As String = String.Empty
	If oTransAddIn.HasSaveCopyAsOptions(oDocToExp, oContext, oOptions) Then
		Dim oItem As Integer = 1
		For Each oPair In oOptions 'do not define Type of oPair ahead of time
			oOptionsString = oOptionsString & vbCrLf & "Option Name = " & oOptions.Name(oItem) & vbCrLf & "Option Value =   " & oOptions.Value(oOptions.Name(oItem)) & vbCrLf
			oItem = oItem + 1
		Next
	End If
	Return oOptionsString
End Function

When you search around within this forum, you will see how others set these options the way they want them using a NameValueMap, and supply that to the TranslatorAddIn.SaveCopyAs() method, which applies them to the export process, similarly to if you had done it manually using the user interface tools and its Options button.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

This following link is to an example of using the DWF TranslatorAddIn object to export an Inventor document out to a DWF file format.  But the example shown within is using VBA, not iLogic.  However, the two are very similar, so you could most likely figure it out from there.  One main difference is that iLogic does not use the "Set" keyword before setting a value to a variable, so you can remove those terms.

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=TranslatorAddIn_Sample 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Or, if you have Inventor 2019 or newer, then you will also have the iLogic Log available to you, which makes it easy to write information from within your iLogic rules out into the Log.  You can use that to write all of those Option names, and their current values out to that Log, which will then be fully select-able, and copy-able, like this.

Sub Main
	Dim oDoc As Document = ThisDoc.Document
	Dim oDWF As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById( _
	"{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
	LogTranslatorOptions(oDoc, oDWF)
	MsgBox("Check within your iLogic Log tab for the Translator Options.",,"")
End Sub

Sub LogTranslatorOptions(oDocToExp As Document, oTransAddIn As TranslatorAddIn)
	Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kUnspecifiedIOMechanism
	Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	If oTransAddIn.HasSaveCopyAsOptions(oDocToExp, oContext, oOptions) Then
		Dim oItem As Integer = 1
		For Each oPair In oOptions
			Logger.Trace("Option Name =   " & oOptions.Name(oItem) & "  /  Option Value =   " & oOptions.Value(oOptions.Name(oItem)))
			oItem = oItem + 1
		Next
	End If
End Sub

And if your iLogic Log tab is not showing right now, you can show it by going to your View tab, click on the User Interface tool, then put a check in the checkbox beside "iLogic Log".

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

mgeeW7SQV
Participant
Participant

Sorry been out of action, We are using Inventor 2022. I have limited understanding of ilogic code ect I will have a proper look at the codes provided, I will probably need for help

0 Likes