iLogic rules to reach Hide others option in multi body solid part

iLogic rules to reach Hide others option in multi body solid part

bhavik4244
Collaborator Collaborator
1,480 Views
9 Replies
Message 1 of 10

iLogic rules to reach Hide others option in multi body solid part

bhavik4244
Collaborator
Collaborator

Hello,

 

I have a multi-body part in which I want to reach at "Hide others" option to Hide other bodies other than selected one.

 

For example: If I right click on Flange body than I have the option to hide others. (See attached snap)

 

is it possible to control that with iLogic? If API code available to reach that object that could be fine.

 

Thanks,

Bhavik


Bhavik Suthar
0 Likes
Accepted solutions (1)
1,481 Views
9 Replies
Replies (9)
Message 2 of 10

JhoelForshav
Mentor
Mentor
Accepted solution

I don't know if you can use "Hide others" specifically, but you could just write a code to set visibility to false for every other body in the part. Something like this maybe?

 

Sub Main
	Dim oBody As SurfaceBody = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Select solid")
	VisibleBody(oBody)
End Sub


Sub VisibleBody(oSelectedSolid As SurfaceBody)
Dim oDoc As PartDocument
oDoc = ThisDoc.Document
For Each oSolid As SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
	If oSolid Is oSelectedSolid
		oSolid.Visible = True
	Else
		oSolid.Visible = False
	End If
Next
End Sub
Message 3 of 10

bhavik4244
Collaborator
Collaborator

Hello,

 

Thanks for the reply. I have modified your rules little bit and want to control with representation.

 

Still, it can run and execute properly. Could you please help me out here.

 

Dim oDoc As PartDocument
oDoc=ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition


Dim oRe As RepresentationsManager
oRe = oCompDef.RepresentationsManager

Dim oRepMgr As DesignViewRepresentation
oRepMgr = oRe.ActiveDesignViewRepresentation

Dim oBody As SurfaceBody
'	MessageBox.Show("Try", "Title")

''step through each solid and 
''set vis based on name and 
''matching true/fase condition
i = 1
For Each SurfaceBody In oCompDef.SurfaceBodies
  oBody = oCompDef.SurfaceBodies.Item(i)
If oRepMgr.Name = "FLANGE" And oBody.Name = "FLANGE"
 oBody.Visible=True
Else If oRepMgr.Name = "SHELL" And oBody.Name = "SHELL"
	oBody.Visible = True
Else If oRepMgr.Name = "PRODUCT FLANGE" And oBody.Name = "PRODUCTFLANGE"
	oBody.Visible=True
Else If  oBody.Visible = False
  End If
i = i +1
Next 
 

 


Bhavik Suthar
0 Likes
Message 4 of 10

Anonymous
Not applicable

Hi Jhoel,

 

I had a very similar problem to solve where i had to hide rest of the bodies except 1 body which i think your code may help me.

But where do you define the solid which you want to see? I am a very beginner in ilogic 😞

 

Regards, Neil

0 Likes
Message 5 of 10

JhoelForshav
Mentor
Mentor

Hi @Anonymous,

How do you want to define the solid that shouldnt be hidden? hardcode the name of the solid or do you want to be able to select it?

0 Likes
Message 6 of 10

Anonymous
Not applicable

Hi @JhoelForshav  ,

 

I have 7 solids in a single part file & Basically I want to keep one solid visible & hide rest of the other 6 solids while i run a rule.

 

Question was how can we define that solid which i want to be keep visible in your script ? 

 

0 Likes
Message 7 of 10

JhoelForshav
Mentor
Mentor

When you run the rule I posted you'll be asked to click the solid that you want to keep visible. If you want to hide all the solids except for one this rule should work just as it is.

Maybe I dont understand the question🤔

Message 8 of 10

Anonymous
Not applicable

@JhoelForshav  basically i also would like to make that selection of that body  also in the code. 

 

Currently we select it the body we want to be visible manually right. so it hides all other bodies?  So if there is some definition of select body also in your code, how do we select the body in the code? what additional script is required? 

0 Likes
Message 9 of 10

JhoelForshav
Mentor
Mentor

Do you want the body that shouldn't be hidden hardcoded like this?

Sub Main()
Dim oDoc As PartDocument
oDoc = ThisDoc.Document
Dim oBodies As SurfaceBodies = oDoc.ComponentDefinition.SurfaceBodies
Dim oVisibleBodyName As String = "Solid1" 'The name of the body you want to keep visible
For Each oSolid As SurfaceBody In oBodies
	If oSolid.Name = oVisibleBodyName
		oSolid.Visible = True
	Else
		oSolid.Visible = False
	End If
Next
End Sub

 

Message 10 of 10

Maxim-CADman77
Advisor
Advisor

Code-line to call "Hide others" command specifically:

 

 

ThisApplication.CommandManager.ControlDefinitions("HideOtherBodiesCtxCmd").Execute()

 

 

PS: Yet I should admit that in Inventor 2022 and 2023 I suffer unpredictable behavior of my iLogic code with this command used if Inventor application window is maximized (supposed API defect).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes