I need with a rule that will look for the closed profiles in a sketch array and select them all

I need with a rule that will look for the closed profiles in a sketch array and select them all

chris
Advisor Advisor
154 Views
4 Replies
Message 1 of 5

I need with a rule that will look for the closed profiles in a sketch array and select them all

chris
Advisor
Advisor

I'm trying to set up a rule that will automatically look at a sketch array, in this case it's a group of circles, and it will automatically select all of the circles, "closed profiles". The issue I am having is that Inventor keeps telling me that it doesn't see any closed profiles, even though once I create the sketch array, all the circles are selectable by a window selection.

 

I want to run the rule on a named sketch within the part file, and have it auto select all the red circles and then perform a revolve feature around the Y axis.

 

chris_0-1754057489470.png

 

 

 

 

0 Likes
Accepted solutions (1)
155 Views
4 Replies
Replies (4)
Message 2 of 5

chris
Advisor
Advisor

Here's a code example I was trying to use

' Get the active part document
Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument

' Get the part component definition
Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition

' Find the specific sketch by name
Dim oSketch As PlanarSketch = Nothing
For i = 1 To oPartDef.Sketches.Count
    If oPartDef.Sketches.Item(i).Name = "Bottom Hoop Profiles" Then
        oSketch = oPartDef.Sketches.Item(i)
        Exit For
    End If
Next

' Check if sketch was found
If oSketch Is Nothing Then
    MessageBox.Show("Sketch 'Bottom Hoop Profiles' not found!", "Error")
    Exit Sub
End If

' For sketch arrays, we need to look at the sketch entities and patterns
MessageBox.Show("Found sketch: " & oSketch.Name & vbCrLf & "Profile count: " & oSketch.Profiles.Count, "Debug Info")

' Method 1: Try to work with all profiles (including arrayed ones)
If oSketch.Profiles.Count > 0 Then
    
    ' Loop through each profile in the sketch
    For i = 1 To oSketch.Profiles.Count
        Dim oProfile As Profile = oSketch.Profiles.Item(i)
        
        Try
            ' For arrayed profiles, we might need to check differently
            Dim profilePaths As Integer = oProfile.Count
            MessageBox.Show("Profile " & i & " has " & profilePaths & " path(s)", "Debug")
            
            ' Try to revolve each profile
            Try
                ' Create revolve definition around Y-axis (WorkAxis 2)
                Dim oRevolveDef = oPartDef.Features.RevolveFeatures.CreateRevolveDefinition(oProfile, oPartDef.WorkAxes.Item(2))
                
                ' Set revolve to full 360 degrees
                oRevolveDef.SetToFullSweep()
                
                ' Create the revolve feature
                Dim oRevolveFeature = oPartDef.Features.RevolveFeatures.Add(oRevolveDef)
                
                MessageBox.Show("Successfully revolved profile " & i, "Success")
                
            Catch ex As Exception
                ' Handle any errors (e.g., profile can't be revolved)
                MessageBox.Show("Could not revolve profile " & i & ": " & ex.Message, "Revolve Error")
            End Try
            
        Catch ex As Exception
            MessageBox.Show("Error processing profile " & i & ": " & ex.Message, "Error")
        End Try
        
    Next
    
Else
    MessageBox.Show("No profiles found. This might be due to how sketch arrays are handled.", "Info")
End If

' Alternative Method 2: Look for sketch patterns and work with them
Try
    If oSketch.SketchPatterns.Count > 0 Then
        MessageBox.Show("Found " & oSketch.SketchPatterns.Count & " sketch patterns", "Pattern Info")
        
        ' You might need to suppress the pattern temporarily and work with individual profiles
        ' Or create a separate approach for patterned geometry
    End If
Catch
    ' SketchPatterns might not be available in this context
End Try

' Update the part
oPartDoc.Update()

MessageBox.Show("Operation completed!", "Final")
0 Likes
Message 3 of 5

jjstr8
Collaborator
Collaborator
Accepted solution

Give this a try. I did this on 2024. I wasn't sure what version you're on, but I couldn't find CreateRevolveDefinition as a valid method. The profiles need to be created as needed using AddForSolid, or AddForSurface. There are optional parameters for the AddForSolid call, but I don't think they're needed in your case.

' Get the active part document
Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument

' Get the part component definition
Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition

' Find the specific sketch by name
Dim oSketch As PlanarSketch = Nothing
For i = 1 To oPartDef.Sketches.Count
    If oPartDef.Sketches.Item(i).Name = "Bottom Hoop Profiles" Then
        oSketch = oPartDef.Sketches.Item(i)
        Exit For
    End If
Next

' Check if sketch was found
If oSketch Is Nothing Then
    MessageBox.Show("Sketch 'Bottom Hoop Profiles' not found!", "Error")
    Exit Sub
End If

Try
	Dim newProfile As Profile
	newProfile = oSketch.Profiles.AddForSolid
    Try
        ' Create revolve definition around Y-axis (WorkAxis 2)
        Dim oRevolveDef = oPartDef.Features.RevolveFeatures.AddFull(newProfile, oPartDef.WorkAxes.Item(2), PartFeatureOperationEnum.kNewBodyOperation)    
    Catch ex As Exception
        ' Handle any errors (e.g., profile can't be revolved)
        MessageBox.Show("Could not revolve profile: "  & ex.Message, "Revolve Error")
    End Try
Catch
    MessageBox.Show("Could not extract profiles", "Info")
End Try

  

0 Likes
Message 4 of 5

chris
Advisor
Advisor

@jjstr8 

That worked, do you think you could help me solve the first part of this design "challenge"? Getting the close profiles to be recognized and revolved was second part of the problem, the first part was getting those circle profiles to be automatically created within the sketch "Bottom Hoop Profiles" with their center points for each "array'd" work point.

 

1. First I sketch a curve, on the XY plane\end sketch 

2. Then I add a workpoint at the beginning of that curve

3. Then I use the pattern feature to pattern the workpoint along the curve, with "curve length" the option for "spacing", let's say 15ul

4. Then I create another XY plane sketch "Bottom Hoop Profiles", currently I manually project all the workpoints and then manually create circles at each workpoint, then select each circle and revolve.

 

What I'm trying to do is get iLogic/vb/API to see the workpoints and automatically create the circle profiles at the workpoints on the "Bottom Hoop Profile" sketch, this way if the number of workpoints changes, the rule will adjust for either a smaller or large amount of workpoints and in turn adjust the revolved feature

 

I'm in 2025, so I'll add images, in order

chris_0-1754539816994.png

chris_1-1754539878936.png

chris_2-1754539913326.png

chris_3-1754539970965.pngchris_4-1754540022016.png

 

 

 

 

 

0 Likes
Message 5 of 5

chris
Advisor
Advisor

@jjstr8 No worries, I have the whole thing working now!