Try to set kNewBodyOperation on a ContourFlangeFeature. Help!

Try to set kNewBodyOperation on a ContourFlangeFeature. Help!

mecanicu
Advocate Advocate
537 Views
2 Replies
Message 1 of 3

Try to set kNewBodyOperation on a ContourFlangeFeature. Help!

mecanicu
Advocate
Advocate

Hello.

I'm trying to use ContourFlangeFeature in a SheetMetal Multi-Body Part. But i don't know how to set the action as a New Solid. 

Sub Main()

Dim oApp  = ThisApplication
Dim part As PartDocument = ThisDoc.Document
Dim partDef = part.ComponentDefinition
Dim bodies = partDef.SurfaceBodies

For Each body As SurfaceBody In bodies
Dim edges = body.Edges
		For Each oEdge As Edge In edges
				Dim length = oApp.MeasureTools.GetMinimumDistance(oEdge.StartVertex, oEdge.StopVertex)
				'MessageBox.Show("Message: " & length, "Title")
				Dim wp As WorkPlane
				Dim oWkPoint As WorkPoint
	    		oWkPoint = part.ComponentDefinition.WorkPoints.AddFixed(oEdge.Geometry.MidPoint)
	    		wp = part.ComponentDefinition.WorkPlanes.AddByNormalToCurve(oEdge, oWkPoint)			

				Dim oPlane1 = partDef.WorkPlanes.AddByPlaneAndOffset(oEdge.Faces.Item(1), 0)
				Dim oPlane2 = partDef.WorkPlanes.AddByPlaneAndOffset(oEdge.Faces.Item(2), 0)
				
				Dim oSketch As Sketch
				oSketch = partDef.Sketches.Add(wp)
				
				Dim sEntity1 = oSketch.AddByProjectingEntity(oPlane1)
				sEntity1.Construction = True
				Dim sEntity2 = oSketch.AddByProjectingEntity(oPlane2)
				sEntity2.Construction = True
				
				oPlane1.Visible = False
				oPlane2.Visible = False
				
				Dim point1 = ThisApplication.TransientGeometry.CreatePoint2d(1, 0)
				Dim center = oSketch.AddByProjectingEntity(oWkPoint)
				Dim profileLine1 = oSketch.SketchLines.AddByTwoPoints(center, point1)
				oSketch.GeometricConstraints.AddCollinear(sEntity1, profileLine1)
				
				Dim point2 = ThisApplication.TransientGeometry.CreatePoint2d(-1, 0)
				Dim profileLine2 = oSketch.SketchLines.AddByTwoPoints(center, point2)
				oSketch.GeometricConstraints.AddCollinear(sEntity2, profileLine2)
                oSketch.GeometricConstraints.AddEqualLength (profileLine1, profileLine2)
				
				 ' Create a path.
	    		Dim oPath As Path
	    		oPath = partDef.Features.CreatePath(profileLine1)
	    
	    		Dim oContourFlangeFeatures As ContourFlangeFeatures
	    		oContourFlangeFeatures = partDef.Features.ContourFlangeFeatures

	    		' Create the flange definition.
	    		Dim cfDef As ContourFlangeDefinition
	    		cfDef = oContourFlangeFeatures.CreateContourFlangeDefinition(oPath)
	    		'set the distance extent
	    		Call cfDef.SetDistanceExtent(length, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection)
	    		
	    		Dim oCF As ContourFlangeFeature
	    		oCF = oContourFlangeFeatures.Add(cfDef)

			Next
			Exit For
		
Next

End Sub

 Thank you for any help! 

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

WCrihfield
Mentor
Mentor
Accepted solution

Hi @mecanicu.  Looks to me like you just needed to add that extra line of code in there for setting the operation of the ContourFlangeDefinition.

cfDef.Operation = PartFeatureOperationEnum.kNewBodyOperation

  I copied your whole block of code, to have the variables set-up, but I think you just need that one extra line.

 

Dim oContourFlangeFeatures As ContourFlangeFeatures
oContourFlangeFeatures = partDef.Features.ContourFlangeFeatures
' Create the flange definition.
Dim cfDef As ContourFlangeDefinition
cfDef = oContourFlangeFeatures.CreateContourFlangeDefinition(oPath)
'set the distance extent
cfDef.SetDistanceExtent(length, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection)
cfDef.Operation = PartFeatureOperationEnum.kNewBodyOperation
Dim oCF As ContourFlangeFeature
oCF = oContourFlangeFeatures.Add(cfDef)

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

