Component.Visible (iam)

Component.Visible (iam)

marcin_bargiel
Advocate Advocate
1,557 Views
20 Replies
Message 1 of 21

Component.Visible (iam)

marcin_bargiel
Advocate
Advocate

i got subassembly  abc.iam which has three parts :  a:1, b:1, c:1 (one or two of them are always hidden)

 

when first time i put it to main assembly ---> main.iam,  some part are visible other are hidden - that GREAT !

but then when i need to  set on demand :  visible or not  - abc:1 using below function - all parts are set as visible !

 

SyntaxEditor Code Snippet

Component.Visible("abc:1")=True 
Component.Visible("abc:1")=False

and now a big question : why this function set visibility to all of my parts in "abc:1" not just to only ones which has set visibility   !????

it is at least not understandable behavior ...

 

i don't want to set visibility or hidden of all parts separately one more time in main.iam !

 

 

 

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Accepted solutions (1)
1,558 Views
20 Replies
Replies (20)
Message 2 of 21

Mark.Lancaster
Consultant
Consultant

@marcin_bargiel

 

Programming needs, questions, and issues should be posted in the Inventor Customization Forum for best results.

 

https://forums.autodesk.com/t5/inventor-customization/bd-p/120

 

I will have the moderator relocate your posting to best suit your needs.

 

Update:  Also when sharing files its important to indicate which version of Inventor you're using..  In your case its Inventor 2019.2

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes
Message 3 of 21

mcgyvr
Consultant
Consultant

I think you should be activating specific design view representations of that subassembly instead of controlling its visibility. Or also setting the appropriate design view rep if you need to use the visibility toggle.

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 4 of 21

clutsa
Collaborator
Collaborator

You have a few things going on here...

The main thing is "abc:1" is the whole sub-assembly so if visible = false all three parts go.

If choose=True Then
Component.Visible("abc:1") = True 
End If

If choose=False Then
Component.Visible("abc:1") = False
End If

All the parts are coming back visible because it's changing from Representation"Default" to "Main" (Main will always have all parts visible)

Are you looking to change "Choose" and have only part "b" come and go?

Add your choose parameter to the acb.iam and add this rule

Dim CompB = Component.InventorComponent("b:1")
If Choose = True Then 
	CompB.Visible = True
Else
	CompB.Visible = False
End IF

Then in main.iam you run this rule instead...

If choose=True Then
	Parameter("abc:1", "Choose") = True
Else
	Parameter("abc:1", "Choose") = False
End If

InventorVb.DocumentUpdate()

And your representation of abc.iam in main.iam needs to be set to default and associative.

I'll try to add some more info tomorrow but that should get you going.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 21

marcin_bargiel
Advocate
Advocate

Actually You are wrong 🙂

My assembly do not have known configuration - it's is always different, i need to choose it by Form.

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 6 of 21

marcin_bargiel
Advocate
Advocate

What am i doing now ?

in sub-assembly i use these :

SyntaxEditor Code Snippet

Component.Visible("a:1")=1
Component.Visible("b:1")=0
Component.Visible("c:1")=1

etc.

And in MAIN ASSEMBLY I HAVE TO do it the same ! (if i want to have the same state of visibility).

This commend shoud not change visibility of  all parts in sub-assembly !

Component.Visible("abc:1")=1

 

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 7 of 21

clutsa
Collaborator
Collaborator

1. add a text parameter to main.iam called "HideThis" and make it a multivalue list with all your parts (a, b, c, none)

2. rule code for main.iam

Parameter("abc:1", "hidePart") = HideThis
InventorVb.DocumentUpdate()

3. add a text parameter to abc.iam called "hidePart"

4. rule code for abc.iam

Dim doc As AssemblyDocument = ThisDoc.Document
For Each comp In doc.ComponentDefinition.Occurrences
 comp.excluded = False
Next
If hidePart <> "none" Then 
 Dim hiddenPart = Component.InventorComponent(hidePart & ":1")
 hiddenPart.Excluded = True
End If

5. change "HideThis" in main.iam and watch it work!

 

I'd give you a screencast but your files are 2019 so I had to open your files in 2020beta and I'm not aloud to screencast that. Smiley Sad

I made a video a while back that might help. I was going to redo it into a couple videos with more data on the drawing side but it will work for now.

 

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 8 of 21

marcin_bargiel
Advocate
Advocate

i did as You said, but do not work 😕

 

thank's anyway !

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 9 of 21

clutsa
Collaborator
Collaborator

Is it throwing an error? What's not working right?

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 10 of 21

marcin_bargiel
Advocate
Advocate

i don't have an error.

But it do not work as i wanted.

 

