Create custom iProperty for modified frame generator parts

Create custom iProperty for modified frame generator parts

Zackery.Breeland
Contributor Contributor
503 Views
4 Replies
Message 1 of 5

Create custom iProperty for modified frame generator parts

Zackery.Breeland
Contributor
Contributor

I am trying to create a rule that can be run at the assembly level to identify any frame generator components that have been modified (notch, miter, or manual custom extrusion cut) and then create a custom property that will increment by 1 for each component found that matches the criteria.

 

I have very little experience with iLogic other than simple, single tasks.  I have found how to write a custom property to the components.  I have an idea on how to search through the components to find any features with a predefined name.  I know how to increment the custom property.

 

What I cannot figure out is how to combine the "add custom property" and the "if component has feature, then" code.  I have seen some examples that are somewhat similar and they use Try/Catch code to add the custom property but I can't get that to work with an if/then.  Hopefully someone can help shed some light on this as I've been working on it for 3 days and have a bunch of non-working code to show for it.

0 Likes
Accepted solutions (1)
504 Views
4 Replies
Replies (4)
Message 2 of 5

dalton98
Collaborator
Collaborator

When you add a modification to a frame part inventor adds a custom iproperty to that file named "CUTDETAIL1", "CUTDETAIL2", etc. This is a simple code i put together that goes through every reference document in the assembly and checks if "CUTDETAIL1" exists in that part.

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim modCount As Integer = 0
Dim oRefDoc As Document
For Each oRefDoc In oDoc.AllReferencedDocuments
	Dim oProp As Inventor.Property
	For Each oProp In oRefDoc.PropertySets.Item(4)
		If oProp.DisplayName = "CUTDETAIL1"
			modCount = modCount + 1
		End If
	Next
Next

Try
	oDoc.PropertySets.Item(4).Item("MOD COUNT").Value = modCount
Catch
	oDoc.PropertySets.Item(4).Add(modCount, "MOD COUNT")
End Try
0 Likes
Message 3 of 5

Zackery.Breeland
Contributor
Contributor

I hadn't thought about using CUTDETAIL1, so I was looking for ICadFeatures and names of features, this makes things simpler, thank you.  I checked this code and it is posting the MOD COUNT to the assembly level and not the part level.  I need to post the MOD COUNT to the part so that I can then use this property to modify my part numbers so I can create unique numbers for any parts that are not stock cuts.

 

The code I have so far is below.  I had given up trying to do it all at once and was attempting to put each of the modified parts into a list, then apply the custom property to the list instead of all occurrences. 

	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	oADocDef = oADoc.ComponentDefinition
	Dim appDoc As New List(Of Document)
	Dim docFile As Document
	
	'MsgBox("Defines")
	For Each docFile In oADoc.AllReferencedDocuments
		'MsgBox("Cycle parts")
		Dim oFeat As ICadFeature
			If oFeat Is Miter Or Notch Then
				'MsgBox("check if")
				appDoc.Add(docFile)
	End If
    'msgbox("End if")
	Next
	
	For Each docFile In appDoc
		'MsgBox("appdoc")
		

	Dim InvCustomPropertySet As PropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")
	'MsgBox("propset")
        Try
            Dim invVolumeProperty As Inventor.Property = InvCustomPropertySet.Item("Rule 5")
            invVolumeProperty.Value = "Test1"
			'MsgBox("create prop")
        Catch
            Call InvCustomPropertySet.Add("Test1", "Rule 5")
			'MsgBox("add prop")
        End Try
    Next
	
	

(forgive the horrible formatting) 

0 Likes
Message 4 of 5

dalton98
Collaborator
Collaborator
Accepted solution

Ok I changed my first rule to do that. I wasn't sure how you wanted to go about setting the part number, if you want it to be parameter based or not so i put both ways of doing it. Also I wasn't sure if you wanted to distinguish between miters, notches, cuts, etc. or just want a total number.

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument

Dim oRefDoc As Document
For Each oRefDoc In oDoc.AllReferencedDocuments
	Dim oPN As String
	oPN = oRefDoc.PropertySets.Item(3).Item("Part Number").Value
	Dim oProp As Inventor.Property
	Dim modCount As Integer = 0
	For Each oProp In oRefDoc.PropertySets.Item(4)
		If Left(oProp.DisplayName, 9) = "CUTDETAIL"
			modCount = modCount + 1
		End If
	
	Next
		Try
			oRefDoc.PropertySets.Item(4).Item("MOD COUNT").Value = modCount
'			oRefDoc.PropertySets.Item(3).Item("Part Number").Value = oPN & " - " & modCount
'			oRefDoc.PropertySets.Item(3).Item("Part Number").Value = "= " & oPN & " - " & "<MOD COUNT>"
		
		Catch
			oRefDoc.PropertySets.Item(4).Add(modCount, "MOD COUNT")
			oRefDoc.PropertySets.Item(3).Item("Part Number").Value = oPN & " - " & modCount
'			oRefDoc.PropertySets.Item(3).Item("Part Number").Value = "= " & oPN & " - " & "<MOD COUNT>"
		End Try
Next

 

0 Likes
Message 5 of 5

Zackery.Breeland
Contributor
Contributor

Thank you so much.  I was able to use the try/catch you suggested to get the proper iproperty to update.

0 Likes