Cut a solid by RevolveFeature

Cut a solid by RevolveFeature

bruscaginmatteo
Participant Participant
289 Views
11 Replies
Message 1 of 12

Cut a solid by RevolveFeature

bruscaginmatteo
Participant
Participant
Hi, how can I choose the solid to cut with RevolveFeature?
This is my code:
Dim revolveFeatRemove As RevolveFeature = DefinizioneParte.Features.RevolveFeatures.AddByAngle(oProfile01, oWorkAx, oElbowAngle, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kCutOperation)
Thanks in advance

 

 


Matteo

 

0 Likes
Accepted solutions (1)
290 Views
11 Replies
Replies (11)
Message 2 of 12

marcin_otręba
Advisor
Advisor

did you try to set affected bodies? :

Inventor 2025 Help | RevolveFeature.SetAffectedBodies Method | Autodesk

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 12

bruscaginmatteo
Participant
Participant

Hi,  Have You a small example? 

0 Likes
Message 4 of 12

J_Pfeifer_
Advocate
Advocate

-<See below conversation>-

Here is a code example of doing exactly what you're looking for. SweepFeature.SetAffectedBodies(MainFittingCol). The main fitting col is a surface body collection. In this case, that collection holds all the surface bodies that make up the fitting.  If I were to pause or stop the program before the set affected line. It will cut the revolve through the main or first surface body object automatically. 

 

0 Likes
Message 5 of 12

bruscaginmatteo
Participant
Participant


Dim oFeatures As PartFeatures
oFeatures = DefinizioneParte.Features

 

Dim objects As ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection
' objects.Add(oFeatures.Item(11).SurfaceBodies)

 

For Each MyPart As PartFeature In oFeatures
objects.Add(MyPart)

Next

 

Dim revolveFeatRemove2 As RevolveFeature

revolveFeatRemove2 = DefinizioneParte.Features.RevolveFeatures.AddByAngle(oProfile01,oWorkAx,oElbowAngle,PartFeatureExtentDirectionEnum.kNegativeExtentDirection,PartFeatureOperationEnum.kCutOperation)


revolveFeatRemove2.SetAffectedBodies(objects) 

 

What is my error? are not the object correct?

 

0 Likes
Message 6 of 12

J_Pfeifer_
Advocate
Advocate

