Retrieve File Subtype of parts in assembly file Ilogic

Retrieve File Subtype of parts in assembly file Ilogic

isaac_galuk
Explorer Explorer
216 Views
4 Replies
Message 1 of 5

Retrieve File Subtype of parts in assembly file Ilogic

isaac_galuk
Explorer
Explorer

I am trying to access the non-editable phrase in the iproperties-project-File Subtype for each part in an assembly. Basically I am trying to make a code that will search the parts of an assembly and return which of them are sheet metal parts. 

 

The easiest way I thought of would be to see if the File Subtype was "Sheet metal" for each part. The problem is 

Dim oFileSubtype = iProperties.Value("Project","Document SubType Name")

returns the top level assembly subtype as "Assembly" , and

Dim propSet = oRefDoc.PropertySets("Inventor User Defined Properties")

can return the custom iproperties for each part in the assembly, but something like

Dim propFiletype = oRefDoc.PropertySets("Project","Document SubType Name")

 gives an error.

 

so how would I go about grabbing the File Subtype or checking if a part is a sheet metal part in an assembly?

Thanks in advance!

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

jwingateRJECD
Enthusiast
Enthusiast

Try this, it should at least have the bones of what you are looking for. 

 

Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oBOM As BOM = oADoc.ComponentDefinition.BOM
oBOM.SetPartNumberMergeSettings(False)
oBOM.HideSuppressedComponentsInBOM = True
oBOM.PartsOnlyViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only")

For Each oBOMRow As BOMRow In oBOMView.BOMRows
	If oBOMRow.ComponentDefinitions(1).Document.SubType.ToString = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		Dim oDoc As PartDocument = oBOMRow.ComponentDefinitions(1).Document
		Dim oPartName As String = Left(oDoc.FullFileName, oDoc.FullFileName.Length - 4)
		MessageBox.Show(oPartName, "This is a sheet metal part.")
	End If
Next
Message 3 of 5

isaac_galuk
Explorer
Explorer

Thanks! For the speed of response and that it does work is great! I have been using it to integrate into my code. 

 

My main problem now is my loop (like the reference forum below) loops through each reference doc and not the BOM. I would just have to match the custom iproperty of a certain part to the same part number found in the sheet metal BOM loop. 

 

For the future,  I would like a simpler way to tell without needing the SubType to string as the {...} phrase.

The ways I have brainstormed are:

- Read the "Thickness" parameter is not = 0, therefore a sheet metal part

- Read the iproperties-project-File Subtype (since it cannot be manually edited) if it says "Sheet Metal"

 

 

For reference, I used the forum below for how to get the custom iproperties information for each part in the assembly

https://forums.autodesk.com/t5/inventor-programming-ilogic/read-custom-properties-from-parts-within-...

 

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

About the shortest way to get the value of that specific iProperty is using the Inventor API way, when you know which 'index' positions that PropertySet and Property are at.  The first 4 PropertySets in every document will always be there, and the first 3 are stable, meaning we can not add to, subtract from, or reorder the properties in them.  The one nicknamed 'Project' is just nicknamed that because of what 'tab' some of them are on in the standard dialog, but it is always the third PropertySet.  We can chart-out all the properties in those first three sets, and count on them always being there, and in the same order, and positions.  With that in mind, we can use the following, as an example:

Dim oDoc As Inventor.Document = ThisDoc.Document
Dim sDocSubTypeName As String = oDoc.PropertySets(3)(17).Value
MsgBox(sDocSubTypeName, vbInformation, "Document SubType Name")

The '3' in Line 2 is telling it which PropertySet, then the '17' is telling it which Property.

One negative aspect to using that iProperty is that 'regular' parts are just called "Modeling", instead of "Part", so you may need to 'interpret' that one result the way you want.

I have gone through this type of thing so many times over the years, and have used so many different ways to achieve the same results, that I finally settled on a method of checking document sub type that is a bit different than the typical routes.  I now use the 'TypeOf' operator to check which base type of document I am dealing with (Drawing, Part, Assembly), then once I know it is one of the 'model' types (Part or Assembly), I then use another 'TypeOf' operator to check which Type of 'ComponentDefinition' it has.  Each 'regular' type has a specific one, and each 'sub type' has a specific one.  I know that we can use the DocumentTypeEnum for checking base document type, but using TypeOf operator actually processes faster, and is super simple to look at and read later.  And since there is no DocumentSubTypeEnum (despite me asking for one in the Inventor Ideas forum), using the TypeOf operator seems to be the fastest, and easiest to read way of determining which one I am dealing with.

Example:

Dim oDoc As Inventor.Document = ThisDoc.Document
If TypeOf oDoc Is PartDocument Then
	Dim oPDoc As PartDocument = oDoc
	If TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then
		Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
		'and so on
	End If
ElseIf TypeOf oDoc Is AssemblyDocument Then
	Dim oADoc As AssemblyDocument = oDoc
	If TypeOf oADoc.ComponentDefinition Is WeldmentComponentDefinition Then
		Dim oWeldmentDef As WeldmentComponentDefinition = oADoc.ComponentDefinition
		'and so on
	End If
ElseIf TypeOf oDoc Is DrawingDocument Then
	Dim oDDoc As DrawingDocument = oDoc
	
End If

Edit:  Another way this could be done, using the same strategy is:

Dim oDoc As Inventor.Document = ThisDoc.Document
Dim bIsPart As Boolean = (TypeOf oDoc Is PartDocument)
Dim bIsAssembly As Boolean = (TypeOf oDoc Is AssemblyDocument)
Dim bIsDrawing As Boolean = (TypeOf oDoc Is DrawingDocument)
Dim oCD As Inventor.ComponentDefinition = Nothing
If bIsPart OrElse bIsAssembly Then oCD = oDoc.ComponentDefinition
Dim bIsSheetMetal As Boolean = (bIsPart AndAlso TypeOf oCD Is SheetMetalComponentDefinition)
Dim bIsWeldment As Boolean = (bIsAssembly AndAlso TypeOf oCD Is WeldmentComponentDefinition)
Dim bRegularPart As Boolean = (bIsPart AndAlso (Not bIsSheetMetal))
Dim bRegularAssembly As Boolean = (bIsAssembly AndAlso (Not bIsWeldment))

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)

Message 5 of 5

isaac_galuk
Explorer
Explorer
Accepted solution

Thanks! The PrepertySets(3)(17).Value was what I needed!

Dim sDocSubTypeName As String = oDoc.PropertySets(3)(17).Value

 

I will keep the rest in mind if I create another code that needs to differentiate between assemblies, model parts, and sheet metal parts.

 

For now here is my working code for checking an assembly for all the sheet metal parts, without duplicates.

 

Dim oAsm As AssemblyDocument = ThisDoc.Document

Dim oSheetPart As New List(Of String)

For Each oRefDoc As Document In oAsm.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject AndAlso oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
		
		Dim oOccName As String = oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)(1).Name
		If oOccName.Contains(":") Then oOccName = oOccName.Split(":")(0)
			
		Dim sDocSubTypeName As String = oRefDoc.PropertySets(3)(17).Value

		If sDocSubTypeName = "Sheet Metal"
			oSheetPart.Add(oOccName)
		End If 
		
	End If
Next

oSheetMetalChoice = InputListBox("Sheet Metal Parts in Assembly ", oSheetPart, "Sheet Metal Parts in Assembly ")

 

 

 For reference, I used the forum below for the main loop

https://forums.autodesk.com/t5/inventor-programming-ilogic/read-custom-properties-from-parts-within-...

0 Likes