Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

About OffsetSketchEntitiesUsingPoint

4 REPLIES 4
Reply
Message 1 of 5
582973718
644 Views, 4 Replies

About OffsetSketchEntitiesUsingPoint

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)

Tags (1)
4 REPLIES 4
Message 2 of 5
YuhanZhang
in reply to: 582973718

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

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 5
582973718
in reply to: YuhanZhang

张工您好,

   请原谅我用中文,因为我都发帖好久了,都没有老理我,您回复的代码 和我好像是一样的?我一般选择的面的轮廓都是方的或是圆的,都是要向外偏移50mm,这个又怎么做呢!

Message 4 of 5
582973718
in reply to: YuhanZhang

好像选择轮廓为园的代码没有错误,但是选择方就不行了
Message 5 of 5
YuhanZhang
in reply to: 582973718

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.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report