Im super sorry friend, barely functioning on like 3 hours of sleep. In looking back on this and copying the message 3 times due to it not posting. I coppied the wrong code for you to look at. This should have been more close to the below code. 

	Dim BackTrimCol As ObjectCollection = oTO.CreateObjectCollection
			
			Dim BackTrimSketch As PlanarSketch 
			
			Dim BackProfile As Profile
			
			Dim BackStartPoint As SketchPoint, BackRectPoint As SketchPoint, Rect2StartPoint As SketchPoint, Rect2EndPoint As SketchPoint
			
			Dim Rectangle2 As SketchEntitiesEnumerator
			
			Dim Rect2Line1 As SketchLine, Rect2Line3 As SketchLine
			
			Dim BackStartDis As DimensionConstraint, Rect2Line1Con As DimensionConstraint, CenterControlA As DimensionConstraint, Rect2Line3con As DimensionConstraint, CenterControlB As DimensionConstraint
			
			Dim BackRevolveTrim as RevolveFeature
				
					
					BackTrimSketch = oCompDef.Sketches.Add(oUCS.YZPlane)
						BackTrimSketch.Name = FittingNameInput & " upper trim sketch "
					
					BackStartPoint = BackTrimSketch.AddByProjectingEntity(Proj_Point)
					
					BackRectPoint  = BackTrimSketch.SketchPoints.Add(oTG.CreatePoint2d(BackStartPoint.Geometry.X, BackStartPoint.Geometry.Y - 1)) 
						BackTrimSketch.GeometricConstraints.AddVerticalAlign(BackStartPoint, BackRectPoint)
						
						BackStartDis = BackTrimSketch.DimensionConstraints.AddTwoPointDistance(BackRectPoint, BackStartPoint, Inventor.DimensionOrientationEnum.kAlignedDim, oTG.CreatePoint2d(10, 10))
							BackStartDis.Parameter.Expression = FittingNameInput & "_Fitting_Proj" & "*2 " & "+tank_id+sidewall_th*2"
							
						oDoc.Update	
							
						Rect2StartPoint = BackTrimSketch.SketchPoints.Add(oTG.CreatePoint2d(BackRectPoint.Geometry.X - 5, BackRectPoint.Geometry.Y - 5))
						Rect2EndPoint = BackTrimSketch.SketchPoints.Add(oTG.CreatePoint2d(BackRectPoint.Geometry.X + 5, BackRectPoint.Geometry.Y + 5))
							
						Rectangle2 = BackTrimSketch.SketchLines.AddAsTwoPointRectangle(Rect2StartPoint, Rect2EndPoint)	
							
							Rect2Line1 = Rectangle2.Item(2)
							Rect2Line3 = Rectangle2.Item(3)
							
							Rect2Line1Con = BackTrimSketch.DimensionConstraints.AddTwoPointDistance(Rect2Line1.StartSketchPoint, Rect2Line1.EndSketchPoint, Inventor.DimensionOrientationEnum.kVerticalDim, oTG.CreatePoint2d(3, 3))
								Rect2Line1Con.Parameter.Expression = "(6+sidewall_th+3)*2+12"
									
							CenterControlA = BackTrimSketch.DimensionConstraints.AddTwoPointDistance(BackRectPoint, Rect2EndPoint, Inventor.DimensionOrientationEnum.kVerticalDim, oTG.CreatePoint2d(-6, -6))
								CenterControlA.Parameter.Expression = "(6+sidewall_th)+3"
								
							Rect2Line3con= BackTrimSketch.DimensionConstraints.AddTwoPointDistance(Rect2Line3.StartSketchPoint, Rect2Line3.EndSketchPoint, Inventor.DimensionOrientationEnum.kHorizontalDim, oTG.CreatePoint2d(-3, -3))
								Rect2Line3Con.Parameter.Value = 48 * 2.54
								
							CenterControlB = BackTrimSketch.DimensionConstraints.AddTwoPointDistance(BackRectPoint, Rect2StartPoint, Inventor.DimensionOrientationEnum.kHorizontalDim, oTG.CreatePoint2d(6, 6))
								CenterControlB.Parameter.Value = 24 * 2.54 
									
						BackProfile = BackTrimSketch.Profiles.AddForSolid
						
							oDoc.Update
						
								'The below is calculating the area to cut away from the outside
								Dim Ratio As Double =  (oUserParams.Item(FittingNameInput & "_Flange_Size").Value / 2) / (tank_id / 2) 
								Dim ThetaRad As Double = 2 * Math.Asin(Ratio)
								Dim ThetaDeg As Double = ThetaRad * (180 / Math.PI)
								
								Dim AdjustedAngle As Double = 360 - ThetaDeg 
								Dim AdjustedRad As Double = AdjustedAngle * Math.PI /180
								
					
						BackRevolveTrim = oCompDef.Features.RevolveFeatures.AddByAngle(BackProfile, oUCS.YAxis, AdjustedRad, Inventor.PartFeatureExtentDirectionEnum.kSymmetricExtentDirection, Inventor.PartFeatureOperationEnum.kCutOperation)
							BackRevolveTrim.Name = FittingNameInput & " Upper trim revolution "
							BackRevolveTrim.SetAffectedBodies(TrimCol)
						
						
						If InputAngle = 0 Then 
						
							BackRevolveTrim.Suppressed = True
							RevolveTrim.Suppressed = False
						Else 	
							'Logger.Info("Inside the revolve trim suppression")
							RevolveTrim.Suppressed = False 'This should be turning on based on the input we have entered. 
							BackRevolveTrim.Suppressed = False
						End If 

 

To answer you're question as a reply. It could be a couple of things going on as I cannot see the full code you're working with. You could have the wrong index for the surface bodies, could be the wrong axis or object. That's why I described the function at creation to you. It can take trial and error due to it not being applicable at creation, but works after setting the bodies. Something else of note, as I've gotten myself into trouble doing so. Try not to name things exactly what they are, sometimes they can be misintrupreted. Your objects, should be something with a defining letter or otherwise like iObjects. For example, I love to do (Dim Heightparam as parameter = something), Inventor doesn't like this and prefers I specify its an inventor parameter (Dim HeightParam as inventor.parameter). seems to fix my issue. 

 

What is the error you're getting exactly, are you failing to create the definition or failing to change it to the new surface body collection?

 

0 Likes
Message 7 of 12

marcin_otręba
Advisor
Advisor

@bruscaginmatteo why you add partfeatures instead of bodies to collection?

 

here is example of working code:

Dim oInvApp As Inventor.Application=ThisApplication
Dim Parte As PartDocument = ThisDoc.Document
Dim DefinizioneParte As PartComponentDefinition=Parte.ComponentDefinition
Dim oFeatures As PartFeatures
oFeatures = DefinizioneParte.Features
Dim objects As ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection

