- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Rich-T
When working through the assembly all workplanes, sketches,faces etc need to be converted to proxies so in the context of the assembly space and not the part.
Any issues implementing just message back. It takes some trial an error. I have the same thing implemented so can share pieces to help you along. Best to give it a crack yourself first as their is more learning opportunities. Start converting one line at a time and object face.
The pick command will actually give the proxy face as an output so thats easy so next is getting its definition which you can get to from the occurrence
Syntax
FaceProxy.ContainingOccurrence() As ComponentOccurrence
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks AA, sadly that's not making any sense to me.
I don't understand how to use a faceproxy to create the offset workplane and similar examples I've found are just confusing me.
If you've got any code that might explain it I'd be very grateful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Rich-T
I wasn't able to make my sample I had work mainly because I hadn't created any workplanes for the groove extrusion. In my case I used project geometry and constructed a sketch and use revolve.
Back to your scenario, trying to create a workplane in the part from the assembly environment was coming back with error not supported. The only way through with this method is to open the part itself and create the workplane in the part environment then close the part. This is very doable with the only snag being passing the selected face to the the workplane creation without the user needing to reselect as that would obviously be unproductive. I will give this a shot tomorrow and see what is possible.
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks AA, much appreciated.
Our current workflow is to open the part and apply the grooves directly to the part model.
So its not too big a deal if we can't do it from within the assembly - but it would be awesome if we could.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thats good.
Its getting stuck on picking up the <G_H> parameter from the selected part.
I thought it'd work with one of occ/partDef/partDoc but I must be using it incorrectly in
If Parameter(occ, "G_H") >20 Then groove_depth = 1.42
if I use the part name like this..
If Parameter("963029 - SCH10 65NB - 200:1", "G_H")
it works fine, but it needs to work whatever the part name is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You can use the below to target the logic parameter. This might fail if the level is too deep.
occ.NameYou can also use the API method directly for parameters see help page here.
Pay attention to the value returned in case its in cm and not your document units.
Dim paramValue As Double = partDef.Parameters.Item("G_H").Value
Or if this helped you, please, click (like)
Regards
Alan