mecanicu
Advocate
Advocate
Accepted solution

@WCrihfield  Thanks for replay. I manage to make it work. Same solution 

cfDef.Operation = kNewBodyOperation

But now i have a Sketch line problem.

Let me explain: the code luck at body and at every edge create a plane by point and line (same edge), on this plane it create a sketch then it's projecting 2 faces (left and right faces of the edge. here i'v offset a plane from faces and i'm projecting the plane. I don't know how to directly project the faces and make them Construction lines) after that i create 2 lines from center point of sketch that should be colinear to above projected lines (but i used AddByTwoPoints and the second point is random picket then i use colinear constrain)

I need a better alternative. Need to create 2 lines that are starting from sketch center point and be colinear to projected lines but towards the solid (sometime the colinear constrains is snapping the line in wrong direction, see attached pic1 correct, pic2 wrong) I don't now how to set the line dimension to 10mm!

Tx

Sub Main()

Dim oApp  = ThisApplication
Dim part As PartDocument = ThisDoc.Document
Dim partDef = part.ComponentDefinition
Dim bodies = partDef.SurfaceBodies

For Each body As SurfaceBody In bodies
Dim edges = body.Edges
		For Each oEdge As Edge In edges
				Dim length = oApp.MeasureTools.GetMinimumDistance(oEdge.StartVertex, oEdge.StopVertex)
				
				Dim wp As WorkPlane
				Dim oWkPoint As WorkPoint
	    		oWkPoint = part.ComponentDefinition.WorkPoints.AddFixed(oEdge.Geometry.MidPoint, Construction= False)
	    		wp = part.ComponentDefinition.WorkPlanes.AddByNormalToCurve(oEdge, oWkPoint, Construction= False)			

				Dim oPlane1 = partDef.WorkPlanes.AddByPlaneAndOffset(oEdge.Faces.Item(1), 0, Construction= False)
				Dim oPlane2 = partDef.WorkPlanes.AddByPlaneAndOffset(oEdge.Faces.Item(2), 0, Construction= False)
				
				
				Dim oSketch As Sketch
				oSketch = partDef.Sketches.Add(wp)
				
				Dim sEntity1 = oSketch.AddByProjectingEntity(oPlane1)
				
				Dim sEntity2 = oSketch.AddByProjectingEntity(oPlane2)
				
			
				oPlane1.Visible = False
				oPlane2.Visible = False
				
				Dim point1 = ThisApplication.TransientGeometry.CreatePoint2d(1, 0)
				Dim center = oSketch.AddByProjectingEntity(oWkPoint)
				Dim profileLine1 = oSketch.SketchLines.AddByTwoPoints(center, point1)
				oSketch.GeometricConstraints.AddCollinear(sEntity1, profileLine1)
				'profileLine1.Length = 10
				Dim point2 = ThisApplication.TransientGeometry.CreatePoint2d(-1, 0)
				Dim profileLine2 = oSketch.SketchLines.AddByTwoPoints(center, point2)
				oSketch.GeometricConstraints.AddCollinear(sEntity2, profileLine2)
                oSketch.GeometricConstraints.AddEqualLength (profileLine1, profileLine2)
				
				 ' Create a path.
	    		Dim oPath As Path
	    		oPath = partDef.Features.CreatePath(profileLine1)
	    
	    		Dim oContourFlangeFeatures As ContourFlangeFeatures
	    		oContourFlangeFeatures = partDef.Features.ContourFlangeFeatures

	    		' Create the flange definition.
	    		Dim cfDef As ContourFlangeDefinition
	    		cfDef = oContourFlangeFeatures.CreateContourFlangeDefinition(oPath)
	    		cfDef.Operation = kNewBodyOperation
	    		Call cfDef.SetDistanceExtent(length, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection)
	    		
	    		Dim oCF As ContourFlangeFeature
	    		oCF = oContourFlangeFeatures.Add(cfDef)

			Next
			Exit For
	Next

End Sub

 

 

 

 

 

0 Likes