iProperties Occurence Access

iProperties Occurence Access

kennyj
Collaborator Collaborator
2,851 Views
6 Replies
Message 1 of 7

iProperties Occurence Access

kennyj
Collaborator
Collaborator

How do I access this area with an iLogic rule?

 

I want to take whatever value is in the "X Occurrence" at the assembly level and link it to a User Parameter in the part file.  I cannot find the path to this area.

 

Goal:  As the part is moved in the assembly, I want my parameter to update accordingly.

 

Thank you for any suggestions.

 

Kenny

 

 

0 Likes
Accepted solutions (1)
2,852 Views
6 Replies
Replies (6)
Message 2 of 7

MechMachineMan
Advisor
Advisor

assembly event triggers.PNG

 

Since the information about a parts location in the assembly is only currently found in the assembly, you must figure out which event you want to use of those listed about to TRIGGER a rule to run through the documents and re-save each of their locations to the files.

 

An big issue I see with this already comes up when you have more than 1 occurrence of the part within the assembly, since there are no occurrence iProperties, as well as what you do when a part is reused in a different assembly.

 

Figure this out, and I'm sure someone can give you the solution.

 

It's as easy as making a for loop that runs through each occurrence (assuming you only want top level components) and then extracting the information from the ComponentOccurrence.Transformation property, and pushing that into the documents iProperties.

 

Again, big issues if a document shows up as more than 1 occurrence, or in another file somewhere.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @kennyj,

 

Try the following iLogic code to access X Offset distance of Occurrences.

 

Dim assyDoc as AssemblyDocument
assyDoc = ThisApplication.ActiveDocument

Dim assyDef as AssemblycomponentDefinition
assyDef = assyDoc.ComponentDefinition

For Each occ as ComponentOccurrence In assyDef.Occurrences
	
	xOffset = Round(occ.Transformation.Translation.x * 0.0328084, 3) 'Converting from cm to ft 
	yOffset = Round(occ.Transformation.Translation.x * 0.0328084, 3) 'Converting from cm to ft
	zOffset = Round(occ.Transformation.Translation.x * 0.0328084, 3) 'Converting from cm to ft
	
	MessageBox.Show("X = "&xOffset &" ft Y = "& yOffset & " ft Z = "& zOffset & " ft", "OffSet Distances in ft")

	
Next

X offset distance can be assigned to a parameter using following code.

 

Parameter("ParameterName") = xOffset

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,

 

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 4 of 7

kennyj
Collaborator
Collaborator

Thank you, Justin.

 

I would think we would trigger the rule at save; possibly at open as well.  I'll have to play with that, once I get there. But agree; must have a trigger.

 

The iProperty Occurrence tab options only appear at the assembly level; it is not available at the part level.  So I need a way to pull that information from the Assembly, and run it through my rule at the part level... I don't think that will work for the reasons you have pointed out...

 

Currently, our work process derives the part into a new file with a unique name; so the library part "Widget" would be "1-1", "1-2", etc. in an assembly.  But your points of multiple occurrences is still valid, we do place multiple "1-1" parts in an assembly sometimes.

 

Currently within an assembly, if I place the part twice each one has a custom / unique iProperty occurrence.  I can change the X, Y or Z and only the selected part moves.  So Inventor already has some method of recognizing which model occurrence is linked to the iProperty occurrence tab.  The same is true of using the part in a separate assembly; the iProperty occurrence is assembly file specific - not linked to the part.

 

I am still trying to link the XYZ iProperty Occurrences to my BOM; but I have to run them through some iLogic equations to convert them to display properly (as you have already helped me with in other posts).  Currently at the part level I can get the results I need - I now need the Part to know WHERE it is in the assembly. 

 

Is there anywhere else other than iProperties Occurrence tab this information resides?  Maybe I'm targeting the wrong area.

 

Thank you again,

 

Kenny

 

 

 

 

 

 

 

 

0 Likes
Message 5 of 7

kennyj
Collaborator
Collaborator

Thank you @chandra.shekar.g!

 

This answered the question!

 

A small note:  Change the code for the y & z offset; as shown it reports the X offset for all three - but easy fix and gets me what I asked for.

 

As Justin has pointed out; I might be asking for the wrong thing, but this is a great help as I learn where I need to go.

 

Best regards,

 

Kenny

 

 

0 Likes
Message 6 of 7

RoyWickrama_RWEI
Advisor
Advisor

I like the code in the post. Also, could you help me with code to retrieve Part Number, Revision number and oProp_Custom. (Try .. Catch may be required for oProp_Custom)

 

