ilogic automatically turn part visibility off

ilogic automatically turn part visibility off

Anonymous
Not applicable
1,268 Views
3 Replies
Message 1 of 4

ilogic automatically turn part visibility off

Anonymous
Not applicable

Hi I am playing around with ilogic to help automate some designs. I have been trying to write a bit of code which when an assembly is resized any components which are not being used will have the visibility turned off. I then already have a piece of code from searching the forums which will delete the unused parts. I basically want a bit of code which will filter down through the assembly, and any parts with a weight of  '0' will get the visibility turned off. So far i have this....

 

SyntaxEditor Code Snippet

Dim openDoc As Document
Dim assemblyDoc As AssemblyDocument
Dim assemblyDef As AssemblyComponentDefinition
Dim obj As Object

    
If TypeOf obj Is ComponentOccurrence Then
Dim occ As ComponentOccurrence
End If
openDoc = ThisDoc.Document

imass = iProperties.Value("Custom", "WEIGHT")

For Each occ In openDoc.AllReferencedDocuments

If iProperties.Value(occ, "Custom", "WEIGHT") = 0 Then
occ.Visibility = Not occ.Visibility
End If
Next

 

...but cant get any further. Would anyone be able to help me please?

 

Cheers

 

Luke

0 Likes
Accepted solutions (1)
1,269 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Sorry just deleted the bits in the iLogic that wernt being used. 

SyntaxEditor Code Snippet

Dim openDoc As Document
Dim assemblyDoc As AssemblyDocument
Dim assemblyDef As AssemblyComponentDefinition
    
If TypeOf obj Is ComponentOccurrence Then
Dim occ As ComponentOccurrence

openDoc = ThisDoc.Document
imass = iProperties.Value("Custom", "WEIGHT")
Weight = occ.imass

For Each occ In openDoc.AllReferencedDocuments

If Weight = 0 Then
occ.Visibility = Not occ.Visibility
End If
Next
End If



iLogicVb.UpdateWhenDone = True

 

 

 

0 Likes
Message 3 of 4

ekinsb
Alumni
Alumni
Accepted solution

If I followed what your trying to do, I think the rule below might do what you need.  It will change the visibility of all occurrences in the assembly based on if the user defined property "WEIGHT" exists or not and if it's value is 0.

 

Dim assemblyDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition

Dim occ As Inventor.ComponentOccurrence
For Each occ In assemblyDef.Occurrences.AllLeafOccurrences
    Dim refDoc As PartDocument = occ.Definition.Document
    
    Dim customPropSet As PropertySet
    customPropSet = refDoc.PropertySets.Item("Inventor User Defined Properties")

	Dim weightProp As Inventor.Property
	weightProp = Nothing
	Try
		weightProp = customPropSet.Item("WEIGHT")
    Catch ex As Exception
	End Try		
    
    If Not weightProp Is Nothing Then
        Dim weightVal As Double
        weightVal = weightProp.Value
        
        If weightVal < 0.00000001 Then
            occ.Visible = False
        Else
            occ.Visible = True
        End If
    End If
Next

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 4 of 4

Anonymous
Not applicable

Your a star thank you! Been plying with code trying to get it to work. I'm learning the VB on the go which makes things a little harder.

 

Thanks again!

0 Likes