Add Area Property in every Assembly parts

Add Area Property in every Assembly parts

CCarreiras
Mentor Mentor
798 Views
4 Replies
Message 1 of 5

Add Area Property in every Assembly parts

CCarreiras
Mentor
Mentor

HI!

 

My goal is to populate the "Area" Property in every Assembly parts, among other properties.

I'm able to manage other custom propertiesand sheet metal extends, but i'm not able to do that with the "Area".

 

Any help?

 

In the code below, Sheet metal extends and custom properties are working. Any idea for  Area? Thanks.

 

SyntaxEditor Code Snippet

Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
Dim docFile As Document

    For Each docFile In openDoc.AllReferencedDocuments
		
        	If docFile.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
             docFile.PropertySets.Item("Design Tracking Properties").Item("Description").Value= "SheetMetal"
             'docFile.ComponentDefinition.Parameters("Thickness").ExposedAsProperty = True 
		
	oParam = docFile.ComponentDefinition.Parameters("Thickness")       
	oParam.ExposedAsProperty = True
								
			oCustomPropertySet = docFile.PropertySets.Item _
			("Inventor User Defined Properties")
		    On Error Resume Next
			oCustomPropertySet.Item("", "SM_Length").Value = "=<Sheet Metal Length>"
				If Err.Number <> 0 Then
					oCustomPropertySet.Add("", "SM_Length").Value = "=<Sheet Metal Length>"
				End If	
			oCustomPropertySet.Item("", "SM_Width").Value = "=<Sheet Metal Width>"
				If Err.Number <> 0 Then
					oCustomPropertySet.Add("", "SM_Width").Value = "=<Sheet Metal Width>"
				End If		
				
oCustomPropertySet.Item("", "Area").Value = "=<Area?????????????>"
If Err.Number <> 0 Then
	oCustomPropertySet.Add("", "Area").Value = "=<Area???????????????>"
End If		
																			
			Else 
			
			docFile.PropertySets.Item("Design Tracking Properties").Item("Description").Value = "Part"
			
oCustomPropertySet = docFile.PropertySets.Item _
("Inventor User Defined Properties")
On Error Resume Next
oCustomPropertySet.Item("", "Area").Value = "=<Area?????????????>"
If Err.Number <> 0 Then
oCustomPropertySet.Add("", "Area").Value = "=<Area??????????????>"
End If
		End If
Next

CCarreiras

EESignature

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

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @CCarreiras,

 

Here's a quick ilogic  example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
Dim docFile As Document

For Each docFile In openDoc.AllReferencedDocuments		
    If docFile.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
	
		'get custom prop set
		oCustomPropertySet = docFile.PropertySets.Item _
		("Inventor User Defined Properties")
		
		'get mass prop set
		Dim oMassProps As MassProperties
    	 oMassProps = docFile.ComponentDefinition.MassProperties
		
		'[ set length 
		Try
			'see if iprop exists
			oTest = oCustomPropertySet.Item("SM_Length").Value
		Catch
			'create it if not found
			oCustomPropertySet.Add("","SM_Length")
		End Try
		'set iprop value
		oCustomPropertySet.Item("SM_Length").Value = "=<Sheet Metal Length>"
		']
		
		'[ set width 
		Try
			'see if iprop exists
			oTest = oCustomPropertySet.Item("SM_Width").Value
		Catch
			'create it if not found
			oCustomPropertySet.Add("","SM_Width")
		End Try
		'set iprop value
		oCustomPropertySet.Item("SM_Width").Value = "=<Sheet Metal Width>"
		']

		
		'[ set area 
		Try
			'see if iprop exists
			oTest = oCustomPropertySet.Item("Area").Value
		Catch
			'create it if not found
			oCustomPropertySet.Add("","Area")
		End Try
		'set iprop value
		oCustomPropertySet.Item("Area").Value = Round(oMassProps.Area,0) & " cm^2"
		']

		
	End If

Next

EESignature

Message 3 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Another version of the same rule:

 

Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
Dim docFile As Document

For Each docFile In openDoc.AllReferencedDocuments		
    If docFile.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
	
		'get custom prop set
		oCustomPropertySet = docFile.PropertySets.Item _
		("Inventor User Defined Properties")
		
		'get mass prop set
		Dim oMassProps As MassProperties
    	oMassProps = docFile.ComponentDefinition.MassProperties
		oArea = Round(oMassProps.Area,0) & " cm^2"
		
		'add each iprop to am array  list
		'using a "|" to seperate the name from the value
		Dim cIprops As New ArrayList
		cIprops.add("SM_Length" & "|" & "=<Sheet Metal Length>")
		cIprops.add("SM_Width" & "|" & "=<Sheet Metal Width>")
		cIprops.add("Area" & "|" & oArea)
		
		i = 0
		For Each oItem in cIprops		
		
			'split array list lines into values using the "|" Char
			Dim oProps As String() 
			oProps = cIprops.Item(i).Split(New Char() {"|"c})
			
			'[ set the iProperty
			Try
				'see if iprop exists
				oTest = oCustomPropertySet.Item(oProps(0)).Value
			Catch
				'create it if not found
				oCustomPropertySet.Add("",oProps(0))
			End Try
			
			'set iprop value
			oCustomPropertySet.Item(oProps(0)).Value = oProps(1)	
			']
			
			i = i+1
		Next 'arraylist item
	End If

Next

EESignature

Message 4 of 5

CCarreiras
Mentor
Mentor

Work as required, thank you very much, you rule (iLogic) !!!.

 

This is a nice workflow to create the "Area" parameter .Preferentially, we will create it at the end of the project, and all will work good.

 

But... if we want to continue with the work, there's a chance to forget to update these parameters.

In case of Sheet Metal extends, there's no problem because the parameter is a function attached to the sheet metal properties  ....  there's any chance to do the same with the Area?

 

Being the Area a variable that changes along the process of modeling, it would be possible to create the property, by maintain it associative to the model's area changes?

 

CCarreiras

EESignature

0 Likes
Message 5 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @CCarreiras,

 

I would typically create something like this as an external rule and set an event trigger to have it run at the "Before Save" event.

 

As for an AREA formula, I did not think it existed, but just tried this and it seems to work.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
Dim docFile As Document

For Each docFile In openDoc.AllReferencedDocuments		
    If docFile.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
	
		'get custom prop set
		oCustomPropertySet = docFile.PropertySets.Item _
		("Inventor User Defined Properties")
		
		
		'add each iprop to am array  list
		'using a "|" to seperate the name from the value
		Dim cIprops As New ArrayList
		cIprops.add("SM_Length" & "|" & "=<Sheet Metal Length>")
		cIprops.add("SM_Width" & "|" & "=<Sheet Metal Width>")
		cIprops.add("Area" & "|" & "=<Sheet Metal Area>")
		
		i = 0
		For Each oItem in cIprops		
		
			'split array list lines into values using the "|" Char
			Dim oProps As String() 
			oProps = cIprops.Item(i).Split(New Char() {"|"c})
			
			'[ set the iProperty
			Try
				'see if iprop exists
				oTest = oCustomPropertySet.Item(oProps(0)).Value
			Catch
				'create it if not found
				oCustomPropertySet.Add("",oProps(0))
			End Try
			
			'set iprop value
			oCustomPropertySet.Item(oProps(0)).Value = oProps(1)	
			']
			
			i = i+1
		Next 'arraylist item
	End If

Next

EESignature

0 Likes