Inventor Customization

Inventor Customization

Reply
Contributor
denis.bourasseau
Posts: 33
Registered: ‎12-13-2012
Message 1 of 2 (298 Views)
Accepted Solution

Bend line projection on a sketch

298 Views, 1 Replies
02-04-2013 12:36 AM

Hello.

Just by selecting a bend line on the flat pattern, I'd like to draw only 2 lines on a sketch (without any border projection, only points) at both ends of the bend line.

I'm sure it can be done via VBA, but don't know how to start for it.

Any idea?

OK, I got it:

 

Sub Marquages()
Dim oPartDoc As PartDocument
Dim oPoint1, oPoint2 As Point2d
Set oPartDoc = ThisApplication.ActiveDocument
Dim oSheetMetalDef As SheetMetalComponentDefinition
Set oSheetMetalDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oFlatPattern As FlatPattern
Set oFlatPattern = oSheetMetalDef.FlatPattern
If oPartDoc.SelectSet.Count = 0 Then
MsgBox "Selectionner un axe de pliage", vbExclamation
End
End If
Dim oBendEdge As Edge
Set oBendEdge = oPartDoc.SelectSet(1)
Dim oSketch As PlanarSketch
Set oSketch = oFlatPattern.Sketches.Add(oSheetMetalDef.FlatPattern.TopFace, False)
oSketch.Name = "Marquages " & oFlatPattern.Sketches.Count
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
Dim oLines(1 To 3) As SketchLine
Set oLines(1) = oFlatPattern.Sketches(1).AddByProjectingEntity(oBendEdge)
Set oPoint1 = oLines(1).Geometry.StartPoint
Set oPoint2 = oLines(1).Geometry.EndPoint
Set oLines(2) = oSketch.SketchLines.AddByTwoPoints(oPoint1, oPoint2)
Call oSketch.GeometricConstraints.AddGround(oLines(2).StartSketchPoint)
Call oSketch.DimensionConstraints.AddTwoPointDistance(oLines(2).StartSketchPoint, oLines(2).EndSketchPoint, kAlignedDim, oPoint1)
oSketch.DimensionConstraints(1).Parameter.Value = 1
Set oLines(3) = oSketch.SketchLines.AddByTwoPoints(oPoint1, oPoint2)
Call oSketch.GeometricConstraints.AddGround(oLines(3).EndSketchPoint)
Call oSketch.DimensionConstraints.AddTwoPointDistance(oLines(3).StartSketchPoint, oLines(3).EndSketchPoint, kAlignedDim, oPoint2)
oSketch.DimensionConstraints(2).Parameter.Value = 1
Call oSketch.GeometricConstraints.AddCollinear(oLines(2), oLines(3))
oLines(1).Delete
End Sub

 

Contributor
denis.bourasseau
Posts: 33
Registered: ‎12-13-2012
Message 2 of 2 (279 Views)

Re : Bend line projection on a sketch

02-04-2013 06:23 AM in reply to: denis.bourasseau

OK, I got it:

 

Sub Marquages()
Dim oPartDoc As PartDocument
Dim oPoint1, oPoint2 As Point2d

Set oPartDoc = ThisApplication.ActiveDocument
Dim oSheetMetalDef As SheetMetalComponentDefinition
Set oSheetMetalDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oFlatPattern As FlatPattern
Set oFlatPattern = oSheetMetalDef.FlatPattern

If oPartDoc.SelectSet.Count = 0 Then
    MsgBox "Selectionner un axe de pliage", vbExclamation
    End
End If

Dim oBendEdge As Edge
Set oBendEdge = oPartDoc.SelectSet(1)

Dim oSketch As PlanarSketch
Set oSketch = oFlatPattern.Sketches.Add(oSheetMetalDef.FlatPattern.TopFace, False)
oSketch.Name = "Marquages " & oFlatPattern.Sketches.Count

Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry

Dim oLines(1 To 3) As SketchLine
Set oLines(1) = oFlatPattern.Sketches(1).AddByProjectingEntity(oBendEdge)

Set oPoint1 = oLines(1).Geometry.StartPoint
Set oPoint2 = oLines(1).Geometry.EndPoint

Set oLines(2) = oSketch.SketchLines.AddByTwoPoints(oPoint1, oPoint2)
Call oSketch.GeometricConstraints.AddGround(oLines(2).StartSketchPoint)
Call oSketch.DimensionConstraints.AddTwoPointDistance(oLines(2).StartSketchPoint, oLines(2).EndSketchPoint, kAlignedDim, oPoint1)
oSketch.DimensionConstraints(1).Parameter.Value = 1

Set oLines(3) = oSketch.SketchLines.AddByTwoPoints(oPoint1, oPoint2)
Call oSketch.GeometricConstraints.AddGround(oLines(3).EndSketchPoint)
Call oSketch.DimensionConstraints.AddTwoPointDistance(oLines(3).StartSketchPoint, oLines(3).EndSketchPoint, kAlignedDim, oPoint2)
oSketch.DimensionConstraints(2).Parameter.Value = 1

Call oSketch.GeometricConstraints.AddCollinear(oLines(2), oLines(3))

oLines(1).Delete
End Sub

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!