11-01-2023
03:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-01-2023
03:26 PM
I have some code (below) to add a groove to a selected pipe end.
It works when editing the part but I want to be able to edit the part from within an assembly and have the rule work.
so the work flow is - when doing a pipework assembly you decide to add a groove to a piece of pipe, double click to edit the part and run the rule.
I'd be grateful for any help you can offer.
'Check if active document is a Part document Dim partDoc = ThisApplication.ActiveEditDocument If partDoc.DocumentType = kPartDocumentObject Then 'checks is active doc is a part doc 'working code Dim oFace = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFacePlanarFilter, "Pick Planar Face") 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
Solved! Go to Solution.