Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 518

Create Chamfer Feature in Assembly Document

$
0
0

By Xiaodong Liang

In the last post, we introduced how to create chamfer feature in part document. In an assembly document, we have two choices, either create the feature in assembly context, or create the real feature in part context. Actually, this applies to other types of feature which are supported in assembly document.

For choice 1, we need to input the proxy geometries (say EdgeProxy, FaceProxy) to the methods of chamfer feature. e.g. the code below assumes a face is selected in the assembly document. Since it is in the context of assembly, it is FaceProxy already. The same to the edges of the FaceProxy, they are EdgeProxy.

   Sub createChamferInAssemblyContext_selectedObject()

 

        Dim oDoc As AssemblyDocument

        oDoc = ThisApplication.ActiveDocument

 

        Dim oDef As AssemblyComponentDefinition

        oDef = oDoc.ComponentDefinition

 

        'selected face. in assembly this is a proxy face

        Dim oSelectedFace As FaceProxy

        oSelectedFace = oDoc.SelectSet(1)

 

        Dim oEdgeCol As EdgeCollection

        oEdgeCol = ThisApplication.TransientObjects.CreateEdgeCollection()

 

        'method 1: creates a new ChamferFeature defined by a specified distance

        'the edge from the FaceProxy is proxy edge already.

        oEdgeCol.Add oSelectedFace.Edges(1)

        oEdgeCol.Add oSelectedFace.Edges(2)

 

        Call oDef.Features.ChamferFeatures.AddUsingDistance(oEdgeCol, "0.1 in")

 

        'method 2: creates a new ChamferFeature that is defined by a distance and at a specified angle to an input face

        'the edge from the FaceProxy is proxy edge already.

        oEdgeCol.Clear()

        oEdgeCol.Add oSelectedFace.Edges(3)

        Call oDef.Features.ChamferFeatures.AddUsingDistanceAndAngle(oEdgeCol, oSelectedFace, "0.2 in", 0.5233)

 

        'creates a new ChamferFeature that is defined by two distances

        'the edge from the FaceProxy is proxy edge already.

        oEdgeCol.Clear()

        oEdgeCol.Add oSelectedFace.Edges(4)

        Call oDef.Features.ChamferFeatures.AddUsingTwoDistances(oEdgeCol, oSelectedFace, "0.1 in", "0.2 in")

 

    EndSub

 

If we get the objects of parts firstly, we can convert them to proxy objects by Occurrence.CreateGeometryProxy. Next, similarly to the above, input the proxy geometries to the methods of chamfer feature.

    Sub createChamferInAssemblyContext_objectFromPart()

 

        Dim oDoc As AssemblyDocument

        oDoc = ThisApplication.ActiveDocument

 

        Dim oAssDef As AssemblyComponentDefinition

        oAssDef = oDoc.ComponentDefinition

 

        Dim oOccurrence1 As ComponentOccurrence

        oOccurrence1 = oAssDef.Occurrences(1)

 

        Dim oPart1Def As PartComponentDefinition

        oPart1Def = oOccurrence1.Definition

 

        'get face and edge in part context

        Dim oFaceInPart As Face

        oFaceInPart = oPart1Def.SurfaceBodies(1).Faces(1)

 

        Dim oEdge1 As Edge

        oEdge1 = oFaceInPart.Edges(1)

 

        Dim oEdge2 As Edge

        oEdge2 = oFaceInPart.Edges(2)

 

        Dim oEdge3 As Edge

        oEdge3 = oFaceInPart.Edges(3)

 

        Dim oEdge4 As Edge

        oEdge4 = oFaceInPart.Edges(4)

 

        'create the proxy geometries

        Dim oFaceProxy As FaceProxy

        Call oOccurrence1.CreateGeometryProxy(oFaceInPart, oFaceProxy)

 

        Dim oEdge1Proxy As EdgeProxy

        Call oOccurrence1.CreateGeometryProxy(oEdge1, oEdge1Proxy)

 

        Dim oEdge2Proxy As EdgeProxy

        Call oOccurrence1.CreateGeometryProxy(oEdge2, oEdge2Proxy)

 

        Dim oEdge3Proxy As EdgeProxy

        Call oOccurrence1.CreateGeometryProxy(oEdge3, oEdge3Proxy)

 

        Dim oEdge4Proxy As EdgeProxy

        Call oOccurrence1.CreateGeometryProxy(oEdge4, oEdge4Proxy)

 

 

        Dim oEdgeCol As EdgeCollection

        oEdgeCol = ThisApplication.TransientObjects.CreateEdgeCollection()

 

        'method 1: creates a new ChamferFeature defined by a specified distance

        Call oEdgeCol.Add(oEdge1Proxy)

        Call oEdgeCol.Add(oEdge2Proxy)

 

        Call oAssDef.Features.ChamferFeatures.AddUsingDistance(oEdgeCol, "0.1 in")

 

        'method 2: creates a new ChamferFeature that is defined by a distance and at a specified angle to an input face

 

        oEdgeCol.Clear()

        Call oEdgeCol.Add(oEdge3Proxy)

        Call oAssDef.Features.ChamferFeatures.AddUsingDistanceAndAngle(oEdgeCol, oFaceProxy, "0.2 in", 0.5233)

 

        'creates a new ChamferFeature that is defined by two distances

 

        oEdgeCol.Clear()

        Call oEdgeCol.Add(oEdge4Proxy)

        Call oAssDef.Features.ChamferFeatures.AddUsingTwoDistances(oEdgeCol, oFaceProxy, "0.1 in", "0.2 in")

 

    EndSub

