Create Project Geometry, Offset and Extrude using ilogic

Create Project Geometry, Offset and Extrude using ilogic

murugasubi
Enthusiast Enthusiast
1,528 Views
2 Replies
Message 1 of 3

Create Project Geometry, Offset and Extrude using ilogic

murugasubi
Enthusiast
Enthusiast

Hi Dear,

I have a part, I want to create project geometry on edges and offset the edges to 1 inch and extrude the sketch. Please refer to the attached image A and B. I want to create image B.

 

I used the below codes, but could not complete the code. Please help.

 

Sub Main
Dim
oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument Dim oCompDef As PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition Dim oSketches As PlanarSketches = ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches Dim oSketch1 As PlanarSketch oSketch1 = oSketches("Sketch1") 'I have used the existing sketch to extrude
Dim oProfile As Profile oProfile = oSketch1.Profiles.AddForSolid ' Create a base extrusion 1 inch thick. Dim oExtrudeDef As ExtrudeDefinition oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation) Call oExtrudeDef.SetDistanceExtent(1, kNegativeExtentDirection) Dim oExtrude As ExtrudeFeature oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef) Dim oFrontFace As Face oFrontFace = oExtrude.StartFaces.Item(1)
'Code not working from here Dim oSketch2 As PlanarSketch oSketch2 = oCompDef.Sketches.Add(oFrontFace) Dim featEdge As Edge For Each featEdge In oFrontFace.Edges Call oSketch2.AddByProjectingEntity(featEdge) Next
end sub

 

0 Likes
Accepted solutions (1)
1,529 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

Your code works as expected.

I just recommend you to modify this line of code to the following form. Avoid to use active document multiple times, because it may be changed.

 

 

...
Dim oSketches As PlanarSketches = oCompDef.Sketches
...

 

 

and then you can use this for rest of your task. Here is used simpler version for projecting all face edges.

 

...

'Code not working from here
Dim oSketch2 As PlanarSketch

If False Then
    oSketch2 = oCompDef.Sketches.Add(oFrontFace)

    Dim featEdge As Edge
    For Each featEdge In oFrontFace.Edges
        Call oSketch2.AddByProjectingEntity(featEdge)
    Next
Else
    'Simpler version
    oSketch2 = oCompDef.Sketches.Add(oFrontFace, True)
End If

Dim entitiesForOffset As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
entitiesForOffset.Add(oSketch2.SketchLines(1))

Dim offsetDistance As Double = 1
Dim offsetDirection As Boolean = True
Dim offsetedEntities = oSketch2.OffsetSketchEntitiesUsingDistance(entitiesForOffset, offsetDistance, offsetDirection, True, True)

Dim profile2 = oSketch2.Profiles.AddForSolid(True)
Dim oExtrudeDef2 = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile2, PartFeatureOperationEnum.kJoinOperation)
Dim oExtrude2 = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef2)

 

 

Message 3 of 3

murugasubi
Enthusiast
Enthusiast

Thanks a lot Michael. Navara

Code working well.. I really appreciate your help and respect your opinion..

 

0 Likes