Common Part Qty's In Different Sub Assemblies - Separate Custom Iprops Within Common Part

Common Part Qty's In Different Sub Assemblies - Separate Custom Iprops Within Common Part

drafting4KGWTN
Contributor Contributor
385 Views
7 Replies
Message 1 of 8

Common Part Qty's In Different Sub Assemblies - Separate Custom Iprops Within Common Part

drafting4KGWTN
Contributor
Contributor

Hi all,

 

I'm currently working on a project where we use the same part multiple times through different sub assemblies of the same main assembly, and when we do the part details we put the part QTY native sub-assembly they're tied to. 

i.e - one sub-assembly would have QTY-5, another would have QTY-10 etc.

 

what I've been trying to do, is make a code (with snippets gathered from these forums) that would go through the main assembly, find all the occurrences of common parts throughout the sub-assemblies and stack those quantities as separate custom iproperties at the part level.

 

See below screenshot for desired outcome. The code i've cobbled together works in 2 parts. the 1st gives the 'PartQty' custom iproperty, and the 2nd gives the 'MultiAssy' custom iproperty. 

 

 

drafting4KGWTN_0-1741125014120.png

 

This method can do the job if there's only 1 more sub-assembly where the part occurs, but any more than one and the 'MultiAssy' value gets overridden.

 

Ideally, I'd like the 'MultiAssy' iprop to take the name of the assembly its being linked to so it's easy to see which total to call up during detailing. But i'm not sure if that's being to greedy at this point. 

 

I've attached both snippets of code i've mentioned above, if anyone better versed could give some assistance it would be greatly appreciated

 

@WCrihfield I've seen your name pop up in a few of these threads. any chance you could have a peek?

0 Likes
Accepted solutions (1)
386 Views
7 Replies
Replies (7)
Message 2 of 8

J-Camper
Advisor
Advisor

It is generally not a good idea to put assembly level information in a part document, but it is possible.  I think this will do what you want:

Sub Main
	Dim mainDoc As AssemblyDocument = TryCast(ThisApplication.ActiveDocument, AssemblyDocument)
	If mainDoc Is Nothing Then MessageBox.Show("Needs to be run in an Assembly Document", "Nothing Happened") : Exit Sub
	
	Dim PartDocuments , AssemblyDocuments As New List(Of Document)

	For Each RefDoc As Document In mainDoc.AllReferencedDocuments
		If mainDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(RefDoc).Cast(Of ComponentOccurrence).Where(Function(s) s.Suppressed = False).Count < 1 Then Continue For
		If RefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
			PartDocuments.Add(RefDoc)
		Else If RefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
			AssemblyDocuments.Add(RefDoc)
		End If		
	Next

	For Each pDoc As PartDocument In PartDocuments
		Dim qty As Integer = mainDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(pDoc).Cast(Of ComponentOccurrence).Where(Function(s) s.Suppressed = False).Count
		AddiProperty(pDoc, mainDoc.DisplayName, qty)
		For Each aDoc As AssemblyDocument In AssemblyDocuments
			qty = aDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(pDoc).Cast(Of ComponentOccurrence).Where(Function(s) s.Suppressed = False).Count
			If qty < 1 
				DeleteiProperty(pDoc, aDoc.DisplayName)
			Else	
				AddiProperty(pDoc, aDoc.DisplayName, qty)
			End If
		Next
	Next
	
End Sub

Sub DeleteiProperty(pDoc As PartDocument, AssemblyName As String)
	
	Dim CustomiProperties As PropertySet = pDoc.PropertySets.Item("Inventor User Defined Properties")
	
	Try
		Dim prop As Inventor.Property = CustomiProperties.Item(AssemblyName)
		prop.Delete()
	Catch:End Try
	
End Sub

Sub AddiProperty(pDoc As PartDocument, AssemblyName As String, qty As Integer)
	
	Dim CustomiProperties As PropertySet = pDoc.PropertySets.Item("Inventor User Defined Properties")
	
	Try
		Dim prop As Inventor.Property = CustomiProperties.Item(AssemblyName)
		If prop.Value <> qty Then prop.Value = qty
	Catch
		 CustomiProperties.Add(qty, AssemblyName)
	End Try
	
End Sub

 

0 Likes
Message 3 of 8

drafting4KGWTN
Contributor
Contributor

thanks mate, it works for what i need at the part level. Now the other hurdle is putting that custom property into the view label.

 

below is the code i have been using in conjunction with the 1st attached code above

 

utilising the code you've given here, im not sure how to pull that custom iprop over into this code though

 

'AUTOMATED PART LABEL

Dim oSSet As SelectSet = ThisDrawing.Document.SelectSet
If oSSet.Count = 0 Then
	MsgBox("You need to pre-select a drawing view before running this rule.  Exiting.", , "")
	Exit Sub
End If
oView = oSSet.Item(1)
If oView Is Nothing Then Exit Sub
	
	'get the model
	    oModelName = oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
	
'idenfity properties
oPartNumber = "<StyleOverride FontSize='0.45' Bold='False' Underline='False'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>"
oDescription = "<StyleOverride FontSize='0.45' Bold='false' Underline='false'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>Description</Property></StyleOverride>"
oPrtQty = "<StyleOverride FontSize='0.35' Bold='FALSE' Underline='false'><Property Document='model' PropertySet='Inventor User Defined Properties' Property='PartQty' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' >Qty</Property></StyleOverride>" 
oStringScale = "<StyleOverride FontSize='0.35'>SCALE: <DrawingViewScale/></StyleOverride>"



'assemble them using <Br/> to go to the next line
oView.Label.FormattedText = oPartNumber & " - " & oDescription & "<Br/>" & "<StyleOverride FontSize='0.35'>QTY: </StyleOverride>" & oPrtQty & "<StyleOverride FontSize='0.35'> OFF</StyleOverride>" & "<Br/>" & oStringScale

 

thanks for the help so far mate

0 Likes
Message 4 of 8

J-Camper
Advisor
Advisor

I don't know if the formatting is correct, but this should add any iProperties that match the format I set up in the first rule.  It might give more than needed if you have other iProperties with the same name format [iproperty name contains ".iam"]:

'AUTOMATED PART LABEL

Dim oSSet As SelectSet = ThisDrawing.Document.SelectSet
If oSSet.Count = 0 Then
	MsgBox("You need to pre-select a drawing view before running this rule.  Exiting.", , "")
	Exit Sub
End If
oView = oSSet.Item(1)
If oView Is Nothing Then Exit Sub
	
	'get the model
	Dim modelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	oModelName = modelDoc.DisplayName
	
'idenfity properties
oPartNumber = "<StyleOverride FontSize='0.45' Bold='False' Underline='False'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>"
oDescription = "<StyleOverride FontSize='0.45' Bold='false' Underline='false'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>Description</Property></StyleOverride>"
oPrtQty = "<StyleOverride FontSize='0.35' Bold='FALSE' Underline='false'><Property Document='model' PropertySet='Inventor User Defined Properties' Property='PartQty' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' >Qty</Property></StyleOverride>" 
oStringScale = "<StyleOverride FontSize='0.35'>SCALE: <DrawingViewScale/></StyleOverride>"

Dim PartQTYs As New List(Of String)

For Each iProp As Inventor.Property In modelDoc.PropertySets.Item("Inventor User Defined Properties")
	If Not iProp.Name.Contains(".iam") Then Continue For
	PartQTYs.Add("<StyleOverride FontSize='0.45' Bold='False' Underline='False'>QTY in "&iProp.Name &": </StyleOverride><StyleOverride FontSize='0.35' Bold='FALSE' Underline='false'><Property Document='model' PropertySet='Inventor User Defined Properties' Property='" & iProp.Name & "' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' ></Property></StyleOverride>" )
Next

Dim FormattedText As String 
If PartQTYs.Count < 1
	FormattedText = oPartNumber & " - " & oDescription & "<Br/>" & "<StyleOverride FontSize='0.35'>QTY: </StyleOverride>" & oPrtQty & "<StyleOverride FontSize='0.35'> OFF</StyleOverride>" & "<Br/>" & oStringScale
Else
	Dim Prefix As String = oPartNumber & " - " & oDescription
	Dim Suffix As String = "<Br/>" & oStringScale
	
	FormattedText = Prefix
	For Each s As String In PartQTYs
		FormattedText = FormattedText & "<Br/>" & s
	Next
	FormattedText = FormattedText & Suffix
End If


'assemble them using <Br/> to go to the next line
oView.Label.FormattedText = FormattedText

 

0 Likes
Message 5 of 8

drafting4KGWTN
Contributor
Contributor

thanks mate. the code works, but i'll try and tweak it a little so it only calls up the total for the assembly that is being detailed. Gives me a good starting block 🙂

0 Likes
Message 6 of 8

drafting4KGWTN
Contributor
Contributor

Alright, i've got the code to display the qty's how the boss wants them. The only hitch now is i want to be able to hide the quantities that are not a part of the assembly i'm detailing. Below is the code i've been trying to use

 

Dim oSSet As SelectSet = ThisDrawing.Document.SelectSet
If oSSet.Count = 0 Then
	MsgBox("You need to pre-select a drawing view before running this rule.  Exiting.", , "")
	Exit Sub
End If
oView = oSSet.Item(1)
If oView Is Nothing Then Exit Sub
	
	'idenfity properties
oPartNumber = "<StyleOverride FontSize='0.45' Bold='False' Underline='False'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>"
oDescription = "<StyleOverride FontSize='0.45' Bold='false' Underline='false'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>Description</Property></StyleOverride>"
oPrtQty = "<StyleOverride FontSize='0.35' Bold='FALSE' Underline='false'><Property Document='model' PropertySet='Inventor User Defined Properties' Property='PartQty' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' >Qty</Property></StyleOverride>" 

'pick which qty to show
Dim Assy As String
Assy = InputBox(" Enter the Number of the Desired Assembly", "Picking the Right Assembly QTY to Show", )
For Each oPartNumber In oView.label
If Assy <> oPartNumber Then
	oView.Label.FormattedText = oView.Label.Replace("<oPartNumber>", "")
end if

Next

and it's giving me this error message 

drafting4KGWTN_0-1741577062776.png

The purpose of the input box is to pick the specific assembly/part qty i need for that view label. Clearly i've stuffed something. Anymore help you could give me please?

0 Likes
Message 7 of 8

J-Camper
Advisor
Advisor
Accepted solution

@drafting4KGWTN,

I don't know how much you changed, but i adjusted the last thing i posted to include a list selection to ask user which assembly to add to the label:

'AUTOMATED PART LABEL

Dim oSSet As SelectSet = ThisDrawing.Document.SelectSet
If oSSet.Count = 0 Then
	MsgBox("You need to pre-select a drawing view before running this rule.  Exiting.", , "")
	Exit Sub
End If
oView = oSSet.Item(1)
If oView Is Nothing Then Exit Sub
	
	'get the model
	Dim modelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	oModelName = modelDoc.DisplayName
	
'idenfity properties
oPartNumber = "<StyleOverride FontSize='0.45' Bold='False' Underline='False'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>"
oDescription = "<StyleOverride FontSize='0.45' Bold='false' Underline='false'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>Description</Property></StyleOverride>"
oPrtQty = "<StyleOverride FontSize='0.35' Bold='FALSE' Underline='false'><Property Document='model' PropertySet='Inventor User Defined Properties' Property='PartQty' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' >Qty</Property></StyleOverride>" 
oStringScale = "<StyleOverride FontSize='0.35'>SCALE: <DrawingViewScale/></StyleOverride>"

Dim iPropOptions As New List(Of String)

For Each iProp As Inventor.Property In modelDoc.PropertySets.Item("Inventor User Defined Properties")
	If Not iProp.Name.Contains(".iam") Then Continue For
	iPropOptions.Add(iProp.Name)
Next

Dim specifyAssembly As String = String.Empty
specifyAssembly = InputListBox("Selection the Assembly you want to add to view label.", iPropOptions, specifyAssembly, Title := "Assembly Selection", ListName := "Available iProperties")

If specifyAssembly = String.Empty Then Exit Sub
Dim PartQTYs As New List(Of String)
For Each iProp As Inventor.Property In modelDoc.PropertySets.Item("Inventor User Defined Properties")
	If Not iProp.Name.Equals(specifyAssembly) Then Continue For
	PartQTYs.Add("<StyleOverride FontSize='0.45' Bold='False' Underline='False'>QTY in "&iProp.Name &": </StyleOverride><StyleOverride FontSize='0.35' Bold='FALSE' Underline='false'><Property Document='model' PropertySet='Inventor User Defined Properties' Property='" & iProp.Name & "' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' ></Property></StyleOverride>" )
Next

Dim FormattedText As String 
If PartQTYs.Count < 1
	FormattedText = oPartNumber & " - " & oDescription & "<Br/>" & "<StyleOverride FontSize='0.35'>QTY: </StyleOverride>" & oPrtQty & "<StyleOverride FontSize='0.35'> OFF</StyleOverride>" & "<Br/>" & oStringScale
Else
	Dim Prefix As String = oPartNumber & " - " & oDescription
	Dim Suffix As String = "<Br/>" & oStringScale
	
	FormattedText = Prefix
	For Each s As String In PartQTYs
		FormattedText = FormattedText & "<Br/>" & s
	Next
	FormattedText = FormattedText & Suffix
End If


'assemble them using <Br/> to go to the next line
oView.Label.FormattedText = FormattedText

 

Let me know if you have any questions, or if this is not working as intended.

Message 8 of 8

drafting4KGWTN
Contributor
Contributor

After putting in the extra bit of code you added, the label works as desired now.

Thanks for all your help

0 Likes