one more time, i want to set visibility of parts in abc.iam by FORM.

 

in main.iam i want to choose only two option - visibility or not of that subassembly abc.iam

 

hide subassembly is easy.  but when i set visibilty of abc.iam from main.iam - inventor always set all components visibile no metter that some of them are set as hidden in subassembly abc.iam.

 

moreover in need to set BOM structure accordingly - default or reference

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 11 of 21

clutsa
Collaborator
Collaborator

I replicated your part to Inv2018 (see attached). I've also included a screen cast.

 

 

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 12 of 21

clutsa
Collaborator
Collaborator

try this code in acb.iam to correct BOM issues...

Dim doc As AssemblyDocument = ThisDoc.Document
Dim comp As ComponentOccurrence
For Each comp In doc.ComponentDefinition.Occurrences
 comp.excluded = False
 comp.visible = True
 comp.bomstructure = BOMStructureEnum.kDefaultBOMStructure
Next
If hidePart <> "none" Then 
 Dim hiddenPart = Component.InventorComponent(hidePart & ":1")
 hiddenPart.Visible = False
 hiddenPart.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
 hiddenPart.Excluded = True
End If
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 13 of 21

marcin_bargiel
Advocate
Advocate

thank's a lot, works almost perfectly !

 

why almost?

what if i'd like to hidden two of them or every components ? now i can hidden only one, or NONE.

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 14 of 21

clutsa
Collaborator
Collaborator

Well... you can make a true/false drop down for each part... or you can pass a string that lists all the parts you want to hide and loop through that... you could have option 'ab', 'bc', 'ac', and 'all' to the drop down and run a "select case" statement to do different hides based on the case. 

I can't tell you exactly what to do because I don't know your exact use case. Will you only ever have three parts? The "right" way to do it depends on how many parts and combinations you will ever need. 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 15 of 21

marcin_bargiel
Advocate
Advocate

SyntaxEditor Code Snippet


Dim
doc As AssemblyDocument = ThisDoc.Document Dim comp As ComponentOccurrence For Each comp In doc.ComponentDefinition.Occurrences comp.Excluded = False comp.Visible = True comp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure Next If hidePart <> "none" And hidePart <> "all" Then 'none visible Dim hiddenPart = Component.InventorComponent(hidePart & ":1") hiddenPart.Visible = False hiddenPart.BOMStructure = BOMStructureEnum.kReferenceBOMStructure hiddenPart.Excluded = True End If If hidePart = "all" Then 'all hidden For Each comp In doc.ComponentDefinition.Occurrences comp.Excluded = True comp.Visible = False comp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Next End If

 

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 16 of 21

marcin_bargiel
Advocate
Advocate

i have many combinations ! depends on what i choose in FORM

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 17 of 21

clutsa
Collaborator
Collaborator

If the componentOccurence is excluded "visible" and "BOMStructure" won't work so you have to change those and then exclude or unexclude and then change them.

 

Dim doc As AssemblyDocument = ThisDoc.Document
Dim comp As ComponentOccurrence
For Each comp In doc.ComponentDefinition.Occurrences
 comp.Excluded = False
 comp.Visible = True
 comp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
Next

If hidePart <> "none" And hidePart <> "all" Then 'none visible
 Dim hiddenPart = Component.InventorComponent(hidePart & ":1")
 hiddenPart.Visible = False
 hiddenPart.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
 hiddenPart.Excluded = True
End If

If hidePart = "all" Then 'all hidden
For Each comp In doc.ComponentDefinition.Occurrences
 comp.Visible = False
 comp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
comp.Excluded = True 'move this to here
Next
End If

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 18 of 21

clutsa
Collaborator
Collaborator

 

Here's a sample of ways to tackle this... For me personally I find that I have a groups of parts that need to be switched out. I will always want one part from the group but only one art from each group... below are some ways to code for different groups of parts.

 

hidePart = "none"' deleted parameter

Dim doc As AssemblyDocument = ThisDoc.Document
Dim comp As ComponentOccurrence
For Each comp In doc.ComponentDefinition.Occurrences
 comp.visible = False
 comp.bomstructure = BOMStructureEnum.kReferenceBOMStructure
 comp.excluded = True
Next

Dim a1 = Component.InventorComponent("a1")
Dim a2 = Component.InventorComponent("a2")
Dim a3 = Component.InventorComponent("a3")
Dim b1 = Component.InventorComponent("b1")
Dim b2 = Component.InventorComponent("b2")
Dim b3 = Component.InventorComponent("b3")
Dim c1 = Component.InventorComponent("c1")
Dim c2 = Component.InventorComponent("c2")
Dim c3 = Component.InventorComponent("c3")
Dim aGroup As New ArrayList
aGroup.Add(a1)
aGroup.Add(a2)
aGroup.Add(a3)
Dim bGroup As New ArrayList
bGroup.Add(b1)
bGroup.Add(b2)
bGroup.Add(b3)
Dim cGroup As New ArrayList
'cGroup.Add(c1)
'cGroup.Add(c2)
'cGroup.Add(c3)

