Extrude Part Sketch to Selected Face Proxy

Extrude Part Sketch to Selected Face Proxy

Raider_71
Collaborator Collaborator
1,035 Views
8 Replies
Message 1 of 9

Extrude Part Sketch to Selected Face Proxy

Raider_71
Collaborator
Collaborator

Hi I am trying to simulate an Extrude to Face (in the assembly environment) of a sketch from "PartA" to a Face of "PartB". I have tried various object types derived from the selected face proxy but cant seem to get it right.

It fails on the extrusion creation.

Any pointers?

 

 

        Dim oAssy As AssemblyDocument = oApp.ActiveDocument

        Dim oPart As Inventor.PartDocument


        Dim oPartOccurance As ComponentOccurrence
        oPartOccurance = oApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Part")
        If oPartOccurance Is Nothing Then
            Exit Sub
        End If
        oPart = oPartOccurance.ReferencedDocumentDescriptor.ReferencedDocument
        Dim oPartCompDef As PartComponentDefinition = oPart.ComponentDefinition

        Dim oFaceProxy As FaceProxy = Nothing
        oFaceProxy = oApp.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Planar Termination Face")
        If oFaceProxy Is Nothing Then
            Exit Sub
        End If

        Dim oFace As Face
        oFace = oFaceProxy.Geometry

        Dim oSketch As Sketch = oPartCompDef.Sketches.Item("Sketch19")

        Dim oProfile As Profile
        oProfile = oSketch.Profiles.AddForSolid

        Dim oExtrudeDef As ExtrudeDefinition
        oExtrudeDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation)
        oExtrudeDef.SetToExtent(oFace, True)
        Dim oExtrude1 As ExtrudeFeature
        oExtrude1 = oPartCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)


        oAssy.Update2()

 

0 Likes
Accepted solutions (1)
1,036 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

Hi @Raider_71.  Have you tried doing this same exact thing manually?  Did it work?  If you can't do it manually, you most likely can't make it happen by code either.  Generally, you can't 'Join' two different components together with an Extrude command within the context of an assembly.  It usually just gives you the option to 'Cut'.  The exception to that is when you are in-place editing a component within the assembly.  But when editing a component within an assembly, all other components are greyed out, and unavailable for anything other than something like projecting sketch geometry.

Also, within your code you created a Face type variable, then are attempting to set its value from the FaceProxy.Geometry property, which I don't think will work correctly.  To get a Face object from a FaceProxy object, you can use the FaceProxy.NativeObject property.  But generally the 'Geometry' of a regular 'planar' Face object is a Plane object.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

Curtis_Waguespack
Consultant
Consultant

Hi @Raider_71 

 

Give this a try.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oApp As Application
oApp = ThisApplication

Dim oAssy As AssemblyDocument = oApp.ActiveDocument
Dim oPart As Inventor.PartDocument

Dim oPartOccurance As ComponentOccurrence
oPartOccurance = oApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Part")
If oPartOccurance Is Nothing Then
	Exit Sub
End If
oPart = oPartOccurance.ReferencedDocumentDescriptor.ReferencedDocument
Dim oPartCompDef As PartComponentDefinition = oPart.ComponentDefinition

Dim oFace As Face 
oFace = oApp.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Planar Termination Face")
If oFace Is Nothing Then
	Exit Sub
End If

Dim oFaceProxy As FaceProxy = oFace

Dim oFaceNative As Face
oFaceNative = oFaceProxy.NativeObject

Dim oSketch As Sketch = oPartCompDef.Sketches.Item("Sketch19")

Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid

Dim oExtrudeDef As ExtrudeDefinition
oExtrudeDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation)
oExtrudeDef.SetToExtent(oFaceNative, True)
Dim oExtrude1 As ExtrudeFeature
oExtrude1 = oPartCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

oAssy.Update2()

 

EESignature

Message 4 of 9

Raider_71
Collaborator
Collaborator

Thank you @Curtis_Waguespack  and @WCrihfield  for replaying. 

 

Since my post and what was mentioned in your replies, I can understand why my solution is failing. 

I have created a quick video to explain my findings and also my requirement in a bit more detail. I think its better than me typing and trying to explain via text... 😉

 

I have also added the files I used in the video. 

 

Video: https://www.dropbox.com/s/prowfk60aqjh59q/Extrude%20to%20Face.mp4?dl=0

The video is also in the attached zip file for future reference.

 

Thanks for the help so far.

0 Likes
Message 5 of 9

Curtis_Waguespack
Consultant
Consultant

Hi @Raider_71 ,

 

ooops! I just took another look at the example files I used yesterday, and realized that the example I gave was not the same situation you were asking for.  I was working in an assembly with some derived parts, that allowed me to fool myself into thinking that I was getting the result you were after.

 

I think your video touches on the crux of the issue, in that we need to use the proxy face to create a workplane first before. I'll try to take another look at this later.

 

