- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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.
Solved! Go to Solution.