Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Set Precision in iLogic

GKPByDesign
Advocate Advocate
1,248 Views
3 Replies
Message 1 of 4

Set Precision in iLogic

GKPByDesign
Advocate
Advocate

I have a code below,

 

however the ending iProperties need to be set to precision 0, and no units, leading or trailing zeros, however I believe I may need to interject a custom parameters first, and let the iProp equal these.

 

Let 

Run code to get L W T

 

L= Custom Para L

W= Custom Para W

T= Custom Para T

 

Set Precision on Custom Para L W T

 

Custom iProp Length = Custom Para L

Custom iProp Width = Custom Para W

Custom iProp Thickness = Custom Para T

 

Imports system.Collections
Public Sub Main() 
    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument 

    ' Get the assembly component definition. 
    Dim oAsmDef As AssemblyComponentDefinition 
    oAsmDef = oAsmDoc.ComponentDefinition 

    ' Get all of the leaf occurrences of the assembly. 
    Dim oLeafOccs As ComponentOccurrencesEnumerator 
    oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences 


    ' Iterate through all part occurrences in assembly. 
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In oLeafOccs 
		L = Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10
		W = Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10
		H = Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10
		 
		Dim oList As New ArrayList 
		oList.Add(L)
		oList.Add(W)
		oList.Add(H)
		 
		Call oList.Sort()
		
		iProperties.Value(oOcc.Name,"Custom", "Length") =  oList.Item(2)& " mm"
		iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)& " mm"
		iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0) & " mm"

		  Next 
End Sub
0 Likes
Accepted solutions (1)
1,249 Views
3 Replies
Replies (3)
Message 2 of 4

GKPByDesign
Advocate
Advocate

I have found the code that code be used, but have no ideas how to implement 

 

DimoPartDocAsPartDocument
 oPartDoc=ThisApplication.ActiveDocument
 DimoParameterAsParameter
 DimoFormatAsCustomPropertyFormat 
 ForEachoParameterInoPartDoc.ComponentDefinition.Parameters.UserParameters 
 oFormat=oParameter.CustomPropertyFormat 
 oParameter.ExposedAsProperty=True

 oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
 oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacesPrecision
 oFormat.Units="mm"
 oFormat.ShowUnitsString= False
 oFormat.ShowLeadingZeros= False
 oFormat.ShowTrailingZeros=False
NextoParameter
0 Likes
Message 3 of 4

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

 

		iProperties.Value(oOcc.Name,"Custom", "Length") =  Round(oList.Item(2),0)& " mm"
		iProperties.Value(oOcc.Name,"Custom", "Width") = Round(oList.Item(1),0)& " mm"
		iProperties.Value(oOcc.Name, "Custom", "Thickness") = Round(oList.Item(0),1) & " mm"

Hi, try changing the last lines.
I hope this helps. regards 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 4 of 4

GKPByDesign
Advocate
Advocate

Any body wants a cutting list that you can run from a component file created from a multi body part, code below! You can also create a cutting list from it too! 

 

Imports system.Collections
Public Sub Main() 
    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument 

    ' Get the assembly component definition. 
    Dim oAsmDef As AssemblyComponentDefinition 
    oAsmDef = oAsmDoc.ComponentDefinition 

    ' Get all of the leaf occurrences of the assembly. 
    Dim oLeafOccs As ComponentOccurrencesEnumerator 
    oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences 


    ' Iterate through all part occurrences in assembly. 
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In oLeafOccs 
		L = Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10
		W = Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10
		H = Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10
		 
		Dim oList As New ArrayList 
		oList.Add(L)
		oList.Add(W)
		oList.Add(H)
		 
		Call oList.Sort()
		
		iProperties.Value(oOcc.Name,"Custom", "Length") =  Round(oList.Item(2),0)& " mm"
		iProperties.Value(oOcc.Name,"Custom", "Width") = Round(oList.Item(1),0)& " mm"
		iProperties.Value(oOcc.Name, "Custom", "Thickness") = Round(oList.Item(0),1) & " mm"

		  Next 
End Sub