Revolve To Create New Body Not Working

Revolve To Create New Body Not Working

huynh40
Explorer Explorer
414 Views
3 Replies
Message 1 of 4

Revolve To Create New Body Not Working

huynh40
Explorer
Explorer

Hello,

 

I have a closed sketch on a work plane that is a fixed distance offset from the XY plane. I also have a work axis created from one of the lines in the sketch. I am trying to perform a revolve with kNewBodyOperation to create a new solid but keep running into this error "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))". I tried revolving it manually and it works fine Here is my code: 

'------------------------------------------------------------------------------------------------------------------------------------------------------
' CLEAR IPT

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

'Delete all existing features
Dim oFeatures As PartFeatures
oFeatures = ThisApplication.ActiveDocument.ComponentDefinition.Features

For Each oFeature In oFeatures
	Try
    	oFeature.Delete
	Catch ex As Exception
	End Try
Next

'Delete all existing sketches
Dim oSketches As PlanarSketches
Dim oSketch As PlanarSketch
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches

For Each oSketch In oSketches
    oSketch.Delete
Next

' Delete all work planes
For Each oWP In oDoc.ComponentDefinition.WorkPlanes
'skip origin planes
    If oWP.IsCoordinateSystemElement = True Then
    'do nothing 
    Else
        oWP.Delete  
    End If    
Next

' Delete all work axes
For Each oWA In oDoc.ComponentDefinition.WorkAxes
'skip origin planes
    If oWA.IsCoordinateSystemElement = True Then
    'do nothing 
    Else
        oWA.Delete  
    End If    
Next

'------------------------------------------------------------------------------------------------------------------------------------------------------
' REVOLVE   

Dim oWP2 As WorkPlane
oWP2 = oCompDef.WorkPlanes.Item("XY Plane")
Dim Length As Double = 0.9
Dim Major As Double  = 0.4/2
Dim blankd As Double = 0.312 / 2

blankWorkPlane = oCompDef.WorkPlanes.AddByPlaneAndOffset(oWP2, 3)

Dim blankCoords(6, 1) As Double

blankCoords(0, 0) = 0
blankCoords(0, 1) = 0
blankCoords(1, 0) = Length
blankCoords(1, 1) = 0
blankCoords(2, 0) = Length
blankCoords(2, 1) = Major - (0.05 * System.Math.Tan(PI / 4))
blankCoords(3, 0) = Length - 0.05
blankCoords(3, 1) = Major
blankCoords(5, 0) = (Major)*1.25
blankCoords(5, 1) = blankd
blankCoords(4, 0) = blankCoords(5, 0) + ((Major - blankd) / (2 * Tan(PI / 3)))
blankCoords(4, 1) = Major
blankCoords(6, 0) = 0
blankCoords(6, 1) = blankd

blankSketch = oCompDef.Sketches.Add(blankWorkPlane)

Dim blankPts(6) As SketchPoint

' Identifying points
For i As Integer = 0 To 6
    Dim x As Double = blankCoords(i, 0)
    Dim y As Double = blankCoords(i, 1)

    blankPts(i) = blankSketch.SketchPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(x, y))
Next

' Specify the Work Axis by name
Dim blankRevAxis As WorkAxis = oCompDef.WorkAxes.AddByLine(blankSketch.SketchLines.AddByTwoPoints(blankPts(1), blankPts(0)))

' Create lines connecting consecutive points
For i As Integer = 0 To 5
    Dim oLine As SketchLine
    oLine = blankSketch.SketchLines.AddByTwoPoints(blankPts(i), blankPts(i + 1))
Next

' Connect the last point to the first point to close the loop
Dim blankFinalLine As SketchLine
blankFinalLine = blankSketch.SketchLines.AddByTwoPoints(blankPts(6), blankPts(0))

' Create a revolution feature using the specified Work Axis
Dim blankRev As RevolveFeature
blankRev = oCompDef.Features.RevolveFeatures.AddFull(blankSketch.Profiles.AddForSolid, blankRevAxis, kNewBodyOperation)

' Update the document
oDoc.Update()

 

This is where I am currently stuck at: 

huynh40_0-1701896811840.png

 

This is my desired end result: 

huynh40_1-1701896880201.png

 

 

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

A.Acheson
Mentor
Mentor

Hi @huynh40 

Is the profile a closed loop? If not then this would give issues with API revolving to profile. Can you tidy up the code used for testing purposes? It is missing document, definition and workplane objects. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 4

huynh40
Explorer
Explorer
'------------------------------------------------------------------------------------------------------------------------------------------------------
' CLEAR IPT

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

'Delete all existing features
Dim oFeatures As PartFeatures
oFeatures = ThisApplication.ActiveDocument.ComponentDefinition.Features

For Each oFeature In oFeatures
	Try
    	oFeature.Delete
	Catch ex As Exception
	End Try
Next

'Delete all existing sketches
Dim oSketches As PlanarSketches
Dim oSketch As PlanarSketch
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches

For Each oSketch In oSketches
    oSketch.Delete
Next

' Delete all work planes
For Each oWP In oDoc.ComponentDefinition.WorkPlanes
'skip origin planes
    If oWP.IsCoordinateSystemElement = True Then
    'do nothing 
    Else
        oWP.Delete  
    End If    
Next

' Delete all work axes
For Each oWA In oDoc.ComponentDefinition.WorkAxes
'skip origin planes
    If oWA.IsCoordinateSystemElement = True Then
    'do nothing 
    Else
        oWA.Delete  
    End If    
Next

'------------------------------------------------------------------------------------------------------------------------------------------------------
' REVOLVE   

Dim oWP2 As WorkPlane
oWP2 = oCompDef.WorkPlanes.Item("XY Plane")
Dim Length As Double = 0.9
Dim Major As Double  = 0.4/2
Dim blankd As Double = 0.312 / 2

blankWorkPlane = oCompDef.WorkPlanes.AddByPlaneAndOffset(oWP2, 3)


Dim blankCoords(6, 1) As Double

blankCoords(0, 0) = 0
blankCoords(0, 1) = 0
blankCoords(1, 0) = Length
blankCoords(1, 1) = 0
blankCoords(2, 0) = Length
blankCoords(2, 1) = Major - (0.05 * System.Math.Tan(PI / 4))
blankCoords(3, 0) = Length - 0.05
blankCoords(3, 1) = Major
blankCoords(5, 0) = (Major)*1.25
blankCoords(5, 1) = blankd
blankCoords(4, 0) = blankCoords(5, 0) + ((Major - blankd) / (2 * Tan(PI / 3)))
blankCoords(4, 1) = Major
blankCoords(6, 0) = 0
blankCoords(6, 1) = blankd


blankSketch = oCompDef.Sketches.Add(blankWorkPlane)

Dim blankPts(6) As SketchPoint

' Identifying points
For i As Integer = 0 To 6
    Dim x As Double = blankCoords(i, 0)
    Dim y As Double = blankCoords(i, 1)

    blankPts(i) = blankSketch.SketchPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(x, y))
Next

' Create lines connecting consecutive points
For i As Integer = 0 To 5
    Dim oLine As SketchLine
    oLine = blankSketch.SketchLines.AddByTwoPoints(blankPts(i), blankPts(i + 1))
Next

' Connect the last point to the first point to close the loop
Dim blankFinalLine As SketchLine
blankFinalLine = blankSketch.SketchLines.AddByTwoPoints(blankPts(6), blankPts(0))

' Specify the Work Axis by name
Dim blankRevAxis As WorkAxis = oCompDef.WorkAxes.AddByLine(blankSketch.SketchLines.AddByTwoPoints(blankPts(1), blankPts(0)))

' Create a revolution feature using the specified Work Axis
Dim blankRev As RevolveFeature
blankRev = oCompDef.Features.RevolveFeatures.AddFull(blankSketch.Profiles.AddForSolid, blankRevAxis, kNewBodyOperation)

' Update the document
oDoc.Update()

 

This code segment should work by itself. I am still getting the same error on the blankRev line. The profile is a closed loop. I can revolve it manually using the tools in Inventor but I cannot seem to get it work in iLogic. 

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor
Accepted solution

So I ran the code and it brought up the error as you described. If I try to revolve manually using the work axis the revolve it will not work, the axis cannot be selected. If I use SketchLines.Item(1) as the revolve axis entity this works. So the issue is the order and dependency in which the work axis is created. If you create the work axis from the workplanes and the work axis appears before the sketch in the tree then the revolve will work. Result below is from a manual revolve. Try and replicate this workflow by code.

 

AAcheson_0-1701971739206.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes