Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Write iProperty values to User Parameters

b.mccarthy
Collaborator

Write iProperty values to User Parameters

b.mccarthy
Collaborator
Collaborator

Hello.

 

I have been using this code to extract various iProperty values and write them to user parameters:

 

'Checks for existing COG, mass, volume and surface area parameters, and creates each if necessary
'Publishes database values to parameters

'Checks for 3d volume, and if nothing exists, ends rule
Volume1 = iProperties.Volume
'MessageBox.Show(Volume1, "Volume1")	

If Volume1 = 0 Then
	Exit Sub
End If

Dim oApp As Inventor.Application = ThisApplication
Dim oParams As Parameters
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oPartCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
oParams = oPartCompDef.Parameters
Dim oUserParams As UserParameters = oParams.UserParameters

'Volume
Try
    p = oParams.Item("Volume")
Catch
    oPara = oParams.AddByValue("Volume", 0, "in^3")
End Try

Parameter("Volume") = Round(iProperties.Volume,2)

'Mass
Try
    p = oParams.Item("Mass")
Catch
    oPara = oParams.AddByValue("Mass", 0, "lbmass")
End Try

Parameter("Mass") = Round(iProperties.Mass,2)

'Surface_Area
Try
    p = oParams.Item("Surface_Area")
Catch
    oPara = oParams.AddByValue("Surface_Area", 0, "in^2")
End Try

Parameter("Surface_Area") = Round(iProperties.Area,2)

'COG_x
Try
    p = oParams.Item("COG_x")
Catch
    oPara = oParams.AddByValue("COG_x", 0, UnitsTypeEnum.kInchLengthUnits)
End Try

Parameter("COG_x") = Round(iProperties.CenterOfGravity.X, 3)

'COG_y
Try
    p = oParams.Item("COG_y")
Catch
    oPara = oParams.AddByValue("COG_y", 0, UnitsTypeEnum.kInchLengthUnits)
End Try

Parameter("COG_y") = Round(iProperties.CenterOfGravity.Y, 3)

'COG_z
Try
    p = oParams.Item("COG_z")
Catch
    oPara = oParams.AddByValue("COG_z", 0, UnitsTypeEnum.kInchLengthUnits)
End Try

Parameter("COG_z") = Round(iProperties.CenterOfGravity.Z, 3)

The code runs fine on parts, but I would to tweak it to run for assemblies as well. 

 

Any help is greatly appreciated.

 

TIA

 

 

0 Likes
Reply
Accepted solutions (1)
354 Views
2 Replies
Replies (2)

A.Acheson
Mentor
Mentor
Accepted solution

Hi @b.mccarthy 

 

Here is a loop for all reference documents and a filter for just parts. 

 

 

 

 

Sub Main

Dim assyDoc As AssemblyDocument = ThisApplication.ActiveDocument

' Iterate through all Referenced Documents in the assembly.
For Each refDoc As Document In assyDoc.AllReferencedDocuments
   
	Logger.Info("Display Name Before Check: " & refDoc.DisplayName)
    
	' Check if the document is a sheet metal part.
    If refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then 
			
	   partDoc = TryCast(refDoc,PartDocument)
		Logger.Info("Display Name:" & partDoc.DisplayName)
    End If
Next

End Sub

 

 

 

 

 Once you have each document you can start doing something with through  sub routine. You will need to change the iproperties of the part to the API equivalent as the ilogic API version is harder to target each document in a stable way. Also the parameter function will need to be changed  to the API version.

 

'Get the document name to reference iproperty with. 
Dim fileName As String = IO.Path.GetFileName(partDoc.FullFileName)
Volume1 = iProperties.Volume(fileName)

 

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

b.mccarthy
Collaborator
Collaborator

@A.Acheson

 

Sorry for the late response. I think your code will work, but I have not had time to implement it.

Thank you!

0 Likes