iLogic Create Ruled Surface in z direction

iLogic Create Ruled Surface in z direction

jaconoorland45
Contributor Contributor
189 Views
2 Replies
Message 1 of 3

iLogic Create Ruled Surface in z direction

jaconoorland45
Contributor
Contributor

Dear forum users,

 

I have inventor 2023.

I have a problem. I try to create a ruled surface from a 3d polyline like this:

Manually this succeeds every time.

jaconoorland45_0-1753115912279.png

I am unable to create an iLogic rule which replicates these steps/feature. I keep getting COM errors. I have tried several different options. Can someone help me? 

 

Thanks in advance!

 

My code:

 

'================================================================================
' iLogic Rule: Create Ruled Surface from 3D Sketch (Version 11 - Final Attempt)
' Description: This version builds the RuledSurfaceDefinition step-by-step.
' This is the final attempt; if this fails, the issue lies with the Inventor installation itself.
'================================================================================

Sub Main()
    If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
        MessageBox.Show("This rule can only be run in a Part (.ipt) file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return
    End If

    Dim oDoc As PartDocument = ThisDoc.Document
    Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition

    ' --- Settings ---
    Dim sketchName As String = "3D Sketch1"
    Dim distanceInMM As Double = 100

    Dim oSketch As Sketch3D = Nothing
    Try
        oSketch = oCompDef.Sketches3D.Item(sketchName)
    Catch
        MessageBox.Show("The 3D sketch named '" & sketchName & "' could not be found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return
    End Try
    
    Dim oDirectionVector As Vector = ThisApplication.TransientGeometry.CreateVector(0, 0, 1)
    Dim featureCount As Integer = 0
    
    Logger.Info("Starting sketch processing (Final Attempt): " & sketchName)

    ' Loop through each geometric entity in the sketch
    For Each oEntity As SketchEntity3D In oSketch.SketchEntities3D
        If TypeOf oEntity Is SketchLine3D Or _
           TypeOf oEntity Is SketchArc3D Or _
           TypeOf oEntity Is SketchSpline3D Or _
           TypeOf oEntity Is SketchControlPointSpline Then
            
            Try
                ' 1. Create a path from the SINGLE entity
                Dim oPath As Path = oCompDef.Features.CreatePath(oEntity)
                
                ' **THE FINAL ALTERNATIVE METHOD**
                ' a. Create an empty definition for this path
                Dim oRuledSurfaceDef As RuledSurfaceDefinition
                oRuledSurfaceDef = oCompDef.Features.RuledSurfaceFeatures.CreateRuledSurfaceDefinition(oPath)
                
                ' b. Set the direction and distance using a separate method
                Call oRuledSurfaceDef.SetDirectionAndDistance(oDirectionVector, distanceInMM / 10)
                
                ' c. Add the fully defined feature
                Dim oRuledSurface As RuledSurfaceFeature
                oRuledSurface = oCompDef.Features.RuledSurfaceFeatures.Add(oRuledSurfaceDef)
                
                featureCount = featureCount + 1
            Catch ex As Exception
                Logger.Warn("Could not create surface for segment. Type: " & TypeName(oEntity) & ". Error: " & ex.Message)
            End Try
        Else
             Logger.Info("Ignored entity of type: " & TypeName(oEntity))
        End If
    Next

    ' Display the result
    If featureCount > 0 Then
        MessageBox.Show(featureCount & " surface(s) created successfully.", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        MessageBox.Show("Operation failed. Fundamental API commands are missing. Check the iLogic Log and consider repairing or updating Inventor.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If

    iLogicVb.UpdateWhenDone = True
End Sub

 

The error messages:


INFO| 5: >>---------------------------
INFO|Starting sketch processing (Final Attempt): 3D Sketch1
INFO|Ignored entity of type: SketchPoint3D
INFO|Ignored entity of type: SketchPoint3D
WARN|Could not create surface for segment. Type: SketchLine3D. Error: Het openbare lid CreateRuledSurfaceDefinition voor type RuledSurfaceFeatures is niet gevonden.
INFO|Ignored entity of type: SketchPoint3D
WARN|Could not create surface for segment. Type: SketchLine3D. Error: Het openbare lid CreateRuledSurfaceDefinition voor type RuledSurfaceFeatures is niet gevonden.
INFO|Ignored entity of type: SketchPoint3D
WARN|Could not create surface for segment. Type: SketchLine3D. Error: Het openbare lid CreateRuledSurfaceDefinition voor type RuledSurfaceFeatures is niet gevonden.
INFO|Ignored entity of type: SketchPoint3D
WARN|Could not create surface for segment. Type: SketchLine3D. Error: Het openbare lid CreateRuledSurfaceDefinition voor type RuledSurfaceFeatures is niet gevonden.

jaconoorland45_0-1753173979739.png

 

 

 

0 Likes
Accepted solutions (1)
190 Views
2 Replies
Replies (2)
Message 2 of 3

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @jaconoorland45 .
According to the Inventor API help, the RuledSurfaceFeatures.CreateRuledSurfaceDefinition() method does not exist, instead we have CreateDefinition and CreateRuledSurfaceEdgeFacePairs. In your case, I used the first method, maybe the second one works too.
Next, I want to draw your attention to the objects that are allowed to be placed to define a vector, these are: Edge, Face, WorkAxis, WorkPlane, SketchLine, and SketchLine3D.
I edited your method "a" and removed the method "b":

'================================================================================
' iLogic Rule: Create Ruled Surface from 3D Sketch (Version 11 - Final Attempt)
' Description: This version builds the RuledSurfaceDefinition step-by-step.
' This is the final attempt; if this fails, the issue lies with the Inventor installation itself.
'================================================================================

Sub Main()
    If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
        MessageBox.Show("This rule can only be run in a Part (.ipt) file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return
    End If

    Dim oDoc As PartDocument = ThisDoc.Document
    Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition

    ' --- Settings ---
    Dim sketchName As String = "3D Sketch1"
    Dim distanceInMM As Double = 100

    Dim oSketch As Sketch3D = Nothing
    Try
        oSketch = oCompDef.Sketches3D.Item(sketchName)
    Catch
        MessageBox.Show("The 3D sketch named '" & sketchName & "' could not be found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return
    End Try
    
    Dim oDirectionVector As Vector = ThisApplication.TransientGeometry.CreateVector(0, 0, 1)
    Dim featureCount As Integer = 0
    
    Logger.Info("Starting sketch processing (Final Attempt): " & sketchName)

    ' Loop through each geometric entity in the sketch
    For Each oEntity As SketchEntity3D In oSketch.SketchEntities3D
        If TypeOf oEntity Is SketchLine3D Or _
           TypeOf oEntity Is SketchArc3D Or _
           TypeOf oEntity Is SketchSpline3D Or _
           TypeOf oEntity Is SketchControlPointSpline Then
            
            Try
                ' 1. Create a path from the SINGLE entity
                Dim oPath As Path = oCompDef.Features.CreatePath(oEntity)
                
                ' **THE FINAL ALTERNATIVE METHOD**
                ' a. Create an empty definition for this path
                Dim oRuledSurfaceDef As RuledSurfaceDefinition
				oRuledSurfaceDef = oCompDef.Features.RuledSurfaceFeatures.CreateDefinition(
												RuledSurfaceTypeEnum.kSweepRuledSurfaceType,
												oPath, distanceInMM / 10, oCompDef.WorkAxes(3))
                
                ' b. Add the fully defined feature
                Dim oRuledSurface As RuledSurfaceFeature
                oRuledSurface = oCompDef.Features.RuledSurfaceFeatures.Add(oRuledSurfaceDef)
                
                featureCount = featureCount + 1
            Catch ex As Exception
                Logger.Warn("Could not create surface for segment. Type: " & TypeName(oEntity) & ". Error: " & ex.Message)
            End Try
        Else
             Logger.Info("Ignored entity of type: " & TypeName(oEntity))
        End If
    Next

    ' Display the result
    If featureCount > 0 Then
        MessageBox.Show(featureCount & " surface(s) created successfully.", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        MessageBox.Show("Operation failed. Fundamental API commands are missing. Check the iLogic Log and consider repairing or updating Inventor.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If

    iLogicVb.UpdateWhenDone = True
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 3

jaconoorland45
Contributor
Contributor

This works like a charm!

 

I was really struggling with this, thank you so much for helping me out! 😉

 

Btw, do you know someplace where i can follow an advanced ilogic course so i can figure these things out myself?

0 Likes