Identify constraints on a particular part inside a sub-assembly with iLogic

Identify constraints on a particular part inside a sub-assembly with iLogic

nick5MWHR
Contributor Contributor
633 Views
8 Replies
Message 1 of 9

Identify constraints on a particular part inside a sub-assembly with iLogic

nick5MWHR
Contributor
Contributor

I've bassicaly got the some question as @DRoam ... However, I'm keen on using iLogic so I'm curious if it is possible.

 

https://forums.autodesk.com/t5/inventor-forum/identify-constraints-on-a-particular-part-inside-a-sub...

 

I'm currently checking if a property of all parts in an assembly (and subassamblies) have a property "IO Type" and if this IO Type contains cable, I want to know to what part this is attached. The code is working;however, I'm struggling with the same part as @DRoam... If the cable is directly constrained to a part I'm retrieving the part, but when the cable is connected to a subassembly, I'm retrieving the subassembly.

 

I'm wondering if it is possible to retrieve the part? I read something about proxy but I don't know how to use that and if it can be achieved using proxy.

 

Keep in mind that the code below is part of a bigger code. This is just the part that checks if the part contains the property and if that property equals cable.

 

	If sFileName.Contains(".ipt") And sBomstructure.Contains("kPurchased") And Not sFileName.Contains("DIN") And Not sFileName.Contains("ISO") Then
		Try 
			IOType = iProperties.Value(sFileName, "Custom", "IO Type")
		Catch
		End Try
		
		If IOType <> "" Then
			sPartNumber = iProperties.Value(sFileName, "Project", "Part Number") 'Everything contains a Part Number
			Try 
				sFabricationNumber = iProperties.Value(sFileName, "Custom", "Fabrication Number") 'Not everything has a fabrication number
								
			Catch
			End Try
			
			If IOType = "Cable" Then
			'Check to what assembly/part the cable is connected.
				For Each CableConstraint As AssemblyConstraint In oComp.Constraints	
					If Not IsNothing(CableConstraint.OccurrenceOne) And Not IsNothing(CableConstraint.OccurrenceTwo) Then
						If CableConstraint.OccurrenceOne.Name <> oComp.Name Then
							IOAttached = CableConstraint.OccurrenceOne.Name
						Else
							IOAttached = CableConstraint.OccurrenceTwo.Name
						End If
					Exit For	
					End If
				Next	
			End If
		End If
	End If

 

0 Likes
Accepted solutions (1)
634 Views
8 Replies
Replies (8)
Message 2 of 9

m_baczewski
Advocate
Advocate
Accepted solution

Hello,

 

Check this.

 

If sFileName.Contains(".ipt") And sBomstructure.Contains("kPurchased") And Not sFileName.Contains("DIN") And Not sFileName.Contains("ISO") Then
		Try 
			IOType = iProperties.Value(sFileName, "Custom", "IO Type")
		Catch
		End Try
		
		If IOType <> "" Then
			sPartNumber = iProperties.Value(sFileName, "Project", "Part Number") 'Everything contains a Part Number
			Try 
				sFabricationNumber = iProperties.Value(sFileName, "Custom", "Fabrication Number") 'Not everything has a fabrication number
								
			Catch
			End Try
			
			If IOType = "Cable" Then
			'Check to what assembly/part the cable is connected.
				For Each CableConstraint As AssemblyConstraint In oComp.Constraints	
					If Not IsNothing(CableConstraint.OccurrenceOne) And Not IsNothing(CableConstraint.OccurrenceTwo) Then
						If CableConstraint.OccurrenceOne.Name <> oComp.Name Then
'							IOAttached = CableConstraint.OccurrenceOne.Name
							IOAttached = CableConstraint.EntityOne.ContainingOccurrence.Name ' <--- 
						Else
'							IOAttached = CableConstraint.OccurrenceTwo.Name
							IOAttached = CableConstraint.EntityTwo.ContainingOccurrence.Name ' <---
						End If
					Exit For	
					End If
				Next	
			End If
		End If
	End If

 

Message 3 of 9

nick5MWHR
Contributor
Contributor

Thank you! That seems to do the trick!

 

May I ask how you found that command? It doesn't "pop-up" as a suggestion like EntityOne for example.

 

 

0 Likes
Message 4 of 9

m_baczewski
Advocate
Advocate

Personally, I use the Inventor API. Recently, I saw someone insert an interactive PDF that illustrates the API. I personally use the API directly through macros and adding "addwatch" to review a given model/part.

Here is a link to the forum post with the PDF of the API: https://forums.autodesk.com/t5/inventor-programming-ilogic/inventor-api-object-model-diagramm-linked...

 

And an interesting fact: if you define a variable as FaceProxy, you will have access to all properties and methods

 

Dim fProxyEntityOne As FaceProxy = CableConstraint.EntityOne
MsgBox(fProxyEntityOne.ContainingOccurrence.Name)

 

0 Likes
Message 5 of 9

nick5MWHR
Contributor
Contributor

Thanks. If I use the PDF, it sends me to this website. However, I can't see what the "object" contains?

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=AssemblyConstraint_EntityOne

 

The FaceProxy seems to work! 

In what are you programming to use the Inventor API, visual studio?

 

Edit: Wrong link

0 Likes
Message 6 of 9

m_baczewski
Advocate
Advocate

At work, I write in Visual Studio, the iLogic editor, and VBA. I mainly use .NET Framework (C#). To better understand the Inventor API, take a look at this.

 

Follow the steps in the pictures:

m_baczewski_0-1720522322898.png

 

Enter this code in Module1:

 

Sub main()
Dim odoc As Document
Set odoc = ThisApplication.ActiveDocument
End Sub

 

 

Then, press F8 to step through to the line End Sub. Next, hover over odoc, right-click, and select "Add Watch". Now you will have access to what is happening in the application and what type you are dealing with. You can expand the individual branches and explore the Inventor program. This is how I learned the API.

0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor

Hi @nick5MWHR.  Pertaining to your question about where/how to program using Inventor's API...

We usually either work with Inventor's API through iLogic rules, or through the VBA Editor dialog.  But I quit using VBA years ago, not only because it is very outdated, but also because Microsoft (its developer/maintainer) stopped maintaining it years ago, making it dangerously unsecure, which is why they stopped including it in standard Inventor installations years ago.  We can also work with Inventor's API through Visual Studio, if you have Visual Studio set-up properly, and have included the references needed to understand the Inventor API Object model.  However, when working within Inventor's iLogic Rule Editor dialog, and iLogic rules, we have extra resources available to us that are not available from within the VBA Editor...and are not available from Visual Studio either, without some extra references and preparations.  This is because iLogic itself is an ApplicationAddIn within Inventor, with its own API (unlike most other Inventor add-ins), resources, and user interface that are unique to it, making many actions shorter and/or simpler to achieve by code.

Inventor API User's Manual 

iLogic 

iLogic API Overview 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 9

_dscholtes_
Advocate
Advocate

@m_baczewski wrote:
Dim fProxyEntityOne As FaceProxy = CableConstraint.EntityOne

According to the API help, EntityOne should be defined as an Object (because it can be any kind of geometric entity, it's not restricted to a FaceProxy).

 

I use VBA as well to develop macro's, but I use the 'Locals' window instead of the 'Watch'  window in combination with a conveniently placed break statement in the code to find interesting properties. Also, the object browser in the VBA IDE (F2) is great source of object properties/methods.

0 Likes
Message 9 of 9

m_baczewski
Advocate
Advocate
Exactly as you say, in this case, I wanted to illustrate that when we define a variable as a certain type, we can see the methods and properties available for that type.
0 Likes