combine ilogic rules

combine ilogic rules

Bram_Jessen
Contributor Contributor
313 Views
2 Replies
Message 1 of 3

combine ilogic rules

Bram_Jessen
Contributor
Contributor

Hello all,

 

I've tried to find a solution for my challenge on this forum but haven't seem to crack it.

I even asked chatGTP for help but he is not of much use when it comes to correct ilogic code.

 

The goal is to launch this code from a part (or assembly), open the drawing (close the part/assy), then make a PDF from the drawing, then close the drawing.

I've tried it as external ilogic rule, and combining the code, but it gets me stuck.

Currently it says i have an error on line 81.

 

Can someone help me on my way?

Thanks in advance

Sub Main()
    ' Call Main1 subroutine
    Call Main1
    
    ' Call Main2 subroutine
    Call Main2
    
    ' Call Main3 subroutine
    Call Main3
End Sub

' Define Main1 subroutine
Sub Main1()
Dim teknummer As String
Dim oDocumentMain1 As Document
oDocumentMain1 = ThisApplication.ActiveDocument

If iProperties.Value("Project", "Stock Number") = ""
	teknummer = iProperties.Value("Project", "Part Number")
Else
	teknummer = iProperties.Value("Project", "Stock Number")
End If

Try
	ThisDoc.Launch(ThisDoc.Path & "\" & teknummer & ".idw")
Catch
	If teknummer = "" Then
	MessageBox.Show("Beetje lastig om een tekening zonder nummer te openen", "ERROR")
	Else
	MessageBox.Show(ThisDoc.Path & "\" & teknummer & ".idw niet gevonden")
	End if
End Try
ThisDoc.Document.Close(True) 'True means don't save it when closing
End Sub

' Define Main2 subroutine
Sub Main2()
'Define the open document
Dim openDocMain2 As Document
openDocMain2 = ThisDoc.Document

'Look at the model file referenced in the open document
Dim docFileMain2 As Document
docFileMain2 = ThisDoc.ModelDocument

'format model file name                   
Dim FNamePosMain2 As Long
FNamePosMain2 = InStrRev(docFileMain2.FullFileName, "\", -1)                        
Dim docFNameMain2 As String 
docFNameMain2 = Right(docFileMain2.FullFileName, Len(docFileMain2.FullFileName) -FNamePosMain2) 

'define the property set
customPropertySet = docFileMain2.PropertySets.Item("Inventor User Defined Properties")

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("project", "revision number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocumentMain2 = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMediuma = ThisApplication.TransientObjects.CreateDataMedium
oDataMediumb = ThisApplication.TransientObjects.CreateDataMedium 


If oPDFAddIn.HasSaveCopyAsOptions(oDocumentMain2, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 600
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 = "Z:\Cad\Documenten\Werkmap Kevin\Inventor Project\Workspace\Export\"

Dim Bestandsnaam As String
'If Left(Right(iProperties.Value(docFNameMain2, "Project", "Part Number"), 3), 1) = "D" Or Left(Right(iProperties.Value(docFNameMain2, "Project", "Part Number"), 3), 1) = "S"
'Bestandsnaam = iProperties.Value(docFNameMain2,"Project", "Part Number")
'Else
Bestandsnaam = iProperties.Value(docFNameMain2, "Project", "Stock Number")
'End If
Dim revisienummer As String
revisienummer = iProperties.Value(docFNameMain2, "Project", "Revision Number") 

Dim jaar As String
Dim maand As String
Dim dag As String
Dim uur As String
Dim minuut As String
Dim datum As String

jaar = Date.Now.Year.ToString

If Len(Date.Now.Month.ToString) = 1
maand = "0" & Date.Now.Month.ToString
Else
maand = Date.Now.Month.ToString
End If

If Len(Date.Now.Day.ToString) = 1
dag = "0" & Date.Now.Day.ToString
Else
dag = Date.Now.Day.ToString
End If

If Len(Date.Now.Hour.ToString) = 1
uur = "0" & Date.Now.Hour.ToString
Else
uur = Date.Now.Hour.ToString
End If

If Len(Date.Now.Minute.ToString) = 1
minuut = "0" & Date.Now.Minute.ToString
Else
minuut = Date.Now.Minute.ToString
End If

datum = jaar &" "& maand & dag &" "& uur & minuut

 'Set the PDF target file name
oDataMediumb.FileName = oFolder & "\RevisieBeheer\" & Bestandsnaam & "-" & revisienummer & " (" & datum & ").pdf" 
oDataMediuma.FileName = oFolder & "\PDF\" &Bestandsnaam & ".pdf" 

'Set timestamp
iProperties.Value("Custom", "TIMESTAMP") = revisienummer &" - "& datum

Try
'Publish document
	Select Case Right(revisienummer, 1)
	Case ""
		oPDFAddIn.SaveCopyAs(oDocumentMain2, oContext, oOptions, oDataMediumb)
	Case "-"
		oPDFAddIn.SaveCopyAs(oDocumentMain2, oContext, oOptions, oDataMediumb)
	Case "+"
		oPDFAddIn.SaveCopyAs(oDocumentMain2, oContext, oOptions, oDataMediumb)
	Case Else
	End Select
	oPDFAddIn.SaveCopyAs(oDocumentMain2, oContext, oOptions, oDataMediumb)
	oPDFAddIn.SaveCopyAs(oDocumentMain2, oContext, oOptions, oDataMediuma)
'MessageBox.Show("PDF file vrijgegeven:" & vbLf & oFolder & "PDF\" & Bestandsnaam & ".pdf")
	Catch
	MessageBox.Show("Kan pdf niet opslaan, mogelijk is bestand in gebruik"& vbLf &"Sluit de pdf af en/of selecteer een ander bestand in de windows verkenner")
	End Try
End Sub

' Define Main3 subroutine
Sub Main3()
ThisDoc.Document.Close(True) 'True means don't save it when closing
End Sub
0 Likes
Accepted solutions (1)
314 Views
2 Replies
Replies (2)
Message 2 of 3

jwingateRJECD
Enthusiast
Enthusiast
Accepted solution

You were on the right path with external rules, but you need to separate the actions into different rules, and call them from within a main rule, at least that is what I have gotten to work for me. Something like this:

 

ThisDoc.Launch(ThisDoc.Path & "\" & iProperties.Value("Project", "Part Number") & ".idw")

oDrawDoc = ThisApplication.ActiveDocument

iLogicVb.Automation.RunExternalRule(oDrawDoc, "*Put the file location of your external pdf rule here*")

Here is the rule that I use for exporting PDF's:

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension

oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 1200
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets

'get PDF target folder path
oFolder = oPath 

ThisApplication.ActiveView.Update()

'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

oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf"
oPDFAddIn.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oDataMedium)'For PDF's

 Hope this helps.

0 Likes
Message 3 of 3

Bram_Jessen
Contributor
Contributor

Thank you for steering me in the right direction, your addition did the trick.

0 Likes