Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a sketch with 6 sketch blocks.
The blocks are very simple, fully constrained and definitely do contain a profile as they are used in the extrusion (see the leftmost 2 in image).
The code accepts a List (of Single) that updates an extrusion to only include as many profiles as there are items in the list.
It also repositions the blocks to the X-value in the list (the blocks are constrained on Y), but that is removed in my example for readability.
The issue is that iLogic throws an error when I try to grab the profiles of the blocks. It claims that
oBlock.Definition.Profiles
is nothing.
Class MyRule Sub Main Dim Block_Positions_List As New List(Of Single) Block_Positions_List.Add(350) Block_Positions_List.Add(2500) Block_Positions_List.Add(-1500) Call UpdateExtrusion("Cutouts_Sketch", "Cutouts_Extrusion", Block_Positions_List) End Sub ' Code to move blocks to specific Y-value removed ' Extrude only Block_Positions_List.Count profiles Sub UpdateExtrusion(ByVal sketchName As String, ByVal extrusionName As String, ByVal Block_Positions_List As List(Of Single)) Dim oDoc As PartDocument = ThisApplication.ActiveDocument Dim oPart As PartComponentDefinition = oDoc.ComponentDefinition Dim oSketch As PlanarSketch Dim oExtrusion As ExtrudeFeature oSketch = oPart.Sketches.Item(sketchName) Dim oSketchBlocks As SketchBlocks = oSketch.SketchBlocks Dim numSketchBlocks As Integer = oSketchBlocks.Count Dim numPositions As Integer = Block_Positions_List.Count Dim profilesToExtrude As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection For i As Integer = 0 To numSketchBlocks - 1 Dim oBlock As SketchBlock = oSketchBlocks.Item(i + 1) If i < numPositions Then ' **debugging** If oBlock.Definition Is Nothing Then MessageBox.Show("Block " & (i + 1) & ": oBlock.Definition is Nothing.", "iLogic Debug") Else MessageBox.Show("Block " & (i + 1) & ": oBlock.Definition is valid.", "iLogic Debug") If oBlock.Definition.Profiles Is Nothing Then MessageBox.Show("Block " & (i + 1) & ": oBlock.Definition.Profiles is Nothing.", "iLogic Debug") Else MessageBox.Show("Block " & (i + 1) & ": oBlock.Definition.Profiles exists.", "iLogic Debug") If oBlock.Definition.Profiles.Count > 0 Then MessageBox.Show("Block " & (i + 1) & ": Profiles.Count = " & oBlock.Definition.Profiles.Count, "iLogic Debug") Try profilesToExtrude.Add(oBlock.Definition.Profiles.Item(1)) ' Assuming one profile per block Catch ex As Exception MessageBox.Show("Error adding profile for block " & (i + 1) & ": " & ex.Message, "iLogic Error") End Try Else MessageBox.Show("Warning: No profiles found for block " & (i + 1) & ". Skipping.", "iLogic Warning") End If End If End If Else ' Code to handle superfluous profiles removed for readability End If Next ' **Update the extrusion profiles** Try oExtrusion.Definition.Profiles = profilesToExtrude Catch ex As Exception MessageBox.Show("Error setting extrusion profiles: " & ex.Message, "iLogic Error") End Try ' Update the model Try oDoc.Update() Catch ex As Exception MessageBox.Show("Error updating the model: " & ex.Message, "iLogic Error") End Try End Sub End Class
Solved! Go to Solution.