11-07-2023
07:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-07-2023
07:12 PM
See below code this was actually easier than I thought. I was missing one crucial piece which was to pass the native face instead of the proxy face to the workplane creation. everything else is as you had it for creation inside the part environment.
How to get the correct face
Dim oFaceProxy As FaceProxy = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFacePlanarFilter, "Pick Planar Face")
Dim occ As ComponentOccurrence = oFaceProxy.Parent.Parent
Dim partDef As PartComponentDefinition = occ.Definition
Dim partDoc As PartDocument = partDef.Document
Dim oFace As Face = oFaceProxy.NativeObject
Working Code, I only tested it as far as workplane creation so hopefully every thing else works.
Dim oFaceProxy As FaceProxy = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFacePlanarFilter, "Pick Planar Face")
Dim occ As ComponentOccurrence = oFaceProxy.Parent.Parent
Dim partDef As PartComponentDefinition = occ.Definition
Dim partDoc As PartDocument = partDef.Document
Dim oFace As Face = oFaceProxy.NativeObject
If partDoc.DocumentType = kPartDocumentObject Then 'checks is active doc is a part doc
Dim oPlane As WorkPlane
Offset = (-15.88 / 10) 'offset of groove start from end of Pipe, convert units to mm
oPlane = partDoc.ComponentDefinition.WorkPlanes.AddByPlaneAndOffset(oFace, (Offset)) 'this is where the error is flagged
Dim oSketch As PlanarSketch
oSketch = partDoc.ComponentDefinition.Sketches.Add(oPlane, False)
Dim oCompdef As PartComponentDefinition
oCompdef = partDoc.ComponentDefinition
cent = oSketch.AddByProjectingEntity(oCompdef.WorkPoints.Item("Center Point"))
Dim oCircle As SketchCircle
'create inner circle
If Parameter("G_H") >20 Then groove_depth = 1.42
If Parameter("G_H") >27 Then groove_depth = 1.6
If Parameter("G_H") >61 Then groove_depth = 1.98
If Parameter("G_H") >101 Then groove_depth = 2.11
'set circle radii
OuterCircleRad = (Parameter("G_H") / 2)
InnerCircleRad = (OuterCircleRad - groove_depth)
Dim oCircle1 As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(cent, (OuterCircleRad / 10)) 'Outer circle, convert units to mm
Dim oCircle2 As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(cent, (InnerCircleRad / 10)) 'inner circle, convert units to mm
Dim oProfile = oSketch.Profiles.AddForSolid
oExtruderDef = oCompdef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
' set groove width to suit pipe dia
If Parameter("G_H") > 48.3 Then GrooveCut = 8.74 Else GrooveCut = 7.14
oExtruderDef.SetDistanceExtent((GrooveCut / 10), kNegativeExtentDirection) 'groove width /10 to convert units to mm
oExtrude = oCompdef.Features.ExtrudeFeatures.Add(oExtruderDef)
For Each oWorkPlane In partDoc.ComponentDefinition.WorkPlanes
oWorkPlane.Visible = False
Next
Else
MessageBox.Show("This iLogic only works on Part Files", "VSVQ iLogic")
End If
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan
Or if this helped you, please, click (like)
Regards
Alan