Sorry for the confusion, and thanks for the simple example files and video - Curtis

EESignature

Message 6 of 9

JelteDeJong
Mentor
Mentor

try this:

Dim oApp As Inventor.Application = ThisApplication
Dim oAssy As AssemblyDocument = oApp.ActiveDocument

Dim faceProxyA As FaceProxy = oApp.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select face to extrude")
If faceProxyA Is Nothing Then
    Exit Sub
End If

Dim faceProxyB As FaceProxy = oApp.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select face to extrude to")
If faceProxyB Is Nothing Then
    Exit Sub
End If

Dim faceA As Face = faceProxyA.NativeObject
Dim partDefA As PartComponentDefinition = faceProxyA.ContainingOccurrence.Definition

Dim testEdge As Edge
Dim longDir As UnitVector
Dim longLength As Double = Double.MinValue
For Each testEdge In faceProxyB.Edges
    If testEdge.GeometryType = CurveTypeEnum.kLineSegmentCurve Then
        Dim lengthVec As Vector = testEdge.StartVertex.Point.VectorTo(testEdge.StopVertex.Point)
        If lengthVec.Length > longLength Then
            longLength = lengthVec.Length
            longDir = lengthVec.AsUnitVector
        End If
    End If
Next

If (longDir Is Nothing) Then
    Throw New Exception("Could not find x direction")
    ' there might be a solve if this happens on:
    ' https://modthemachine.typepad.com/my_weblog/assemblies/
End If
Dim xVec As UnitVector = longDir
Dim yVec As UnitVector = faceProxyB.Geometry.Normal.CrossProduct(xVec)
Dim originPoint As Point = faceProxyB.Geometry.RootPoint

Dim transformation = faceProxyA.ContainingOccurrence.Transformation
transformation.Invert()

xVec.TransformBy(transformation)
yVec.TransformBy(transformation)
originPoint.TransformBy(transformation)

Dim toWorkplane As WorkPlane = partDefA.WorkPlanes.AddFixed(originPoint, xVec, yVec)
toWorkplane.Visible = False

Dim sketch As PlanarSketch = partDefA.Sketches.Add(faceA, True)
Dim profile As Profile = sketch.Profiles.AddForSolid()

Dim extFeatures As ExtrudeFeatures = partDefA.Features.ExtrudeFeatures
Dim extrudeDef = extFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kJoinOperation)
extrudeDef.SetToExtent(toWorkplane)
extFeatures.Add(extrudeDef)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 7 of 9

Raider_71
Collaborator
Collaborator

Thank you for the reply @JelteDeJong ! That helps as I missed that "Mod The Machine" post.

This solution gets me almost there. Any idea how to get this workplane to be adaptive? 

0 Likes
Message 8 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

try it like this:

Dim oApp As Inventor.Application = ThisApplication
Dim oAssy As AssemblyDocument = oApp.ActiveDocument

Dim faceProxyA As FaceProxy = oApp.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select face to extrude")
If faceProxyA Is Nothing Then
	Exit Sub
End If

Dim faceProxyB As FaceProxy = oApp.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select face to extrude to")
If faceProxyB Is Nothing Then
	Exit Sub
End If

Dim faceA As Face = faceProxyA.NativeObject
Dim partDefA As PartComponentDefinition = faceProxyA.ContainingOccurrence.Definition

Dim sketch As PlanarSketch = partDefA.Sketches.Add(faceA, True)
Dim profile As Profile = sketch.Profiles.AddForSolid()

Dim oAssyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssyCompDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition
Dim occA As ComponentOccurrence = faceProxyA.ContainingOccurrence
Dim occADef As PartComponentDefinition = occA.Definition
Dim oFaceA As Face = faceProxyA.NativeObject
Dim wpA As WorkPlane = occADef.WorkPlanes.AddByPlaneAndOffset(oFaceA, 0)
wpA.Adaptive = True
wpA.Visible = False
occA.Adaptive = True
Dim oProxyWP As WorkPlaneProxy
Call occA.CreateGeometryProxy(wpA, oProxyWP)


Dim occB As ComponentOccurrence = faceProxyB.ContainingOccurrence
Dim oFace2 As Face = faceProxyB.NativeObject
Dim oProxyFace As FaceProxy
occB.CreateGeometryProxy(oFace2, oProxyFace)
oAssyCompDef.Constraints.AddFlushConstraint(oProxyWP, oProxyFace, 0)


Dim extFeatures As ExtrudeFeatures = partDefA.Features.ExtrudeFeatures
Dim extrudeDef = extFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kJoinOperation)
extrudeDef.SetToExtent(wpA)
extFeatures.Add(extrudeDef)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 9 of 9

Raider_71
Collaborator
Collaborator

@JelteDeJong Thank you for the solution to this. Much appreciated!

0 Likes