Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help updating iLogic - From 2016 to 2021

9 REPLIES 9
Reply
Message 1 of 10
drafting1
699 Views, 9 Replies

Help updating iLogic - From 2016 to 2021

Hi we have just had our software updated to 2021 from 2016.

 

I had the below ilogic previously working.

 

It was to create to ask if I wanted to create a PDF and DXF.

in a folder call PDFDXF under the same location with file name and rev.

 

If any one could help that would be great.

 

Here are the errors

drafting1_0-1594097260811.png

drafting1_1-1594097288128.png

 

 

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'query user
question = MessageBox.Show("Create PDF?", "Create PDF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

'set condition based on answer
            If question = vbYes Then
			
'------start of iLogic-------
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If

'get PDF target folder path
oFolder = oPath & "\" & "PDFDXF"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" rev" & oRevNum & ".pdf"
MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName, "PDF Saved", MessageBoxButtons.OK)
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'------end of iLogic-------

Else If question = vbNo Then
End If

'query user
question = MessageBox.Show("Create DXF?", "Create DXF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

'set condition based on answer
            If question = vbYes Then

'get DXF target folder path
oFolder = oPath & "\" & "PDFDXF"

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

 'Set the DXF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" rev" & oRevNum & ".dxf"
MessageBox.Show("DXF SAVED TO: " & oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK)
'Publish document
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'------end of iLogic-------

Else If question = vbNo Then
End If

 

9 REPLIES 9
Message 2 of 10
WCrihfield
in reply to: drafting1

See if this works for you.

The main thing I changed was instead of specifying the Addin by its ClientId String (which is horrible), I find it with a loop, by checking which of them has the document type abbreviation in its DisplayName, which they do.

I also simply declared the Types of most of the variables, because that sometimes causes folks problems too, depending on how everything is set up.

I also moved the oFolder specification, and its check for existing job, up above both of the translator blocks, since it was the same in both situations.

 

 

Dim oPath As String = ThisDoc.Path
Dim oFileName As String = ThisDoc.FileName(False) 'without extension
Dim oRevNum As String = iProperties.Value("Project", "Revision Number")

Dim oPDFAddIn As TranslatorAddIn
Dim oDXFAddIn As TranslatorAddIn
For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
	If oAddin.AddInType = ApplicationAddInTypeEnum.kTranslationApplicationAddIn Then
		If oAddin.DisplayName.Contains("PDF") Then
			oPDFAddIn = oAddin
		ElseIf oAddin.DisplayName.Contains("DXF") Then
			oDXFAddIn = oAddin
		End If
	End If
Next
		
Dim oDocument As Document = ThisApplication.ActiveDocument
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

Dim oFolder As String = oPath & "\" & "PDFDXF"
If Not System.IO.Directory.Exists(oFolder) Then
	System.IO.Directory.CreateDirectory(oFolder)
End If

'PDF portion
Dim oQ1 As DialogResult = MessageBox.Show("Create PDF?", "Create PDF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If oQ1 = DialogResult.Yes Then
	If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
		oOptions.Value("Remove_Line_Weights") = 1
		oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
		'oOptions.Value("Custom_Begin_Sheet") = 2
		'oOptions.Value("Custom_End_Sheet") = 4
	End If
	oDataMedium.FileName = oFolder & "\" & oFileName & " rev" & oRevNum & ".pdf"
	MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName, "PDF Saved", MessageBoxButtons.OK)
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If

'DXF portion
Dim oQ2 As DialogResult = MessageBox.Show("Create DXF?", "Create DXF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If oQ2 = DialogResult.Yes Then
	oDataMedium.FileName = oFolder & "\" & oFileName & " rev" & oRevNum & ".dxf"
	MessageBox.Show("DXF SAVED TO: " & oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK)
	oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If

 

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE" 👍.

Also, when you have time, please review & vote for these 'Ideas' I'd like to get implemented.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
  • Create DocumentSubTypeEnum Click Here
  • Add kRevisionTag or kDrawingRevisionTag to ObjectTypeEnum Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 10
drafting1
in reply to: WCrihfield

Hi it seems to have same type of error.

 

drafting1_0-1594169129856.png

drafting1_1-1594169153764.png

 

Message 4 of 10
WCrihfield
in reply to: drafting1

I think I see where the problem may have been.

Within the HasSaveCopyAsOptions, you specified oDataMedium as the first entry instead of oDocument, and I didn't catch and change that before posting the code that last time.

I fixed that in this updated code, and changed a couple more things too, to help with errors.

I added a check for in there, before each translation block of code, that checks if the Translator Addin was found, before trying to use it.  If not found, it lets you know, then either skips to the next translator block or ends the rule.

Try this now:

 

Dim oPath As String = ThisDoc.Path
Dim oFileName As String = ThisDoc.FileName(False) 'without extension
Dim oRevNum As String = iProperties.Value("Project", "Revision Number")

Dim oPDFAddIn As TranslatorAddIn
Dim oDXFAddIn As TranslatorAddIn
For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
	If oAddin.AddInType = ApplicationAddInTypeEnum.kTranslationApplicationAddIn Then
		If oAddin.DisplayName = "Translator: PDF" Then
			oPDFAddIn = oAddin
		ElseIf oAddin.DisplayName = "Translator: DXF" Then
			oDXFAddIn = oAddin
		End If
	End If
Next

Dim oDocument As Document = ThisApplication.ActiveDocument
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

Dim oFolder As String = oPath & "\" & "PDFDXF"
If Not System.IO.Directory.Exists(oFolder) Then
	System.IO.Directory.CreateDirectory(oFolder)
End If

'PDF portion
If oPDFAddIn Is Nothing Then
	MsgBox("PDF Translator Addin could not be found.", vbOKOnly, " ")
	GoTo DXF
End If

Dim oQ1 As MsgBoxResult = MsgBox("Create PDF?", vbYesNo + vbQuestion, "Create PDF?")
If oQ1 = vbYes Then
	If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
		oOptions.Value("Remove_Line_Weights") = 1
		oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
		'oOptions.Value("Custom_Begin_Sheet") = 2
		'oOptions.Value("Custom_End_Sheet") = 4
	End If
	oDataMedium.FileName = oFolder & "\" & oFileName & " rev" & oRevNum & ".pdf"
	MsgBox("PDF SAVED TO: " & oDataMedium.FileName, vbOKOnly, "PDF Saved")
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If

'DXF portion
DXF :
If oDXFAddIn Is Nothing Then
	MsgBox("DXF Translator Addin could not be found.", vbOKOnly, " ")
	Return
End If

Dim oQ2 As MsgBoxResult = MsgBox("Create DXF?", vbYesNo + vbQuestion,"Create DXF?")
If oQ2 = vbYes Then
	If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
		oOptions.Value("Export_Acad_IniFile") = "Default DXF Configuration"
		'Or something similar to this:
		'oOptions.Value("Export_Acad_IniFile") = "C:\Users\YourProfileName\AppData\Local\Temp\exportdxf250ENU.ini"
	End If
	oDataMedium.FileName = oFolder & "\" & oFileName & " rev" & oRevNum & ".dxf"
	MsgBox("DXF SAVED TO: " & oDataMedium.FileName, vbOKOnly, "DXF Saved")
	oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE" 👍.

Also, when you have time, please review & vote for these 'Ideas' I'd like to get implemented.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
  • Create DocumentSubTypeEnum Click Here
  • Add kRevisionTag or kDrawingRevisionTag to ObjectTypeEnum Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 10
drafting1
in reply to: WCrihfield

That fixed the PDF part of it, but seems the DXF is still broken.

 

I get the following:

 

drafting1_0-1594248193916.png

 

drafting1_2-1594248218633.png

Thanks

Message 6 of 10
WCrihfield
in reply to: drafting1

Hmm... This is odd.  I don't usually export multiple formats from the same iLogic rule, but my other rules for exporting haven't had any problems, and are somewhat similarly laid out, so I'm not entirely sure why this one isn't working for you.

 

The error message suggests that it is having trouble with the SaveCopyAs built-in sub, but it does have several variables, so it's not that straight forward diagnose.

In my investigation, I noticed that sometimes it would recognize one addin and not the other, and some times it would recognize both, with no changes to the code, so I'm thinking it isn't liking the direct value asignment of oAddin, for both.  So I changed the way I was setting the values of both addin variables, and the new method works like a charm.  The reason I avoid using the long string values of ClientId and ClassIdString is because these long complicated looking strings have been known to change when changing Inventor versions.  Not with every Inventor version, but between some versions.  So, it is just more stable/reliable to go the loop route.

 

I also added a few more checks into the code to help catch errors.

And also some other minor modifications, that may or may not fix the error, but might help us figure out exactly where the error is happening, and why.  Some of the newer stuff you may be able to either comment out, or delete completely, once we get it working for you.

Here's the latest code that is working for me:

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works with an active Drawing Document.  Exiting.", vbOKOnly + vbExclamation, " ")
	Return
End If

Dim oAddins As ApplicationAddIns =ThisApplication.ApplicationAddIns
Dim oAddin As ApplicationAddIn
'Dim oPDFAddIn As TranslatorAddIn = oAddins.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'Dim oDXFAddIn As TranslatorAddIn = oAddins.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

For Each oAddin In oAddins
	If oAddin.AddInType = ApplicationAddInTypeEnum.kTranslationApplicationAddIn Then
		If oAddin.DisplayName.Contains("PDF") Then
			oPDFAddIn = oAddins.ItemById(oAddin.ClassIdString)
		End If
		If oAddin.DisplayName.Contains("DXF") Then
			oDXFAddIn = oAddins.ItemById(oAddin.ClassIdString)
		End If
	End If
Next

Dim oDDoc As DrawingDocument = ThisDrawing.Document
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

Dim oSourcePath As String = IO.Path.GetDirectoryName(oDDoc.FullFileName)
Dim oSourceFileName As String = IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
Dim oRevNum As String = iProperties.Value("Project", "Revision Number")

Dim oTargetFolder As String = oSourcePath & "\" & "PDFDXF"
If Not System.IO.Directory.Exists(oTargetFolder) Then
	System.IO.Directory.CreateDirectory(oTargetFolder)
End If

'PDF portion
If oPDFAddIn Is Nothing Then
	MsgBox("PDF Translator Addin could not be found.", vbOKOnly, " ")
	GoTo DXF
End If

oPDFAddIn.Activate

If oDXFAddIn.SupportsSaveCopyAs = False Then
	MsgBox("This PDF Addin does not support the 'SaveCopyAs' Sub. Exiting.", vbOKOnly + vbExclamation, " ")
	Return
End If

Dim oQ1 As MsgBoxResult = MsgBox("Create PDF?", vbYesNo + vbQuestion, "Create PDF?")
If oQ1 = vbYes Then
	If oPDFAddIn.HasSaveCopyAsOptions(oDDoc, oContext, oOptions) Then
		oOptions.Value("Remove_Line_Weights") = 1
		oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
		'oOptions.Value("Custom_Begin_Sheet") = 2
		'oOptions.Value("Custom_End_Sheet") = 4
	End If
	oDataMedium.FileName = oTargetFolder & "\" & oSourceFileName & " rev" & oRevNum & ".pdf"
	Try
		oPDFAddIn.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)
		MsgBox("PDF SAVED TO: " & oDataMedium.FileName, vbOKOnly, "PDF Saved")
	Catch oEx As Exception
		MsgBox("The PDF 'SaveCopyAs' sub failed." & vbCr & _
		"Error message is as follows:" & vbCr & _
		oEx.Message, vbOKOnly + vbExclamation, "PDF - SAVE-COPY-AS FAILURE")
	End Try
End If

'DXF portion
DXF :
If oDXFAddIn Is Nothing Then
	MsgBox("DXF Translator Addin could not be found.", vbOKOnly, " ")
	Return
End If

oDXFAddIn.Activate

If oDXFAddIn.SupportsSaveCopyAs = False Then
	MsgBox("This DXF Addin does not support the 'SaveCopyAs' Sub. Exiting.", vbOKOnly + vbExclamation, " ")
	Return
End If

Dim oQ2 As MsgBoxResult = MsgBox("Create DXF?", vbYesNo + vbQuestion,"Create DXF?")
If oQ2 = vbYes Then
	If oDXFAddIn.HasSaveCopyAsOptions(oDDoc, oContext, oOptions) Then
		oOptions.Value("Export_Acad_IniFile") = "Default DXF Configuration"
		'Or something similar to this:
		'oOptions.Value(Export_Acad_IniFile") = "C:\Users\YourProfileName\AppData\Local\Temp\exportdxf250ENU.ini"
	Else
		MsgBox("This DXF Addin does not have 'SaveCopyAs' options.", vbOKOnly," ")
	End If
	oDataMedium.FileName = oTargetFolder & "\" & oSourceFileName & " rev" & oRevNum & ".dxf"
	Try
		oDXFAddIn.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)
		MsgBox("DXF SAVED TO: " & oDataMedium.FileName, vbOKOnly, "DXF Saved")
	Catch oEx As Exception
		MsgBox("The DXF 'SaveCopyAs' sub failed." & vbCr & _
		"Error message is as follows:" & vbCr & _
		oEx.Message, vbOKOnly + vbExclamation, "DXF - SAVE-COPY-AS FAILURE")
	End Try
End If

 

I hope this works for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 10
drafting1
in reply to: WCrihfield

Thanks for having another go.

But I get the following.

 

drafting1_0-1594340478110.png

 

Message 8 of 10
WCrihfield
in reply to: drafting1

I had it working for me, before posting it that last time, but that's often not any guarantee that it will work on another persons situation.

Maybe try separating the two different export processes into two different external iLogic rules, then use another rule which asks the question and runs the necessary other external rules.  Or separating the two export processes into different subs.

I'm wandering if the values of the oContext and/or oOptions variables are being modified by passing through the first PDF exporter process first, then not working for the DXF exporter.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 10
drafting1
in reply to: WCrihfield

Thanks,

 

Originally i found the the ilogic by using someone else's code,

 

Its been so long since I looked at it and I have forgotten how it all works.

 

Message 10 of 10
drafting1
in reply to: drafting1

Is anyone possibly able to help with this.

 

Thanks

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report