Hello,
I want to offset sketchline which is drawed by "AddByProjectingEntity" of a face's Edge, when I use "OffsetSketchEntitiesUsingPoint" there is error,this is my code, it is very sample, can you help me!
Public Sub erer()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oFace As Face
Set oFace = oDoc.SelectSet(1)
Dim oCompDef As PartComponentDefinition
Set oCompDef = oDoc.ComponentDefinition
Dim oSketch2 As PlanarSketch
Set oSketch2 = oCompDef.Sketches.Add(oFace)
Dim oEndLine As SketchEntity
Dim Oedge As Edge
Dim oCollection As ObjectCollection
Set oCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each Oedge In oFace.Edges
Set oEndLine = oSketch2.AddByProjectingEntity(Oedge)
Next
oCollection.Add oEndLine
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
Dim oOffsetPoint As Point2d
Set oOffsetPoint = oTransGeom.CreatePoint2d(0, 3)
Call oSketch2.OffsetSketchEntitiesUsingPoint(oCollection, oOffsetPoint, True)
This looks like an API issue for the method, I will log this. A workaround is to add all the sketch entities to the collection for creating offset like below:
Public Sub erer() Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument Dim oFace As Face Set oFace = oDoc.SelectSet(1) Dim oCompDef As PartComponentDefinition Set oCompDef = oDoc.ComponentDefinition Dim oSketch2 As PlanarSketch Set oSketch2 = oCompDef.Sketches.Add(oFace) Dim oEndLine As SketchEntity Dim oEdge As Edge Dim oCollection As ObjectCollection Set oCollection = ThisApplication.TransientObjects.CreateObjectCollection For Each oEdge In oFace.Edges Set oEndLine = oSketch2.AddByProjectingEntity(oEdge) oCollection.Add oEndLine Next 'oCollection.Add oEndLine Dim oTransGeom As TransientGeometry Set oTransGeom = ThisApplication.TransientGeometry Dim oOffsetPoint As Point2d Set oOffsetPoint = oTransGeom.CreatePoint2d(0, 3) Call oSketch2.OffsetSketchEntitiesUsingPoint(oCollection, oOffsetPoint, False) End Sub
张工您好,
请原谅我用中文,因为我都发帖好久了,都没有老理我,您回复的代码 和我好像是一样的?我一般选择的面的轮廓都是方的或是圆的,都是要向外偏移50mm,这个又怎么做呢!
So your requirement is to create a profile which is bigger than the original one with offset of 50 mm, I think you can try the OffsetSkechEntitiesUsingDistance for this requirement, but you need to determine the direction for outer/inner of the sketch profile so you can then know how to specify the third argument NaturalOffsetDirection in the function. To determine the direction for the outer/inner of the profile, I suggest that you can do it like below:
1. Create a Profile based on the closed sketch entities which are connected end-to-end, and remember its area, let me call it Area1.
2. In a transaction you can use the OffsetSkechEntitiesUsingDistance to create a offet based on the sketch entities in step#1, and then create another profile with the newly created sketch entities, and then get its area, let me call it Area2.
3. Compare the Area2 with Area1, and if the Area2 > Area1, then the newly created profile in step#2 is bigger and this is what you need, then we can end the transaction.
4. If the Area2 < Area1, then the newly created profile is smaller and we need to abort the transaction, and then call the OffsetSkechEntitiesUsingDistance to create sketch entities with specifying flipped direction for NaturalOffsetDirection.
Hope the suggestion works for you.