How can I run though all the componets in an assembly then supress or unsupress?

How can I run though all the componets in an assembly then supress or unsupress?

SMillsYS3X2
Advocate Advocate
358 Views
8 Replies
Message 1 of 9

How can I run though all the componets in an assembly then supress or unsupress?

SMillsYS3X2
Advocate
Advocate

This is some rough code. What I am trying to do is go through the parts of an assembly, then suppress or unsupress it according to it's part name and XYZ coordinates in the assembly it is in. Has anyone done something like this before?

 

Dim Part1 As String
Dim Comp1 As Object

For Each Comp1 In ThisAssembly.Components
	Part1 = Comp1.Item.Name
'	If stringcontains(Part1, "Panels") = True 
'		If part origin is within accepted area (need to write code/math)
'			Component.IsActive(Part1) = True
'		Else
'			Component.IsActive(Part1) = False
'		End If
'	End If 
Next Components

 

I have not yet figured out the exact math to do the commented out section. I am mainly asking about the for→each→next loop actually cycling through all the parts in the assembly.

0 Likes
Accepted solutions (2)
359 Views
8 Replies
Replies (8)
Message 2 of 9

ryan.rittenhouse
Advocate
Advocate

This is the bare bones of cycling through an assembly and toggling the suppression state:

 

'Cycle through each component in the open/active assembly
For Each comp As ComponentOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
	
	' Change this to your own code to determin if they get turned on or not
	If comp.Name.Contains("SUPPRESS") Then 
		comp.Suppress()
		'alternate: Component.IsActive(comp.Name) = False
	Else
		comp.Unsuppress()
		'alternate: Component.IsActive(comp.Name) = True
	End If
	
Next comp

 

 

 

Hope it helps.

If this solved your problem, or answered your question, please click Accept Solution.
Message 3 of 9

SMillsYS3X2
Advocate
Advocate

Thank you I think it does. Use ThisDoc instead of ThisAssembly? What is the difference?

0 Likes
Message 4 of 9

ryan.rittenhouse
Advocate
Advocate

Functionally it will work the same in this instance. ThisDoc is a more generic wrapper that will work in any document type, not just assemblies. ThisAssembly has specific iLogic wrappers that only work in the context of an Assembly object.

If this solved your problem, or answered your question, please click Accept Solution.
0 Likes
Message 5 of 9

Curtis_Waguespack
Consultant
Consultant

Hi @SMillsYS3X2 , 

 

Here is a quick example of how to get and evaluate the coordinates of the components.

 

We start off using the iLogic components collection to get each component, and then strip off the iLogic wrapper that ryan.rittenhouse mentioned, so that we can have access to the Inventor API ComponentOccurrence object.

 

From that we can get the origin coordinates of the component.

 

We then set the IsActive state to be NOT equal to teh equation X > 5 And Z > 5, which is either going to return true or false. You can remove the Not operator to evaluate for the opposite case if needed.

 

Hope that helps,

Curtis

 

For Each iLogicComponent In ThisAssembly.Components
	Dim InventorComponent As ComponentOccurrence = iLogicComponent.Occurrence
	Dim ComponentName As String = InventorComponent.Name

	Dim X As Double = Round(InventorComponent.Transformation.Translation.X, 5)
	Dim Y As Double = Round(InventorComponent.Transformation.Translation.Y, 5)
	Dim Z As Double = Round(InventorComponent.Transformation.Translation.Z, 5)

	Logger.Info(X & ", " & Y & ", " & Z)

	If ComponentName.Contains("Panels") = True
		Component.IsActive(ComponentName) = Not (X > 5 And Z > 5)
	End If
Next 

 

EESignature

Message 6 of 9

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@SMillsYS3X2, here is another example that is checking to see if the components are fully within a "bounding box".

 

In this example image there is a blue box just for visual representation ( not created by the code) and the cabinet on the right will be suppressed because some part of it is outside the bounding box.

 

Hope that helps,

Curtis  

 

Curtis_Waguespack_0-1741708057185.png

 

' Create min and max points to define the bounding box
Dim MinPt As Point = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)
Dim MaxPt As Point = ThisApplication.TransientGeometry.CreatePoint(80, 80, 80)

For Each iLogicComponent In ThisAssembly.Components
	Dim InventorComponent As ComponentOccurrence = iLogicComponent.Occurrence
	Dim ComponentName As String = InventorComponent.Name
	'unsuppress component to get range box
	Component.IsActive(ComponentName) = True

	Dim MaxX As Double = InventorComponent.PreciseRangeBox.MaxPoint.X
	Dim MaxY As Double = InventorComponent.PreciseRangeBox.MaxPoint.Y
	Dim MaxZ As Double = InventorComponent.PreciseRangeBox.MaxPoint.Z
	Dim MinX As Double = InventorComponent.PreciseRangeBox.MinPoint.X
	Dim MinY As Double = InventorComponent.PreciseRangeBox.MinPoint.Y
	Dim MinZ As Double = InventorComponent.PreciseRangeBox.MinPoint.Z

	Dim Exceed_Check(5) As Boolean
	Exceed_Check(0) = MinX < MinPt.X
	Exceed_Check(1) = MinY < MinPt.Y
	Exceed_Check(2) = MinZ < MinPt.Z
	Exceed_Check(3) = MaxX > MaxPt.X
	Exceed_Check(4) = MaxY > MaxPt.Y
	Exceed_Check(5) = MaxZ > MaxPt.Z

	IsOutOfBox = False
	For i = 0 To 5
		If Exceed_Check(i) = True Then
			IsOutOfBox = True
			Exit For
		End If
	Next

	If ComponentName.Contains("BASE") = True
		Component.IsActive(ComponentName) = Not IsOutOfBox
	End If
Next 

 

EESignature

Message 7 of 9

SMillsYS3X2
Advocate
Advocate

The second is a bit more than I was looking for, thank you! Let go test these.

0 Likes
Message 8 of 9

SMillsYS3X2
Advocate
Advocate

Follow up questions.

 

The measurements are in centimeters?

 

How is the "Bounding box" / PreciseRangeBox defined by the user? It's another part in the assembly?

-I'm not sure if it will work for what I need to do, the bounding box I need to define is a trapezoid , not a cube or rectangle. Two faces of this bounding box are not at right angles "∟" to others.

 

Is it possible to get XYZ coordinates from a work point in the model? I try to capture current state in iLogic and I don't see anything.

0 Likes
Message 9 of 9

Stakin
Collaborator
Collaborator
Accepted solution

Use Box.contain can simple the code.

' Create min and max points to define the bounding box
Dim MinPt As Point = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)
Dim MaxPt As Point = ThisApplication.TransientGeometry.CreatePoint(80, 80, 80)
Dim oBaseBox As Box
oBaseBox = ThisApplication.TransientGeometry.CreateBox()
oBaseBox.Extend(MinPt)
oBaseBox.Extend(MaxPt)
For Each iLogicComponent In ThisAssembly.Components
	Dim InventorComponent As ComponentOccurrence = iLogicComponent.Occurrence
	Dim ComponentName As String = InventorComponent.Name
	Component.IsActive(ComponentName) = True
	MaxPt = InventorComponent.PreciseRangeBox.MaxPoint
	MinPt = InventorComponent.PreciseRangeBox.MinPoint
	If oBaseBox.Contains(MinPt) And oBaseBox.Contains(MaxPt) Then
		IsOutOfBox = False
	Else
		IsOutOfBox = True
	End If
	If ComponentName.Contains("BASE") = True
		Component.IsActive(ComponentName) = Not IsOutOfBox
	End If
Next