Public Class PVars
	Shared oTextSave As String = "C:\Users\Public\Documents\iLogicBuffer.txt"
	Shared iLNO As String = "0004A"
	Sub Main()
		Dim oWrite As System.IO.StreamWriter = System.IO.File.CreateText(oTextSave)
		Dim oDoc As Document = ThisApplication.ActiveDocument
		Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
		Dim oOcc As ComponentOccurrence
		Dim oStr As String = ""
		Dim XX As String = ""
		Dim oList As New List(Of Object)
		oWrite.WriteLine("FILE REFERENCE TREE RAN FROM: " & oDoc.FullFileName)
		oWrite.Close
		For Each oOcc In oCD.Occurrences
			RecurReferencing(oOcc, oStr, 0)
		Next
		Process.Start ("Notepad.exe", oTextSave)
	End Sub
	
	Sub RecurReferencing(oOcc As ComponentOccurrence, oStr As String, Level As Integer)
		Dim SubOcc As ComponentOccurrence
		If Level = 0
			oStr = oOcc.Name
		Else
			oStr = oOcc.Name & "$" & oStr
		End If
		
		Dim SubParts As Integer = 0
		Try
			SubParts = oOcc.Definition.Occurrences.Count
		Catch
		End Try
		
		'Retrieve Rev_Number, Part_number and oProp_Custom
		' Then iterate through the Custom iProperties
		'NEED TO CREATE "oProp_Custom" if not existing. Value, "N/A" may be assigned
		
		'Rev_Number = -----------				'Revision Number
		'Part_number = -----------				'Part Number
		'oProp_Custom = -----------		'a custom property
		




		Dim oStr_Data As String
		oStr_Data = Rev_Number & "$" & Part_number & "$" & oProp_Custom

		oSub_Write(oStr_Data)
		If SubParts = 0
			oSub_Write(oStr)
		Else
			For Each SubOcc In oOcc.Definition.Occurrences
				RecurReferencing(SubOcc, oStr, Level + 1)
			Next
		End If
	End Sub
	
	Sub oSub_Write(oStr As String)
			oWrite = System.IO.File.AppendText(oTextSave)
			oWrite.WriteLine(oStr)	
			oWrite.Flush()
			oWrite.Close
	End Sub

End Class
0 Likes
Message 7 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI ,

 

Hoping that below iLogic code may be helpful.

 

Public Class PVars
	Shared oTextSave As String = "C:\Users\Public\Documents\iLogicBuffer.txt"
	Shared iLNO As String = "0004A"
	Sub Main()
		Dim oWrite As System.IO.StreamWriter = System.IO.File.CreateText(oTextSave)
		Dim oDoc As Document = ThisApplication.ActiveDocument
		Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
		Dim oOcc As ComponentOccurrence
		Dim oStr As String = ""
		Dim XX As String = ""
		Dim oList As New List(Of Object)
		oWrite.WriteLine("FILE REFERENCE TREE RAN FROM: " & oDoc.FullFileName)
		oWrite.Close
		For Each oOcc In oCD.Occurrences
			RecurReferencing(oOcc, oStr, 0)
		Next
		Process.Start ("Notepad.exe", oTextSave)
	End Sub
	
	Sub RecurReferencing(oOcc As ComponentOccurrence, oStr As String, Level As Integer)
		Dim SubOcc As ComponentOccurrence
		If Level = 0
			oStr = oOcc.Name
		Else
			oStr = oOcc.Name & "$" & oStr
		End If
		
		Dim SubParts As Integer = 0
		Try
			SubParts = oOcc.Definition.Occurrences.Count
		Catch
		End Try
		
		Dim oReferDoc As Document
		oReferDoc = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
		
		'Retrieve Rev_Number, Part_number and oProp_Custom
		' Then iterate through the Custom iProperties
		'NEED TO CREATE "oProp_Custom" if not existing. Value, "N/A" may be assigned
		
		Try 
			oProp_Custom = oReferDoc.PropertySets.Item("Inventor User Defined Properties").Item("oProp_Custom").Value 
		Catch 
			Call oReferDoc.PropertySets.Item("Inventor User Defined Properties").Add("N/A","oProp_Custom")
			oProp_Custom = "N/A"
		End Try
		
		Rev_Number = oReferDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number")			'Revision Number
		Part_number = oReferDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number")
		 

		Dim oStr_Data As String
		oStr_Data = Rev_Number & "$" & Part_number & "$" & oProp_Custom

		oSub_Write(oStr_Data)
		If SubParts = 0
			oSub_Write(oStr)
		Else
			For Each SubOcc In oOcc.Definition.Occurrences
				RecurReferencing(SubOcc, oStr, Level + 1)
			Next
		End If
	End Sub
	
	Sub oSub_Write(oStr As String)
			oWrite = System.IO.File.AppendText(oTextSave)
			oWrite.WriteLine(oStr)	
			oWrite.Flush()
			oWrite.Close
	End Sub

End Class

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network