clip_image001

For choice 2, we can manipulate the part definition directly and save the part document. In this code, I found an issue: after the face/edge object in part is used by one chamfer method, they seem to be broken. I have to get the objects again.

Sub createChamferInPartContext()

 

        Dim oDoc As AssemblyDocument

        oDoc = ThisApplication.ActiveDocument

 

        Dim oAssDef As AssemblyComponentDefinition

        oAssDef = oDoc.ComponentDefinition

 

        Dim oOccurrence1 As ComponentOccurrence

        oOccurrence1 = oAssDef.Occurrences(1)

 

        Dim oPart1Def As PartComponentDefinition

        oPart1Def = oOccurrence1.Definition

 

        'get face and edge in part context

        Dim oFaceInPart As Face

        oFaceInPart = oPart1Def.SurfaceBodies(1).Faces(3)

 

        Dim oEdge1 As Edge

        oEdge1 = oFaceInPart.Edges(1)

 

        Dim oEdge2 As Edge

        oEdge2 = oFaceInPart.Edges(2)

 

        Dim oEdgeCol As EdgeCollection

        oEdgeCol = ThisApplication.TransientObjects.CreateEdgeCollection()

 

        'method 1: creates a new ChamferFeature defined by a specified distance

        Call oEdgeCol.Add(oEdge1)

        Call oEdgeCol.Add(oEdge2)

 

        Call oPart1Def.Features.ChamferFeatures.AddUsingDistance(oEdgeCol, "0.1 in")

 

        'method 2: creates a new ChamferFeature that is defined by a distance and at a specified angle to an input face

        ' after the face/edge object in part is used by one chamfer method, they seem to be broken.  have to get the objects again

        oEdgeCol.Clear()

        oFaceInPart = oPart1Def.SurfaceBodies(1).Faces(3)

        Dim oEdge3 As Edge

        oEdge3 = oFaceInPart.Edges(3)

 

        Call oEdgeCol.Add(oEdge3)

        Call oPart1Def.Features.ChamferFeatures.AddUsingDistanceAndAngle(oEdgeCol, oFaceInPart, "0.1 in", 0.5233)

 

        'creates a new ChamferFeature that is defined by two distances

        ' after the face/edge object in part is used by one chamfer method, they seem to be broken.  have to get the objects again

        oEdgeCol.Clear()

        oFaceInPart = oPart1Def.SurfaceBodies(1).Faces(3)

        Dim oEdge4 As Edge

        oEdge4 = oFaceInPart.Edges(4)

        Call oEdgeCol.Add(oEdge4)

        Call oPart1Def.Features.ChamferFeatures.AddUsingTwoDistances(oEdgeCol, oFaceInPart, "0.1 in", "0.2 in")

 

        Call oPart1Def.Document.Save()

 

    EndSub

 

clip_image002


Viewing all articles
Browse latest Browse all 518

Trending Articles