How to set a conditional Rule to match body visibility and component visibility?

How to set a conditional Rule to match body visibility and component visibility?

caroline_ccc
Enthusiast Enthusiast
692 Views
6 Replies
Message 1 of 7

How to set a conditional Rule to match body visibility and component visibility?

caroline_ccc
Enthusiast
Enthusiast

Hello. Hope you all are doing well.

 

I have a question and would appreciate your help. 

 

If i want to set a rule as:

 

If Solid 2x3. Visible = false   Then 

Component.IsActive("Top Section") = False

End If

 

I know the rule won't be something as simple as this. But I think it`s explaining well. 

 

question solid visibility ilogic 2.png

 

 

0 Likes
Accepted solutions (2)
693 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor
Accepted solution

See if this works for you:

Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oMBPart As PartComponentDefinition = oADef.Occurrences.ItemByName("Rectangular Top Section for spikes").Definition
If oMBPart.SurfaceBodies.Item("Solid 2x3").Visible = False Then
	Component.IsActive("Top Section") = False
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

caroline_ccc
Enthusiast
Enthusiast

Thanks for your help. 

 

Here is the message when I run the rule. 

 

"Conversion from string "Solid 2x3" to type 'Integer' is not valid."

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

It must not have liked using its name as its Item().  Usually you can get away with this.

Try it this way instead.  It's a bit longer, but should be more stable.  Working with component names can be tricky, because the system automatically put a colon : and an Integer at the end of each name, by default, so multiple instances of it have different names from each other.

Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oMBPart As PartComponentDefinition = oADef.Occurrences.ItemByName("Rectangular Top Section for spikes").Definition
Dim oBody As SurfaceBody
For Each oSBody As SurfaceBody In oMBPart.SurfaceBodies
'	If oSBody.Name = "Solid 2x3" Then
	If oSBody.Name.Contains("Solid 2x3") Then
		If oSBody.Visible = False Then
			For Each oComp As ComponentOccurrence In oADef.Occurrences
				If oComp.Name.Contains("Top Section") Then
					If oComp.Suppressed = False Then
						oComp.Suppress
					End If
				End If
			Next
		End If
	End If
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 7

caroline_ccc
Enthusiast
Enthusiast
Accepted solution

Thanks again. 

This is showing this error. 

"Variable 'ocomp' hides a variable in an enclosing block."

 

But the first rule works perfectly if we change the "name" of the solid per the "position" of the solid in the list. 

"Solid 2x3"  is the  6th .

 

 

''''''This works '''''

 

	Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oMBPart As PartComponentDefinition = oADef.Occurrences.ItemByName("Rectangular Top Section for spikes").Definition
If oMBPart.SurfaceBodies.Item(6).Visible = False Then
	Component.IsActive("Fiberwall Washer2x3") = False
End If

 

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Good to hear. That last error usually happens when you define a variable in two different levels of the code blocks, but I'm not seeing where I defined the variable "oComp" anywhere other than right where I'm using it.

I usually like to define all variables above/before a loop, then use them or set their values within the loop, but apparently I didn't follow my own rules here. 😒

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

caroline_ccc
Enthusiast
Enthusiast

Probably i had another "oComp" somewhere in my giant rule here I`m creating. That's why.

 

All sorted with a simple condition rule. 

Thanks again! 😁

0 Likes