For Each body As SurfaceBody  In DefinizioneParte.SurfaceBodies
objects.Add(body)
Next

 Dim oProfile01 As Profile = oInvApp.CommandManager.Pick(SelectionFilterEnum.kSketchProfileFilter,"pick profile to revolve")
 Dim oWorkAx As WorkAxis = oInvApp.CommandManager.Pick(SelectionFilterEnum.kWorkAxisFilter,"pick axis to revolve")
 Dim oElbowAngle As Double =1

Dim revolveFeatRemove2 As RevolveFeature
revolveFeatRemove2 = DefinizioneParte.Features.RevolveFeatures.AddByAngle(oProfile01,oWorkAx,oElbowAngle,PartFeatureExtentDirectionEnum.kNegativeExtentDirection,PartFeatureOperationEnum.kCutOperation)
revolveFeatRemove2.SetAffectedBodies(objects ) 

 

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 8 of 12

bruscaginmatteo
Participant
Participant

Thanks for the help!

but stiil dont' work...:(

this is my code


Dim oWorkAx As Object
Dim oProfile01 As Profile

Dim oElbowAngle As Double
Dim pi As Double = Math.Acos(-1)
oElbowAngle = (360 * pi / 180)


oWorkAx = DefinizioneParte.WorkAxes.Item(1)
oProfile01 = oRaccordo.Profiles.AddForSolid

Dim oFeatures As PartFeatures
oFeatures = DefinizioneParte.Features
Dim objects As ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection

For Each body As SurfaceBody In DefinizioneParte.SurfaceBodies
objects.Add(body)
Next


Dim revolveFeatRemove2 As RevolveFeature
revolveFeatRemove2 = DefinizioneParte.Features.RevolveFeatures.AddByAngle(oProfile01, oWorkAx, oElbowAngle, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kCutOperation)
revolveFeatRemove2.SetAffectedBodies(objects)

 

One parameter isnt correct.

Below there is a picture.

0 Likes
Message 9 of 12

marcin_otręba
Advisor
Advisor

maybe you can share you part here ?

can you try to make it without api? make it in inventor and choosing all bodies then see if you get error?

you can also add only this body you want to objects? because right now it add all bodies to you revolve ft.

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 10 of 12

bruscaginmatteo
Participant
Participant

this is my routine

 

i call this routine just for modify the last exagon, this routine should be used for many different exagon.

MANY THANKS

 

Private Sub CreaSmussoAEsagonoGirevole(ByVal oInvApp As Application, ByVal Estrusione As ExtrudeFeature, ByVal oPartDoc As PartDocument, ByVal DefinizioneParte As PartComponentDefinition, ByVal oTG As TransientGeometry, ByVal M_Chiave As Double, ByVal OffsetDaCentroX As Double, ByVal OffsetDaCentroY As Double)

 

M_Chiave = M_Chiave / 10
Dim AltezzaEstrusione As Double
Dim extrudeDef As ExtrudeDefinition ' calcolo ' altezza del esagono
extrudeDef = Estrusione.Definition
If extrudeDef.ExtentType = PartFeatureExtentEnum.kDistanceExtent Then
Dim distanceEx As DistanceExtent
distanceEx = extrudeDef.Extent
AltezzaEstrusione = CDbl(distanceEx.Distance.Value)
End If


Dim A As Point2d
Dim B As Point2d
Dim C As Point2d
Dim Linea1 As SketchLine
Dim Linea2 As SketchLine
Dim Linea3 As SketchLine
Dim oRaccordo As PlanarSketch
OffsetDaCentroX = OffsetDaCentroX \ 10
OffsetDaCentroY = OffsetDaCentroY \ 10
Dim AggiuntaPerInizio As Double = ((M_Chiave * 0.05)) ' con quest0 parametro aumento in % il valore di uscita dall'ingombro del dado


' Dim InizioY As Double = ((M_Chiave * 0.49) + AggiuntaPerInizio + OffsetDaCentroY) ' questo punto è la distanza fuori ingombro della rivoluzione nell asse Y

Dim InizioY As Double = ((M_Chiave / 2) + OffsetDaCentroY) ' questo punto è la distanza fuori ingombro della rivoluzione nell asse Y
Dim InizioX As Double = (AltezzaEstrusione / 2) + OffsetDaCentroX

