Get the name of an occurrence if it has any change in its properties

Get the name of an occurrence if it has any change in its properties

Anonymous
Not applicable
450 Views
4 Replies
Message 1 of 5

Get the name of an occurrence if it has any change in its properties

Anonymous
Not applicable

Hello Everyone,

 

I am using vb.net and Add-in template to create an add-in. Is there any way to get the name of an occurrence if it has any change in its properties.

 

I read some documents but can not find the best way to do that!

 

Many thanks!

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

WCrihfield
Mentor
Mentor

So...you're wanting to take advantage of the "iProperty Change" iLogic event trigger at the sub-component/sub-assembly level, from the main assembly?  Would the change to those properties be caused by something you're doing at the main assembly level?

Perhaps you could plant a simple local rule into those sub documents, that is set up to be triggered by that event, but suppressed (so they don't drive you crazy while working within those sub documents), but run some code which unsuppresses those rules before you need them early in your code, within the main assembly?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Anonymous
Not applicable

Hello Mr. WCrihfield

 

Thanks for the quick reply!

 

I just want to create an event in my add-in. (Visual Studio) Not the event trigger. Is there any way to do that?

 

Thanks!

0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor

You can catch inventor events in your addin in. I have written an addin that lissens for the OnDocumentChange event and checks all occurnce in a assembly (it will mark all occurnces in an assembly that are fully constaint). You can have a look at it on github. (its writen in C#) On line 41 is defined wich function should be fired on a document change. On line 48 the function it self is defined.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 5

Anonymous
Not applicable


Hello Mr. JelteDeJong

 

I did the same thing on vb.net, but it does not work anymore! Please take a look at my code!

 

Many thanks Sir!

 

Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Namespace TTF
<ProgIdAttribute("TTF.StandardAddInServer"),
GuidAttribute(g_simpleAddInClientID)>
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer

'*********************************************************************************
'* The two declarations below are related to adding buttons to Inventor's UI.
'* They can be deleted if this add-in doesn't have a UI and only runs in the
'* background handling events.
'*********************************************************************************

' Declaration of the object for the UserInterfaceEvents to be able to handle
' if the user resets the ribbon so the button can be added back in.
Private WithEvents m_uiEvents As UserInterfaceEvents
Private WithEvents m_onDocumentChangeEvents As ApplicationEvents


' Declaration of the button definition with events to handle the click event.
' For additional commands this declaration along with other sections of code
' that apply to the button can be duplicated from this example.

#Region "ApplicationAddInServer Members"

' This method is called by Inventor when it loads the AddIn. The AddInSiteObject provides access
' to the Inventor Application object. The FirstTime flag indicates if the AddIn is loaded for
' the first time. However, with the introduction of the ribbon this argument is always true.


Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
Try
' Initialize AddIn members.
g_inventorApplication = addInSiteObject.Application

' Connect to the user-interface events to handle a ribbon reset.
m_uiEvents = g_inventorApplication.UserInterfaceManager.UserInterfaceEvents
m_onDocumentChangeEvents = g_inventorApplication.ApplicationEvents

'*********************************************************************************
'* The remaining code in this Sub is all for adding the add-in into Inventor's UI.
'* It can be deleted if this add-in doesn't have a UI and only runs in the
'* background handling events.
'*********************************************************************************

' Create the button definition using the CreateButtonDefinition function to simplify this step.

' Add to the user interface, if it's the first time.
' If this add-in doesn't have a UI but runs in the background listening
' to events, you can delete this.


If firstTime Then
AddToUserInterface()
End If
Catch ex As Exception
MsgBox("Unexpected failure in the activation of the add-in ""TTF""" & vbCrLf & vbCrLf & ex.Message)
End Try

End Sub

 

' This method is called by Inventor when the AddIn is unloaded. The AddIn will be
' unloaded either manually by the user or when the Inventor session is terminated.


Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
' Release objects.

m_uiEvents = Nothing
m_onDocumentChangeEvents = Nothing
g_inventorApplication = Nothing

System.GC.Collect()
System.GC.WaitForPendingFinalizers()
End Sub

 

' This property is provided to allow the AddIn to expose an API of its own to other
' programs. Typically, this would be done by implementing the AddIn's API
' interface in a class and returning that class object through this property.
' Typically it's not used, like in this case, and returns Nothing.


Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
Get
Return Nothing
End Get
End Property

' Note:this method is now obsolete, you should use the
' ControlDefinition functionality for implementing commands.
Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
' Not used.
End Sub

 

Private Sub m_onDocumentChangeEvents_OnDocumentChange(ByVal DocumentObject As Document,
ByVal BeforeOrAfter As EventTimingEnum,
ByVal ReasonsForChange As CommandTypesEnum,
ByVal Context As NameValueMap,
ByRef HandlingCode As HandlingCodeEnum) Handles m_onDocumentChangeEvents.OnDocumentChange

If BeforeOrAfter = EventTimingEnum.kAfter Then
MsgBox("OnDocumentChange")
End If

End Sub

 

#End Region

#Region "User interface definition"
' Adds whatever is needed by this add-in to the user-interface. This is
' called when the add-in loaded and also if the user interface is reset.
Private Sub AddToUserInterface()
' This sample code illustrates creating a button on a new panel of the Tools tab of
' the Part ribbon. You'll need to change this to create the UI that your add-in needs.

End Sub

Private Sub m_uiEvents_OnResetRibbonInterface(Context As NameValueMap) Handles m_uiEvents.OnResetRibbonInterface
' The ribbon was reset, so add back the add-ins user-interface.
AddToUserInterface()
End Sub

#End Region

End Class
End Namespace


Public Module Globals
' Inventor application object.
Public g_inventorApplication As Inventor.Application

' The unique ID for this add-in. If this add-in is copied to create a new add-in
' you need to update this ID along with the ID in the .manifest file, the .addin file
' and create a new ID for the typelib GUID in AssemblyInfo.vb
Public Const g_simpleAddInClientID As String = "45065451-f806-4680-8d84-4d2166b2b77a"
Public Const g_addInClientID As String = "{" & g_simpleAddInClientID & "}"
End Module

0 Likes