Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

How can i create event trigger with external rule for all parts ?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
534 Views, 3 Replies

How can i create event trigger with external rule for all parts ?

Hi,

 

I have a code below, now while this code working i also want to set a event trigger(before save) for all parts and assemblies. I checked the forum but couldn't find exact solution.

 

RRFA=MessageBox.Show("Bu komutu çalıştırmadan önce tüm CHECKOUT'ları almış olmanız gerekmektedir. Eğer checkout almadıysanız lütfen işlemi iptal ederek checkout alın. Referans olarak çekilmiş .stp parçalar montajda var ise program hata verecektir. Devam edilsin mi?", "ÇOK ÖNEMLİ UYARI",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)


If RRFA = vbYes Then
	
	RRFA2= MessageBox.Show("Tüm montaj için parametreleri eklemeye başlamak üzeresiniz. İşlem süresince Inventor'e müdahale etmeyiniz. Checkout'u sizde olmayan parçalar açıldıktan sonra kapanmayacaktır. Montajın büyüklüğüne göre işlem süresi çok uzun olabilir. Devam etmek istediğinize emin misiniz ?", "Köprüden Önceki Son Çıkış",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)

If RRFA2 = vbYes Then
		
Dim oDoc As Document
oDoc = ThisDoc.Document

'Dim oDoc As AssemblyDocument
'oDoc = ThisApplication.ActiveDocument

If Not ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then 
	Return
End If
'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In oDoc.AllReferencedDocuments
	
ThisApplication.Documents.Open(docFile.FullFileName, True)

iLogicVb.RunExternalRule("RunRuleForAll2")
'iLogicVb.RunExternalRule("StokTanım") THIS IS THE RULE WHICH I WOULD LIKE TO ADD TO EVENT TRIGGER

docFile.Save
docFile.Close
	
Next

	MessageBox.Show("İşlem tamamlandı.", "Mutlu Son")


	Else
	MessageBox.Show("İşlem iptal edildi.", "ÇOK ÖNEMLİ UYARI")
	End If
Else
	MessageBox.Show("İşlem iptal edildi.", "ÇOK ÖNEMLİ UYARI")

End If
iLogicVb.UpdateWhenDone = True

 

3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

@Sergio.D.Suárez  May i ask for your help ?

Message 3 of 4
Sergio.D.Suárez
in reply to: Anonymous

Merhaba, aşağıdaki kuralı yürütmeyi deneyin.
Olay tetikleyicilerine harici bir kural eklemek için, adı "file: //" ve ardından kuralın harici kurallar klasörüne (kırmızı kuralların altına) konumunu ekleyerek iyi yerleştirmelisiniz. kural alt klasörlerde bulunacaksa kuralın adı)

 

Sub main

RRFA = MessageBox.Show("Bu komutu çalıştırmadan önce tüm CHECKOUT'ları almış olmanız gerekmektedir. Eğer checkout almadıysanız lütfen işlemi iptal ederek checkout alın. Referans olarak çekilmiş .stp parçalar montajda var ise program hata verecektir. Devam edilsin mi?", "ÇOK ÖNEMLİ UYARI", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)


If RRFA = vbYes Then
	
	RRFA2= MessageBox.Show("Tüm montaj için parametreleri eklemeye başlamak üzeresiniz. İşlem süresince Inventor'e müdahale etmeyiniz. Checkout'u sizde olmayan parçalar açıldıktan sonra kapanmayacaktır. Montajın büyüklüğüne göre işlem süresi çok uzun olabilir. Devam etmek istediğinize emin misiniz ?", "Köprüden Önceki Son Çıkış",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)

If RRFA2 = vbYes Then
		
Dim oDoc As Document
oDoc = ThisDoc.Document

If Not ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then 
	Return
End If
'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In oDoc.AllReferencedDocuments
	
ThisApplication.Documents.Open(docFile.FullFileName, True)

iLogicVb.RunExternalRule("RunRuleForAll2")
'iLogicVb.RunExternalRule("StokTanım") THIS IS THE RULE WHICH I WOULD LIKE TO ADD TO EVENT TRIGGER


Events(docFile, "file://RunRuleForAll2")
'Events(docFile, "file://Olders\Routines\RunRuleForAll2")

docFile.Save
docFile.Close
	
Next

	MessageBox.Show("İşlem tamamlandı.", "Mutlu Son")


	Else
	MessageBox.Show("İşlem iptal edildi.", "ÇOK ÖNEMLİ UYARI")
	End If
Else
	MessageBox.Show("İşlem iptal edildi.", "ÇOK ÖNEMLİ UYARI")

End If
iLogicVb.UpdateWhenDone = True


End Sub


Sub Events(oDoc As Document,RuleName As String)
On Error Resume Next
Dim EventPropSet As Inventor.PropertySet
EventPropSet = oDoc.PropertySets.Item("iLogicEventsRules")

If EventPropSet Is Nothing Then
	EventPropSet = oDoc.PropertySets.Item("_iLogicEventsRules")
End If
If EventPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then
	Call EventPropSet.Delete
	EventPropSet = oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
End If
If EventPropSet Is Nothing Then
	EventPropSet = oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
End If
If EventPropSet Is Nothing Then
	MsgBox ("Unable to create the Event Triggers property for this file!", , "Event Triggers Not Set")
	Err.Raise(1)
End If

EventPropSet.Add(RuleName, "BeforeDocSave", 700)

End Sub

 Bir test yaptım ve iyi çalıştı, umarım sizin için çalışır. selamlar


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 4 of 4
Anonymous
in reply to: Sergio.D.Suárez

Thank you so much for your reply.

 

There is two issue: 

 

I was hoping that after event injection event trigger will work before save and close the document. Do you have any idea why event trigger is not working while code working ?

 

Second one is if there is an another rule on before saving, code injection is not working as well. before save document should be empty.

 

Sub main

RRFA = MessageBox.Show("Bu komutu çalıştırmadan önce tüm CHECKOUT'ları almış olmanız gerekmektedir. Eğer checkout almadıysanız lütfen işlemi iptal ederek checkout alın. Referans olarak çekilmiş .stp parçalar montajda var ise program hata verecektir. Devam edilsin mi?", "ÇOK ÖNEMLİ UYARI", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)


If RRFA = vbYes Then
	
	RRFA2= MessageBox.Show("Tüm montaj için parametreleri eklemeye başlamak üzeresiniz. İşlem süresince Inventor'e müdahale etmeyiniz. Checkout'u sizde olmayan parçalar açıldıktan sonra kapanmayacaktır. Montajın büyüklüğüne göre işlem süresi çok uzun olabilir. Devam etmek istediğinize emin misiniz ?", "Köprüden Önceki Son Çıkış",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)

If RRFA2 = vbYes Then
		
Dim oDoc As Document
oDoc = ThisDoc.Document

If Not ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then 
	Return
End If
'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In oDoc.AllReferencedDocuments
	
ThisApplication.Documents.Open(docFile.FullFileName, True)

iLogicVb.RunExternalRule("RunRuleForAll2")
'iLogicVb.RunExternalRule("StokTanım") 'THIS Is THE RULE WHICH I WOULD Like To ADD To Event TRIGGER


Events(docFile, "file://StokTanım")
'Events(docFile, "file://Olders\Routines\RunRuleForAll2")

docFile.Save
docFile.Close
	
Next

	MessageBox.Show("İşlem tamamlandı.", "Mutlu Son")


	Else
	MessageBox.Show("İşlem iptal edildi.", "ÇOK ÖNEMLİ UYARI")
	End If
Else
	MessageBox.Show("İşlem iptal edildi.", "ÇOK ÖNEMLİ UYARI")

End If
iLogicVb.UpdateWhenDone = True


End Sub


Sub Events(oDoc As Document, RuleName As String)
RuleName="StokTanım"
On Error Resume Next
Dim EventPropSet As Inventor.PropertySet
EventPropSet = oDoc.PropertySets.Item("iLogicEventsRules")

If EventPropSet Is Nothing Then
	EventPropSet = oDoc.PropertySets.Item("_iLogicEventsRules")
End If
If EventPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then
	Call EventPropSet.Delete
	EventPropSet = oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
End If
If EventPropSet Is Nothing Then
	EventPropSet = oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
End If
If EventPropSet Is Nothing Then
	MsgBox ("Unable to create the Event Triggers property for this file!", , "Event Triggers Not Set")
	Err.Raise(1)
End If

EventPropSet.Add(RuleName, "BeforeDocSave", 700)

End Sub

 

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

Post to forums  

Autodesk Design & Make Report