' **************************** START OF iLOGIC CODE ********************************************** 'This iLogic code is from Cadline Community – it allows user to cycle through all part features, renaming as required 'https://www.cadlinecommunity.co.uk/hc/en-us/articles/202020121-Autodesk-Inventor-2014-iLogic-Feature-Player-and-Rename-Tool Doc = ThisDoc.Document If Doc.DocumentType = kAssemblyDocumentObject OrElse Doc.DocumentType = _ kDrawingDocumentObject Then MessageBox.Show("This rule can only be run in a part file!", "Cadline iLogic", _ MessageBoxButtons.Ok,MessageBoxIcon.Exclamation, _ MessageBoxDefaultButton.Button1) Return End If 'Define stuff Dim oDef As ComponentDefinition = Doc.ComponentDefinition Dim oFeature As PartFeature Dim oFeatures As PartFeatures = oDef.Features 'Define height of camera away from origin Dim HeightMultiplier As Double = 4 'Define distance of rotation away from origin Dim DistMultiplier As Double = 4 'Define the number of steps for later in the animation. Dim steps As Integer = 200 'Get the active camera. Dim cam As Camera = ThisApplication.ActiveView.Camera 'Define transient geometry Dim tg As TransientGeometry = ThisApplication.TransientGeometry 'Define eye position (height on users selected axis of choice) Dim eyeDistance As Double 'Calculate pi. Dim PI As Double = Atan(1) * 4'Make all surface bodies visible (for playback) Dim oWorkSurfaces As WorkSurfaces = oDef.WorkSurfaces Dim oWorkSurface As WorkSurface Dim oSurfaces As SurfaceBodies = oDef.SurfaceBodies Dim oSurface As SurfaceBody Dim oParams As Parameters = oDef.Parameters 'Turn on surface bodies (so they can be seen in player) For Each oWorkSurface In oWorkSurfaces For aa = 1 To oWorkSurface.SurfaceBodies.Count oWorkSurface.SurfaceBodies.Item(aa).Visible = "True" Next Next 'Now turn on main solid body (or bodies) For Each oSurface In oSurfaces oSurface.Visible = "True" Next 'Variable for the player count position.. Dim Player_Count As Double = 1 'Count Features Feat_Count = oFeatures.Count Question1: 'Request input from user for axis to be rotated around Dim Choices As New ArrayList Choices.Add("X") Choices.Add("Y") Choices.Add("Z") RotationChoice = InputListBox("First please select the 'Up' direction axis for this part", _ Choices, "Eh?", Title := "Cadline Feature Player", ListName := "Axes") If RotationChoice = "" Then USure = MessageBox.Show("Please select an 'up' axis for the player!", "Cadline iLogic", _ MessageBoxButtons.OKCancel,MessageBoxIcon.Information) If USure = 2 Then Return Else Goto Question1 End If End If 'Get range box for whole part (to be used to calculate eye height only) Dim oPartBox As Box = oDef.RangeBox 'Define size of whole part in each direction Xrange = (oPartBox.MaxPoint.X-oPartBox.MinPoint.X) Yrange = (oPartBox.MaxPoint.Y-oPartBox.MinPoint.Y) Zrange = (oPartBox.MaxPoint.Z-oPartBox.MinPoint.Z) 'Set part to first feature Try oFeatures.Item(1).SetEndOfPart(False) 'Highlight feature Feature.Color(oFeatures.Item(1).Name) = "Red" Catch End Try 'Get range box for first feature (used to calculate eye height and eye distance) Dim oBox As Box = oFeatures.Item(1).RangeBox 'Define size of feature in each direction Xrange = (oBox.MaxPoint.X-oBox.MinPoint.X) Yrange = (oBox.MaxPoint.Y-oBox.MinPoint.Y) Zrange = (oBox.MaxPoint.Z-oBox.MinPoint.Z) 'Set the initial view position ------------------ ' Calculate the x and y coordinates of the eye. Dim z As Double Dim x As Double Dim y As Double Try For bb = 1 To 2 Select Case RotationChoice Case "X" eyeDistance = DistMultiplier*(Max(Yrange,Zrange)) x = oPartBox.MaxPoint.X*HeightMultiplier y = eyeDistance * Cos((26) / (steps) * (2 * PI)) z = eyeDistance * Sin((26) / (steps) * (2 * PI)) 'Define the distance between the eye and target. cam.UpVector = tg.CreateUnitVector(1, 0, 0) Case "Y" eyeDistance = DistMultiplier*(Max(Xrange,Zrange)) x = eyeDistance * Sin((26) / (steps) * (2 * PI)) y = oPartBox.MaxPoint.Y*HeightMultiplier z = eyeDistance * Cos((26) / (steps) * (2 * PI)) cam.UpVector = tg.CreateUnitVector(0, 1, 0) Case "Z" eyeDistance = DistMultiplier*(Max(Xrange,Yrange)) x = eyeDistance * Cos((26) / (steps) * (2 * PI)) y = eyeDistance * Sin((26) / (steps) * (2 * PI)) z = oPartBox.MaxPoint.Z*HeightMultiplier cam.UpVector = tg.CreateUnitVector(0, 0, 1) End Select cam.Eye = tg.CreatePoint(x, y, z) cam.Apply cam.Fit ThisApplication.ActiveView.Update() InventorVb.DocumentUpdate() Next bb Catch MessageBox.Show("Error 2 - please check iLogic code", "Cadline Feature Player") End Try 'Give user some initial information MsgBox("Instructions:" & vbLf & vbLf & _ "1) Hit 'Enter' to advance" & vbLf & _ "2) Type a number to skip to that feature no." & vbLf & _ "3) Type text and hit 'Enter' to rename the current feature" & vbLf & _ "4) Hit 'Cancel' button to leave part 'as is' and exit iLogic" & vbLf & _ "5) Type 'e' to rebuild part completely and exit iLogic" _ , MsgBoxStyle.Information, "Cadline Feature Player") Player_Count = 1 'Iterate through features Do Try oFeatures.Item(Player_Count).SetEndOfPart(False) 'Highlight feature Feature.Color(oFeatures.Item(Player_Count).Name) = "Red" Catch 'MessageBox.Show("Error 3 - please check iLogic code", "Cadline Feature Player") End Try 'Start camera rotation animation 'Set Rangebox Try 'Get range box for first feature (used to calculate eye height and eye distance) oBox = oFeatures.Item(Player_Count).RangeBox 'Define size of feature in each direction Xcentre = (oBox.MaxPoint.X+oBox.MinPoint.X)/2 Ycentre = (oBox.MaxPoint.Y+oBox.MinPoint.Y)/2 Zcentre = (oBox.MaxPoint.Z+oBox.MinPoint.Z)/2 'Get X Y and Z range of feature Xrange = (oBox.MaxPoint.X-oBox.MinPoint.X) Yrange = (oBox.MaxPoint.Y-oBox.MinPoint.Y) Zrange = (oBox.MaxPoint.Z-oBox.MinPoint.Z) Catch 'MessageBox.Show("Error 4 - please check iLogic code", "Cadline Feature Player") End Try 'Iterate through the specified number of steps. Try For cc = 1 To steps Select Case RotationChoice Case "X" eyeDistance = DistMultiplier*(Max(Yrange,Zrange)) x = oPartBox.MaxPoint.X*HeightMultiplier y = Ycentre + (eyeDistance * Cos((cc+25) / (steps) * (2 * PI))) z = Zcentre + (eyeDistance * Sin((cc+25) / (steps) * (2 * PI))) cam.UpVector = tg.CreateUnitVector(1, 0, 0) Case "Y" x = Xcentre + (eyeDistance * Sin((cc+25) / (steps) * (2 * PI))) y = oPartBox.MaxPoint.Y*HeightMultiplier z = Zcentre + (eyeDistance * Cos((cc+25) / (steps) * (2 * PI))) cam.UpVector = tg.CreateUnitVector(0, 1, 0) Case "Z" x = Xcentre + (eyeDistance * Cos((cc+25) / (steps) * (2 * PI))) y = Ycentre + (eyeDistance * Sin((cc+25) / (steps) * (2 * PI))) z = oPartBox.MaxPoint.Z*HeightMultiplier cam.UpVector = tg.CreateUnitVector(0, 0, 1) End Select 'Set the eye cam.Eye = tg.CreatePoint(x, y, z) 'Make camera target the centre of X Y and Z cam.Target = tg.CreatePoint(Xcentre, Ycentre, Zcentre) 'Apply the current camera definition to the view. If cc > 1 Then cam.ApplyWithoutTransition Else cam.Apply End If Next Catch MessageBox.Show("Error 5 - please check iLogic code", "Cadline Feature Player") End Try 'Get input for each feature Question2: Try Input1 = InputBox("(type 'slow' or 'fast' to change rotation speed)","Feature: " _ & Player_Count & " of " & Feat_Count & " - " & oFeatures.Item(Player_Count).Name _ ,oFeatures.Item(Player_Count).Name) Catch MessageBox.Show("Could not rename feature - exiting rule!!", "Cadline Feature Player") Return End Try 'Exit if 'cancel' button is hit If Input1 = "" Then 'Reset feature colour Try Feature.Color(oFeatures.Item(Player_Count).Name) = "As Body" Catch ' do nothing End Try Return ' Exit Else If Player_Count>1 'Check if feature name already exists For dd = 1 To Player_Count-1 If UCase(oFeatures.Item(dd).Name) = UCase(Input1) Then MessageBox.Show("That feature name already exists - try again!", _ "Cadline Feature Player") Goto Question2 End If Next End If Try 'Reset feature colour Feature.Color(oFeatures.Item(Player_Count).Name) = "As Body" Catch MessageBox.Show("Error 6 - please check iLogic code", "Cadline Feature Player") End Try 'Act on user input If UCase(Input1) = "E" Then oFeatures.Item(Feat_Count).SetEndOfPart(False) 'Turn off surface bodies (so they can be seen in player) For Each oWorkSurface In oWorkSurfaces For ee = 1 To oWorkSurface.SurfaceBodies.Count oWorkSurface.SurfaceBodies.Item(ee).Visible = "False" Next Next Return Else If UCase(Input1) = "SLOW" If steps < 400 Then steps = steps+40 Player_Count = Player_Count+1 Else MsgBox("You can't go any slower than that!", MsgBoxStyle.Information, _ "Cadline Feature Player") End If Else If UCase(Input1) = "FAST" If steps > 60 Then steps = steps-40 Player_Count = Player_Count+1 Else MsgBox("You can't go any faster than that!", MsgBoxStyle.Information, _ "Cadline Feature Player") End If Else If IsNumeric(Input1) If Input1 <= Feat_Count And Input1 > 0 Then Player_Count = Input1 InventorVb.DocumentUpdate() oFeatures.Item(Player_Count).SetEndOfPart(False) Else MessageBox.Show("There aren't that many features in the part!" & vbLf & vbLf & _ "Setting part to last feature", "Cadline Feature Player") Player_Count = Feat_Count InventorVb.DocumentUpdate() oFeatures.Item(Feat_Count).SetEndOfPart(False) End If Else If UCase(Input1) <> UCase(oFeatures.Item(Player_Count).Name) Then oFeatures.Item(Player_Count).Name = Input1 Player_Count = Player_Count+1 Else Player_Count = Player_Count+1 End If 'Exit loop if reach end of features If Player_Count = Feat_Count+1 Then Exit Do End If Loop 'Rebuild part completely oFeatures.Item(Feat_Count).SetEndOfPart(False) 'Turn off surface bodies (but only if there is no solid body) If oSurfaces.Count > 0 Then For Each oWorkSurface In oWorkSurfaces For ff = 1 To oWorkSurface.SurfaceBodies.Count oWorkSurface.SurfaceBodies.Item(ff).Visible = "False" Next Next End If ThisApplication.ActiveView.GoHome ' **************************** END OF iLOGIC CODE *********************************************