Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic: control the visibility of one body

Anonymous

iLogic: control the visibility of one body

Anonymous
Not applicable

If I were to control the visibility of one body, how would I write the code for that

It's a yes or no function I'm looking for

 

 

Parameter (Parameter name: Sliderail)

  Yes

  No

 

Bodyname

  Sliderail, round

0 Likes
Reply
Accepted solutions (2)
653 Views
7 Replies
Replies (7)

dgreatice
Collaborator
Collaborator

Hi,

 

try this:

 

Version:1.0 StartHTML:00000145 EndHTML:00002241 StartFragment:00000294 EndFragment:00002209 StartSelection:00000294 EndSelection:00000294SyntaxEditor Code Snippet

Dim oApp As Application
Dim oPD As PartDocument
Dim oPCD As PartComponentDefinition
Dim oSurfBody As SurfaceBody

oApp = ThisApplication
oPD = oApp.ActiveDocument
oPCD = oPD.ComponentDefinition

For Each oSurfBody In oPCD.SurfaceBodies
    If oSurfBody.Name = "Sliderail" Then
        oSurfBody.Visible = False
    End If
Next

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes

Anonymous
Not applicable

The parameter will be a "text" parameter with yes or no. Will this affect the code?

0 Likes

dgreatice
Collaborator
Collaborator
Accepted solution

You can add more condition

 

Dim oApp As Application
Dim oPD As PartDocument
Dim oPCD As PartComponentDefinition
Dim oSurfBody As SurfaceBody

oApp = ThisApplication
oPD = oApp.ActiveDocument
oPCD = oPD.ComponentDefinition

For Each oSurfBody In oPCD.SurfaceBodies
    If oSurfBody.Name = "Sliderail" Then
        if Sliderail = "Yes" then
oSurfBody.Visible = True
else
oSurfBody.Visible = False
end if
End If Next
Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014

Anonymous
Not applicable

What if you have the paramter options and 2 bodies?

 

Parameter (Parameter name: Sliderail)

  No   (...None of the 2 bodies are vissible)

  Round   (Sliderail, round is visible)

  Square   (Sliderail, Square is visible)

 

Bodynames

  Sliderail, round

  Sliderail, square

0 Likes

dgreatice
Collaborator
Collaborator
Accepted solution

 

Dim oApp As Application

Dim oPD As PartDocument

Dim oPCD As PartComponentDefinition

Dim oSurfBody As SurfaceBody

 

oApp = ThisApplication

oPD = oApp.ActiveDocument

oPCD = oPD.ComponentDefinition

 

For Each oSurfBody In oPCD.SurfaceBodies

if Sliderail = "No" then

if oSurfBody.Name = "Sliderail, round" or oSurfBody.Name = "Sliderail, Square" then

oSurfBody.Visible = False

else

osurfbody.visible = true
End if

ElseIf Sliderail = "Round" Then

If oSurfBody.Name = "Round" Then

oSurfBody.Visible = True

else

oSurfBody.Visible = False

end if

ElseIf Sliderail = "Square" Then
If oSurfBody.Name = "Square" Then

oSurfBody.Visible = True

else

oSurfBody.Visible = False

End if

End if

Next

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014

Anonymous
Not applicable

Awesome. Thank You!

 

 

What if I had 3 extra bodies that should be visible at all times. How would that affect the code

 

Lets just call them

body1

body2

body3

0 Likes

dgreatice
Collaborator
Collaborator

you can try, let me know if there are error.

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes