Loop through Assembly for iProperties

Loop through Assembly for iProperties

haphanthanhtam.work
Enthusiast Enthusiast
516 Views
4 Replies
Message 1 of 5

Loop through Assembly for iProperties

haphanthanhtam.work
Enthusiast
Enthusiast

Hi
I need to loop through an assembly and get iProperties for each part. The iProperties i need are:

Length
Width
Hight


How can i do this? I can loop through the assembly but im struggling to get all of the properties.

Below is the code for getting the size:

L1 = Measure.ExtentsLength
L2 = Measure.ExtentsWidth
L3 = Measure.ExtentsHeight
'Sort measurements

L4 = MinOfMany(L1,L2,L3)
L6 = MaxOfMany(L1,L2,L3)
L5 = L1 + L2 + L3 - L4 - L6

'Create external custom parameters
iProperties.Value("custom","Length") = Round(L6)
iProperties.Value("custom","Width") = Round(L5)
iProperties.Value("custom","Hight") = Round(L4)

 

Thanks

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

JelteDeJong
Mentor
Mentor
Accepted solution

try this:

Sub Main()

    Dim doc As Document = ThisDoc.Document

    For Each refDoc As Document In doc.AllReferencedDocuments
        If (refDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject) Then Continue For
        SetProperty(refDoc)
    Next

End Sub

Private Sub SetProperty(doc As PartDocument)
    Dim box As Box = doc.ComponentDefinition.RangeBox

    Dim L1 As Double = box.MaxPoint.X - box.MinPoint.X
    Dim L2 As Double = box.MaxPoint.Y - box.MinPoint.Y
    Dim L3 As Double = box.MaxPoint.Z - box.MinPoint.Z
    'Sort measurements

    Dim L4 As Double = {L1, L2, L3}.Min()
    Dim L6 As Double = {L1, L2, L3}.Max()
    Dim L5 As Double = L1 + L2 + L3 - L4 - L6

    SetCustomProperty(doc, "Length", L6)
    SetCustomProperty(doc, "Width", L5)
    SetCustomProperty(doc, "Hight", L4)
End Sub

Public Sub SetCustomProperty(doc As PartDocument, name As String, value As Double)

    Dim propSet As PropertySet = doc.PropertySets.Item("Inventor User Defined Properties")
    Try
        propSet.Item(name).Value = value
    Catch ex As Exception
        propSet.Add(value, name)
    End Try
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

haphanthanhtam.work
Enthusiast
Enthusiast

It's work perfect
Thank you very much !!

0 Likes
Message 4 of 5

haphanthanhtam.work
Enthusiast
Enthusiast

It's work perfect
Thank you very much

0 Likes
Message 5 of 5

sun069099
Enthusiast
Enthusiast

Hi:

請問如果要最大值x第二大值x最小值,我該如何實現呢

0 Likes