XY, YZ, XZ automatic display

XY, YZ, XZ automatic display

kaomar23
Contributor Contributor
967 Views
10 Replies
Message 1 of 11

XY, YZ, XZ automatic display

kaomar23
Contributor
Contributor
 

hello 

i want to know if i can display the plans (xy, yz and xz) of a part or sub assembly when the part is placed into the assembly so it would be easier to make constraints  using the main plans  of the part or subbassemly without going to the browser and turn the display from there so it  time saving 

or creating a rule to make the display automatic on, once brought into the assembly

thanks in advance

0 Likes
Accepted solutions (1)
968 Views
10 Replies
Replies (10)
Message 2 of 11

A.Acheson
Mentor
Mentor

As discussed on the Inventor Forum here. Select the part in either the browser or the model window and add as many parts as you need, press esc and the workplane will be switched on, repeat the workflow for off. This isn't an automatic rule but it is semi automatic. Much faster than manual method.  Use the rule as an external rule

Rule sourced from here

 

While True
Dim comp As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a component") 'Change filter as needed'.kAssemblyOccurrenceFilter
If IsNothing(comp) Then Exit While
comps.Add(comp) 
End While

For Each comp In comps
	Dim WP As WorkPlane = comp.definition.document.ComponentDefinition.WorkPlanes.Item(1)
	Dim oValue As Boolean
	If WP.Visible = True Then oValue = False Else oValue = True
	
	For i As Integer = 1 To 3
		comp.definition.document.ComponentDefinition.WorkPlanes.Item(i).Visible = oValue
	Next
	iLogicVb.UpdateWhenDone = True
Next

  

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 11

kaomar23
Contributor
Contributor

thanks for your answer and for the code, but unfortunatly when i tried to save the code to run it in inventor it says 

: error in line 04

  

comps.Add(comp) 

comp not defined or declared

how could i fix it

thanks  

0 Likes
Message 4 of 11

A.Acheson
Mentor
Mentor

Appoligies it was a copy paste error. This line was missing.

Dim comps As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

Working Rule

Dim comps As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

While True
Dim comp As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a component") 
If IsNothing(comp) Then Exit While
comps.Add(comp) 
End While

For Each comp In comps
	Dim WP As WorkPlane = comp.definition.document.ComponentDefinition.WorkPlanes.Item(1)
	Dim oValue As Boolean
	If WP.Visible = True Then oValue = False Else oValue = True
	
	For i As Integer = 1 To 3
		comp.definition.document.ComponentDefinition.WorkPlanes.Item(i).Visible = oValue
	Next
	iLogicVb.UpdateWhenDone = True
Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 11

kaomar23
Contributor
Contributor

thanks again 

but sorry to tell you, i still have an error message

i'm using inventor 2021.3.2 

 

0 Likes
Message 6 of 11

A.Acheson
Mentor
Mentor

We’re you able to have it work on any parts your end? Can you step by step tell us how it failed when operated last add Lao the more info dialogue of the error message bay offer more information. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 11

kaomar23
Contributor
Contributor

hello,

i create the assembly, place the first part grounded and brougth the other parts, then i run the rule, so i can select the component i want , but nothing hapened and i went on selecting parts but still nothing so i hit the esc key, and the error message show up

thanks again

0 Likes
Message 8 of 11

kaomar23
Contributor
Contributor

more info in the message error

0 Likes
Message 9 of 11

A.Acheson
Mentor
Mentor
Accepted solution

Ok try it on a part that is not read only . Select part and press esc this cancels the loop and allows to work on the part selected. It is possible read only parts were selected . I selected a read only part below and it errored out

AAcheson_0-1630949022802.png

 

 

To get around the read only file error you can place an On error resume next which will move on to the next file if an error occurs. It would be better to check the status of the file if read only or not but this can be difficult to achieve.

Dim comps As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

While True
Dim comp As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a component") 
If IsNothing(comp) Then Exit While
comps.Add(comp) 
End While

On Error Resume Next
For Each comp In comps
	
	Dim WP As WorkPlane = comp.definition.document.ComponentDefinition.WorkPlanes.Item(1)
	Dim oValue As Boolean
	If WP.Visible = True Then oValue = False Else oValue = True
	
	For i As Integer = 1 To 3
		comp.definition.document.ComponentDefinition.WorkPlanes.Item(i).Visible = oValue
	Next
	iLogicVb.UpdateWhenDone = True
Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 10 of 11

kaomar23
Contributor
Contributor

thanks very much 

now it's working

0 Likes
Message 11 of 11

kaomar23
Contributor
Contributor

just additionnal thing if its possible 

could you make the rule automatically run and i can shut it off once finished

many thanks

0 Likes