iLogic - Check active project is true

iLogic - Check active project is true

neil.cooke
Participant Participant
669 Views
5 Replies
Message 1 of 6

iLogic - Check active project is true

neil.cooke
Participant
Participant

I have found similar requests with solution but I am quite a new user to iLogic and perhaps missing the obvious (Sorry).

 

I am trying to check that a specific project file is active, if it is not true then to pop up a message box stating you need to set the active project to the specified file.

 

Please could someone help.

 

Many thanks

 

0 Likes
Accepted solutions (1)
670 Views
5 Replies
Replies (5)
Message 2 of 6

bradeneuropeArthur
Mentor
Mentor
Accepted solution
 Public Sub InventorProjectFile(oInvapp As Inventor.Application)

        Dim proj As DesignProject

        Try
            proj = oInvapp.DesignProjectManager.DesignProjects.ItemByName("C:\#######.ipj")
            proj.Activate()
        Catch ex As Exception
            If Not oInvapp.DesignProjectManager.ActiveDesignProject.FullFileName = "C:\#######.ipj" Then
                MsgBox("The wrong Project file has been Loaded !" & vbCrLf & "The Current Project file = " & oInvapp.DesignProjectManager.ActiveDesignProject.Name & vbCrLf & "Load the " & "C:\#######.ipj" & " file", vbCritical)
            End If
        End Try
end sub

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

Message 3 of 6

neil.cooke
Participant
Participant

Cheers, I have managed to play around with this and get what I needed. Thanks

0 Likes
Message 4 of 6

SevInventor
Advocate
Advocate

Hello,

how do you guys trigger this rule? I need to check if a user works in the wrong project.
The check should be done when Inventor launches.
I'm often asked what the problem is.
After some troubleshooting i find out the project was out of tune. 
 Sometimes it costst time to find out....

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Are you planning on handling its triggering entirely with iLogic rules, or do you intend to use an add-in?  Add-ins load when Inventor starts, and iLogic itself is an add-in.  Plus, the iLogic add-in doesn't really initialize in the user interface until we either open an existing Inventor file, or start a 'New' one for the first time after starting Inventor.  So, if you wanted to keep it simple, you could put it in the iLogic 'Event Triggers' dialog, on the 'All Documents' tab, under the 'New Document' event, and under the 'After Open Document' event.  But if you do it that way, the rule will likely get ran a lot of times, so it should be pretty efficient.  If using an add-in, I think they can use the ApplicationEvents.OnReady Event which is associated with the Application.Ready property, but I am not experienced in add-in development yet.

By the way, here is another example you can review or modify however you want.  I intentionally made the hardcoded file path & name generic, so you would have to edit those before testing it.  The first 2 are not being used right now, so they could be eliminated.  There are other properties or methods related to the projects which can use them, but they are not present in this example.

Sub Main
	Const sProjPath As String = "C:\Temp\"
	Const sProjFileName As String = "MyInventorProject.ipj"
	Const sProjFile As String = "C:\Temp\MyInventorProject.ipj"
	Dim oProjMgr As Inventor.DesignProjectManager = ThisApplication.DesignProjectManager
	'get FullFileName of active DesignProject
	Dim sActiveProj As String = oProjMgr.ActiveDesignProject.FullFileName
	'only react if it is not the one expected / wanted
	If Not sActiveProj = sProjFile Then
		'Log it, or let user know
		Logger.Info("Active Project File Is:  " & sActiveProj)
		'MessageBox.Show("Active Project File Is:  " & sActiveProj)
		'try to find / get the DesignProject we want, by its FullFileName
		Dim oMyProj As Inventor.DesignProject = Nothing
		Try
			oMyProj = oProjMgr.DesignProjects.ItemByName(sProjFile)
		Catch
			Logger.Warn("Specified Inventor DesignProject Not Fount In Projects Collection!")
		End Try
		'if it was not found in that collection, then add it
		If oMyProj Is Nothing Then
			Try
				oMyProj = oProjMgr.DesignProjects.AddExisting(sProjFile)
			Catch
				Logger.Error("Error Adding Specified DesignProject To Projects Collection!")
			End Try
		End If
		'if we now have it, then activate it
		If oMyProj IsNot Nothing Then
			Try
				'True = Set as Default Project
				oMyProj.Activate(True)
			Catch
				Logger.Error("Error Activating Specified DesignProject!")
			End Try
		End If
	End If
End Sub

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

bradeneuropeArthur
Mentor
Mentor

I have had exactly the same issu and solved via a add in. Works like a charm. Let me have a look how we can arrange. Could you please send me a pm.

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