'You can do something like this
Dim finalA
Select Case SelectedA
Case = "a1"
	finalA = a1
Case = "a2"
	finalA = a2
Case = "a3"
	finalA = a3
End Select
If Not finalA Is Nothing Then
	finalA.Excluded = False
	finalA.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
	finalA.Visible = True
End If

'or something like this
For Each memberB In bGroup
	If memberB.Name Like "*" & SelectedB & "*" Then 'I added the LCase() because the 'like' feature is case sensitive and I didn't match 
		memberB.Excluded = False
		memberB.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
		memberB.Visible = True
	End If
Next
	
'or another option for doing combinations of parts
If SelectedC Like "*1*" Then cGroup.Add(c1)
If SelectedC Like "*2*" Then cGroup.Add(c2)
If SelectedC Like "*3*" Then cGroup.Add(c3)
For Each memberC In cGroup
		memberC.Excluded = False
		memberC.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
		memberC.Visible = True
Next

and one last video to help you implement it 

 

Screencast will be displayed here after you click Post.

c227aba8-d5d2-4bfb-80d7-533a5871d9ca

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 19 of 21

marcin_bargiel
Advocate
Advocate

I attached sample part.

I'd like to hide all parts when parameter n_baffles <=1.  Below code works when n_baffles >1 but i got an error when n_baffles =1 , why ???  i use pattern, is this cause that problem?

 

SyntaxEditor Code Snippet

InventorVb.DocumentUpdate()
Dim doc As AssemblyDocument = ThisDoc.Document
Dim comp As ComponentOccurrence

If n_baffles > 1 Then 
	
For Each comp In doc.ComponentDefinition.Occurrences
 comp.Excluded = False
 comp.Visible = True
 comp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
Next

Else
	
For Each comp In doc.ComponentDefinition.Occurrences
 comp.Visible = False
 comp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
 comp.Excluded = True 
 Next
 
End If

 

 

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 20 of 21

clutsa
Collaborator
Collaborator
Accepted solution

Sorry been out on holidays. Couple of things that were going wrong.

1. your code needs to be "if n_baffles >= 1 then" or if n_baffles > 0 then".  Your description of your problem had your answer right in it. 

2. when you have zero n_baffles your pattern fails because d17 = "360 / n_baffles" or "360/0" not good. This "360 deg / abs(n_baffles + ( 1 ul - sign(n_baffles) ))" will ensure that d17 always = 1 or more

3. Here is a list of all the components in your assembly...

_Weldbead:1    <-----this guy won't let you change his BOMStructure to reference
baffle:1
support:1
repad:1
support:2
repad:2
ISO 4017 - M20 x 40 - ISO:1
ISO 4032 - M20 - ISO:1
ISO 4032 - M20 - ISO:2
ISO 7089 - 20 - 140 HV(1):1
ISO 4017 - M20 x 40 - ISO:2
ISO 4032 - M20 - ISO:3
ISO 4032 - M20 - ISO:4
ISO 7089 - 20 - 140 HV(1):2
ISO 4017 - M20 x 40 - ISO:3
ISO 4032 - M20 - ISO:5
ISO 4032 - M20 - ISO:6
ISO 7089 - 20 - 140 HV(1):3
ISO 4017 - M20 x 40 - ISO:4
ISO 4032 - M20 - ISO:7
ISO 4032 - M20 - ISO:8
ISO 7089 - 20 - 140 HV(1):4

3.1 I had code to skip just that one part but then found that if all the parts in the model are gone the BOM won't update... I assume that other parts come into this in some way because there is no point in having an empty drawing... at any rate my fix was to only look if the part is a pattern member to do the hiding. 

In the end my code looks like this...

'InventorVb.DocumentUpdate() 'moved to bottom

Dim doc As AssemblyDocument = ThisDoc.Document
Dim comp As ComponentOccurrence

If n_baffles >0 Then 
	For Each comp In doc.ComponentDefinition.Occurrences
		comp.Excluded = False
		comp.Visible = True
		comp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
	Next
Else
	For Each comp In doc.ComponentDefinition.Occurrences
		If comp.IsPatternElement Then
			comp.Visible = False
			comp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
			comp.Excluded = True
		End If
	Next
End If
InventorVb.DocumentUpdate()

don't forget to fix d17 too.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates