I have a face "f", which can be assumed to be planar.
I have a SurfaceBody, which is a Surface, called "midsurface"
I wish to create a Sketch containing curve generated by intersection of "f" and "midsurface", placed at "f". (Pic attached)
Following is my attempt, which fails at various places. Sketch is not created. Then I am not able to find type of Intersection curve, so as to cast it and then add it to Sketch.
Public Sub fillMidcurvesData(ByRef nd As Node, ByRef transGeom As TransientGeometry, ByRef oCompDef As PartComponentDefinition)
'Find Interface Face's plane
Dim pt1 As Point = f.Vertices(1).Point()
Dim pt2 As Point = f.Vertices(2).Point()
Dim pt3 As Point = f.Vertices(3).Point()
Dim plane As Plane = transGeom.CreatePlaneByThreePoints(pt1, pt2, pt3)
Dim otherNode As Node = getOtherNode(nd)
Dim otherMidsurface = otherNode.midsuface
If Not otherMidsurface Is Nothing Then
Dim out1 As ObjectsEnumerator = transGeom.SurfaceSurfaceIntersection(plane, otherMidsurface.Faces.Item(1).Geometry(), 0.01) ' plane.IntersectWithSurface(otherMidsurface.Faces(1).Geometry())
If out1.Count > 0 Then
Dim workplane As WorkPlane = oCompDef.WorkPlanes.AddByPlaneAndOffset(plane, 0.0)
Dim sketch As PlanarSketch = oCompDef.Sketches.Add(workplane, False)
Dim line As Line = out1.Item(1)
midcurveProfile = sketch.Profiles.Item(1)
End If
End If
End Sub
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
You may consider oSketch3d.IntersectionCurves.Add method that is the most powerful if you need to get the intersection of two surfaces.
The following sample creates 3d intersection curve that could be a) used as is or b) projected to the planar sketch created on the top face.
Sub SketchWithIntersectionCurve() Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument Dim oDef As PartComponentDefinition Set oDef = oDoc.ComponentDefinition 'top face (in this sample - by index) Dim oFace As Face Set oFace = oDef.SurfaceBodies.Item(1).Faces.Item(4) 'cutting surface Dim oSurf As WorkSurface Set oSurf = oDef.WorkSurfaces.Item(1) '3d intersection curve with the top face Dim oSketch3d As Sketch3D Set oSketch3d = oDef.Sketches3D.Add Dim oIntersectionCurve As IntersectionCurve Set oIntersectionCurve = oSketch3d.IntersectionCurves _ .Add(oSurf.SurfaceBodies.Item(1), oFace) 'it is possible to project all intersection surve 'segments to the planar sketch Dim oSketch2d As PlanarSketch Set oSketch2d = oDef.Sketches.Add(oFace, False) Dim oEntity3d As SketchEntity3D Dim oEntity2d As SketchEntity For Each oEntity3d In oIntersectionCurve.SketchEntities Set oEntity2d = oSketch2d.AddByProjectingEntity(oEntity3d) Next Beep End Sub
cheers,
I've attached the part model that was used for this demo.
I have uploaded my project and a video describing problem at
https://drive.google.com/file/d/0B9ZSXyeZHd37M1FJTi0ydk1MZzA/view?usp=sharing
https://drive.google.com/file/d/0B9ZSXyeZHd37YTNwT25hRUFjX3c/view?usp=sharing
Can you have a look at the function fillMidcurvesData() and let me know if I am doing something wrong?
The first problem with your code – IntersectionCurves.Add() method does not accept Face.Geometry type argument. This can be one of the following: SurfaceBody, Face, WorkPlane or 2D sketch curve object. Seehelp for further details.
If Not otherMidsurface Is Nothing Then Dim oSketch3d As Sketch3D = oCompDef.Sketches3D.Add Dim oIntersectionCurve As IntersectionCurve = oSketch3d.IntersectionCurves _ .Add(otherMidsurface.Faces.Item(1).Geometry(), f.Geometry())
The second potential problem you should check – if both arguments are valid faces for this operation. (I can’t verify this).
If I interrupt execution of your code just before Sketch3D creation and then run my VBA test with acceptable SurfaceBody objects then I get correct 3d sketch intersection lines.
Sub SketchWithIntersectionCurve_2() Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument Dim oDef As PartComponentDefinition Set oDef = oDoc.ComponentDefinition 'Blue box surface body Dim oBlueBoxBody As SurfaceBody Set oBlueBoxBody = oDef.SurfaceBodies.Item(1) '3d intersection curve with the top face Dim oSketch3d As Sketch3D Set oSketch3d = oDef.Sketches3D.Add 'vertical cutting surface Dim oSurf1 As WorkSurface Set oSurf1 = oDef.WorkSurfaces.Item(1) 'horizontal cutting surface Dim oSurf2 As WorkSurface Set oSurf2 = oDef.WorkSurfaces.Item(2) Dim oIntersectionCurve1 As IntersectionCurve Set oIntersectionCurve1 = oSketch3d.IntersectionCurves _ .Add(oSurf1.SurfaceBodies.Item(1), oBlueBoxBody) Dim oIntersectionCurve2 As IntersectionCurve Set oIntersectionCurve2 = oSketch3d.IntersectionCurves _ .Add(oSurf2.SurfaceBodies.Item(1), oBlueBoxBody) Beep End Sub
Here are both intersection lines:
cheers,
Your post provided me with a good solution. Thank you very much! But I have a question. When I defined "Dim oIntersectionCurve As IntersectionCurve" and used “oSketch3D.IntersectionCurves.Add()” method, there is a error showing that "user-defined type not defined"? My Inventor edition is "Autodesk Inventor Professional 2012". The following is the code.
Sub blade()
Dim oapp As Inventor.Application
Set oapp = ThisApplication
Dim oDoc As PartDocument
Set oDoc = oapp.ActiveDocument
Dim oCompDef As ComponentDefinition
Set oCompDef = oDoc.ComponentDefinition
Dim otg As TransientGeometry
Set otg = oapp.TransientGeometry
Dim oSketch3D As Sketch3D
Set oSketch3D = oCompDef.Sketches3D.Add
Dim oFace As Face
Set oFace = oCompDef.Features.Item(1).SurfaceBodies.Item(1).Faces.Item(3)
Dim oWorkPlane5 As WorkPlane
Set oWorkPlane5 = oCompDef.WorkPlanes.Item(5)
oWorkPlane5.Visible = True
Dim oWorkPlane6 As WorkPlane
Set oWorkPlane6 = oCompDef.WorkPlanes.Item(6)
oWorkPlane6.Visible = True
Dim Distance As Double
Distance = 5
Dim InsertWorkPlane As WorkPlane
Set InsertWorkPlane = oCompDef.WorkPlanes.AddByPlaneAndOffset(oWorkPlane5, Distance)
Dim oIntersectionCurve As IntersectionCurve
Set oIntersectionCurve = oSketch3D.IntersectionCurves.Add(oCompDef.Features.Item(1).SurfaceBodies.Item(1).Faces.Item(3), _
oWorkPlane5)
End Sub
Thank you very much!!