Dim RadicediTre As Double = 1.73
Dim AltezzaSfaccio As Double
AltezzaSfaccio = M_Chiave * RadicediTre
AltezzaSfaccio = AltezzaSfaccio / 3

AltezzaSfaccio = (M_Chiave) - AltezzaSfaccio
AltezzaSfaccio = AltezzaSfaccio / 10 '" = diametro x radice di tre diviso 3
Dim Cateto As Double = (((M_Chiave / 100) * 3.5)) ' la misura dei lati del triangolo

 

oRaccordo = DefinizioneParte.Sketches.Add(DefinizioneParte.WorkPlanes.Item(2))

A = oTG.CreatePoint2d(InizioX, InizioY + AltezzaSfaccio + AltezzaSfaccio)
B = oTG.CreatePoint2d(InizioX, InizioY)
C = oTG.CreatePoint2d(InizioX - Cateto, InizioY + AltezzaSfaccio + AltezzaSfaccio)


Linea1 = oRaccordo.SketchLines.AddByTwoPoints(A, B)
Linea2 = oRaccordo.SketchLines.AddByTwoPoints(Linea1.EndSketchPoint, C)
Linea3 = oRaccordo.SketchLines.AddByTwoPoints(Linea2.EndSketchPoint, Linea1.StartSketchPoint)


Dim oWorkAx As Object
Dim oProfile01 As Profile

Dim oElbowAngle As Double
Dim pi As Double = Math.Acos(-1)
oElbowAngle = (360 * pi / 180)


oWorkAx = DefinizioneParte.WorkAxes.Item(1)
oProfile01 = oRaccordo.Profiles.AddForSolid

Dim oFeatures As PartFeatures
oFeatures = DefinizioneParte.Features
Dim objects As ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection

For Each body As SurfaceBody In DefinizioneParte.SurfaceBodies
objects.Add(body)
Next


Dim revolveFeatRemove2 As RevolveFeature
revolveFeatRemove2 = DefinizioneParte.Features.RevolveFeatures.AddByAngle(oProfile01, oWorkAx, oElbowAngle, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kCutOperation)
revolveFeatRemove2.SetAffectedBodies(objects)

 

 

 

'' ''Dim oPDC As Inventor.PartComponentDefinition = oPartDoc.ComponentDefinition
'' ''Dim oFeatures As Inventor.PartFeatures = oPDC.Features

'' ''Dim oYZPlane As WorkPlane
'' ''oYZPlane = DefinizioneParte.WorkPlanes.Item(1)

'' ''Dim oBjColExtrude As Inventor.ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection
' '' ''Dim oBjColSweep As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
'' ''oBjColExtrude.Add(oRevFeature)

'' ''Dim oMirs As Inventor.MirrorFeatures = oFeatures.MirrorFeatures
'' ''Dim oMirFeatDef As Inventor.MirrorFeatureDefinition
'' ''oMirFeatDef = oFeatures.MirrorFeatures.CreateDefinition(oBjColExtrude, oYZPlane, PatternComputeTypeEnum.kIdenticalCompute)

'' ''Dim oMirFeat As Inventor.MirrorFeature
'' ''oMirFeat = oMirs.AddByDefinition(oMirFeatDef)
' '' '' oMirFeat.Name = "Testing"

 

 


End Sub

0 Likes
Message 11 of 12

marcin_otręba
Advisor
Advisor
Accepted solution

i think this is because you try to add body wchich already is affected by this feature.. try this change:

 

Dim objects As ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection
Dim revolveFeatRemove2 As RevolveFeature
revolveFeatRemove2 = DefinizioneParte.Features.RevolveFeatures.AddByAngle(oProfile01, oWorkAx, oElbowAngle, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kCutOperation)

objects.Clear

For Each body As SurfaceBody In DefinizioneParte.SurfaceBodies
If body IsNot revolveFeatRemove2.SurfaceBodies(1) Then  objects.Add(body)
Next
revolveFeatRemove2.SetAffectedBodies(objects)

 

you can also affect only your extrude body using:

If body IsNot revolveFeatRemove2.SurfaceBodies(1) Then objects.Add(Estrusione.SurfaceBodies(1))

 

instead of:

For Each body As SurfaceBody In DefinizioneParte.SurfaceBodies
If body IsNot revolveFeatRemove2.SurfaceBodies(1) Then  objects.Add(body)
Next

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 12 of 12

bruscaginmatteo
Participant
Participant

Hi! Is working now!! Many thanks!!

But isnt so clear what was the Issue.. 

0 Likes