Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Set Precision in iLogic

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
GKPByDesign
1045 Views, 3 Replies

Set Precision in iLogic

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
3 REPLIES 3
Message 2 of 4
GKPByDesign
in reply to: GKPByDesign

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
Message 3 of 4

 

		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

Message 4 of 4

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report