iLogic send email with selected parts and attach pdf

iLogic send email with selected parts and attach pdf

Neuzzo
Advocate Advocate
954 Views
4 Replies
Message 1 of 5

iLogic send email with selected parts and attach pdf

Neuzzo
Advocate
Advocate

Hi, i've this macro that get the selected file, collect it and open an email with this selected parts name in a body.

I wanna attach a pdf to this email but i don't find a solution.

All pdf is in 

\\server-ut01\DISEGNI\PDF\

and it's name is same as part name.

 

Example:

- Part name "SGE3000001.ipt"

- Pdf name  "SGE3000001..pdf"

in a folder \\server-ut01\DISEGNI\PDF\

 

 

Can anyone help me? Thanks

 

Sub Main()
'Make a ref to active doc
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

'selected components collection
Dim oSelected As ObjectCollection
oSelected = ThisApplication.TransientObjects.CreateObjectCollection

Dim oCount As Integer
oCount = oDoc.SelectSet.Count

'Check that at least 1 is selected
If oCount = 0 Then
	'MessageBox.Show("Please select a component.", "iLogic")
	Exit Sub 'bail out
End If

'add to Object Collection
Dim i As Long
For i = 1 To oCount
	If oDoc.SelectSet.Item(i).Type = _
		ObjectTypeEnum.kComponentOccurrenceObject Then
		oSelected.Add (oDoc.SelectSet.Item(i))
	End If
Next

  ' Start Outlook.
 ' If it is already running, you'll use the same instance...
   Dim oOApp
   oOApp = CreateObject("Outlook.Application")
   
' Log on. Doesn't hurt if you are already running and logged on...
   Dim olNs
   olNs = oOApp.GetNamespace("MAPI")
   olNs.Logon

For Each oItem In oSelected
	oMsg = oMsg & vbLf & Left(oItem.Name, Len(oItem.Name) - 2)
Next

'send email using outlook
Dim oOMail

oOMail = oOApp.CreateItem(olMailItem)

With oOMail
	
			
            'replace with your client's email address
            .To = ""
            .Subject = InputBox("Nome del cliente.", "iLogic", "") '"Please Review: "
          .Body = "Particolari da produrre:" & vbLf & oMsg
'            .Body = .Body & "Thanks, " & myName
            .Display
			For Each oMsg
            objOutlookAttach = .Attachments.Add("\\server-ut01\DISEGNI\PDF\" & oMsg 6 ".pdf"(True))
			Next
	End With
	

End Sub

The code for this operation is

 

For Each oMsg
            objOutlookAttach = .Attachments.Add("\\server-ut01\DISEGNI\PDF\" & oMsg 6 ".pdf"(True))
			Next

and obviously is incorrect. Can someone have idea to fix it?

 

Thanks

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Accepted solutions (1)
955 Views
4 Replies
Replies (4)
Message 2 of 5

bradeneuropeArthur
Mentor
Mentor
objOutlookAttach = .Attachments.Add("\\server-ut01\DISEGNI\PDF\" & oMsg & ".pdf"(True))

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 5

Neuzzo
Advocate
Advocate

@bradeneuropeArthursyntax error message in

For Each oMsg

Thisi is error now

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Message 4 of 5

Neuzzo
Advocate
Advocate

I've try with single file but error appear: "index over Matrix limit" in italian "indice oltre i limiti della matrice"

 

The code is

objOutlookAttach = .Attachments.Add("\\server-ut01\DISEGNI\PDF\" & "SGE30093430" & ".pdf"(True))
Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Message 5 of 5

Neuzzo
Advocate
Advocate
Accepted solution

Now it work! 🙂

 

Sub Main()
'Make a ref to active doc
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

'selected components collection
Dim oSelected As ObjectCollection
oSelected = ThisApplication.TransientObjects.CreateObjectCollection

Dim oCount As Integer
oCount = oDoc.SelectSet.Count

'Check that at least 1 is selected
If oCount = 0 Then
	'MessageBox.Show("Please select a component.", "iLogic")
	Exit Sub 'bail out
End If

'add to Object Collection
Dim i As Long
For i = 1 To oCount
	If oDoc.SelectSet.Item(i).Type = _
		ObjectTypeEnum.kComponentOccurrenceObject Then
		oSelected.Add (oDoc.SelectSet.Item(i))
	End If
Next

  ' Start Outlook.
 ' If it is already running, you'll use the same instance...
   Dim oOApp
   oOApp = CreateObject("Outlook.Application")
   
' Log on. Doesn't hurt if you are already running and logged on...
   Dim olNs
   olNs = oOApp.GetNamespace("MAPI")
   olNs.Logon

'send email using outlook
Dim oOMail

oOMail = oOApp.CreateItem(olMailItem)

With oOMail
	
			
            'replace with your client's email address
            .To = ""
            .Subject = InputBox("Nome del cliente.", "iLogic", "") '"Please Review: "
            .Display
			For Each oItem In oSelected
				oMsg = oMsg & vbLf & Left(oItem.Name, Len(oItem.Name) -2)
				oMsg1 = Left(oItem.Name, Len(oItem.Name) -2) 'Left(oItem.Name, Len(oItem.Name) -2)
				objOutlookAttach = .Attachments.Add("\\server-ut01\DISEGNI\PDF\" & oMsg1 & ".pdf")
			Next
			 .Body = "Particolari da produrre:" & vbLf & oMsg
	End With
	

End Sub

If someone need it, just select some parts in an assembly and run rule.

 

Obvs change folder in rule to your pdf folder (or what you want)

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes