Adding Surface area to BOM/parts list

Adding Surface area to BOM/parts list

mjc_design
Advocate Advocate
417 Views
3 Replies
Message 1 of 4

Adding Surface area to BOM/parts list

mjc_design
Advocate
Advocate

Hi all

I'm trying to add a surface area column to parts list on a project i am working on , using an ilogic that i got from this forum but i'm not having much luck getting it to work. It returns an error every time i try, and some parts and sub-assemblies have the custom iproperty added, but never the top level assembly (the open document basically). I've tries it with multiple assemblies and no joy with any of them.

Does anyone have any success with troubleshooting this?

 

Matt

snip3.JPGSNIP 2.JPGsnip1.JPG

 

0 Likes
418 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

If you want to work with the document your running the rule from you will need to replicate what is happening in the occurrence loop out side of the loop. What is happening in the loop will only affect  occurrences of document type assembly and part. 

To work with the main assembly the rule is running from.

1. Copy the contents of the if statement and place before the for loop. 

2. The document reference for the area of component  iproperty  and the custom iproperty will need to be changed from “oOccurrence.Name” to “ThisApplication.ActiveDocument.DisplayName” or alternatively leave it blank and it will default to the top document. 

3. To deal with read only files like content center/library either filter out using appropriate document filter or use an error catch statement such as below. 

 

1> Using error catch on the for loop statement


On Error Resume Next'Error catching statement
For 
'Do Something
Next

 

2> Use try catch statement around the if statement contents

Try
'Do Something
Catch
'Catch Error
End Try

If you have any issues applying the changes paste the complete rule in to this post and user can trouble shoot. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 4

marcin_otręba
Advisor
Advisor

hi,

use:

 

Try
	oocurrance.Definition.Document.PropertySets(4).Item("SurfaceArea")=strArea	
Catch 
oocurrance.Definition.Document.PropertySets(4).Add(strArea,"SurfaceArea")	
End Try

instead of:

iProperties.Value(oocurrance.name, "Custom", "SurfaceArea")

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Both points mentioned above by the other helpful folks are valid and useful, but just in case you are not sure how to apply it all, here is a completed version of the code for you to look at.

 

Also, just so you know, there are multiple ways to get the surface area of documents and components.  You've already pointed out one of them that isn't very well known, because its documentation isn't found in the usual places to look for such things.  When using the iProperties iLogic snippet, there is also a property of that iProperties object called Area that can be used (may have been introduced in the 2022 version though).  When using the longer API route, there is a standard iProperty in the third Set called "SurfaceArea", which is ReadOnly, and returns a value in database units.  There is a so an Area property within the MassProperties object, under the ComponentDefinition of Parts & Assemblies.

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oAsmArea = iProperties.Area 'retrieved from the 'active' document by default
oAsmArea = Round(oAsmArea / 10000, 3) & " m^2"
Dim oAsmSAProp As Inventor.Property
Try
	oAsmSAProp = oADoc.PropertySets.Item(4).Item("SurfaceArea")
	oAsmSAProp.Value = oAsmArea
Catch
	oAsmSAProp = oADoc.PropertySets.Item(4).Add(oAsmArea, "SurfaceArea")
End Try

oADef = oADoc.ComponentDefinition
For Each oOcc As ComponentOccurrence In oADef.Occurrences.AllReferencedOccurrences(oADef)
	If Not TypeOf oOcc.Definition Is VirtualComponentDefinition Then
		oCompSA = iProperties.AreaOfComponent(oOcc.Name)
		'oCompSA = iProperties.Area(oComp.Name)
		Dim oOccDoc As Document = oOcc.Definition.Document
		'a standard iProperty by this name already exists in all documents (ReadOnly, database units) 
		'oCompSA = oOccDoc.PropertySets.Item(3).Item("SurfaceArea").Value
		
		oCompSA = Round(oCompSA / 10000, 3) & " m^2"
				
		Dim oCSA As Inventor.Property
		Try
			oCSA = oOccDoc.PropertySets.Item(4).Item("SurfaceArea")
			oCSA.Value = oCompSA
		Catch
			oCSA = oOccDoc.PropertySets.Item(4).Add(oCompSA, "SurfaceArea")
		End Try
	End If
Next

 

And just in case the iProperties.Area won't work for you, due to having an older version of Inventor, here are a couple of additional lines you can use to get the Area value.

 

oAsmArea = oADef.MassProperties.Area
oCompSA = oOcc.Definition.MassProperties.Area

 

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)