Autodesk Inventor Customization
- Start Article
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Any ideas / advice why this macro does not work
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello All, any input would be much apprciated.
The macro crashes on the second last line:
"Call oSketch.DimensionConstraints.AddOffset(olines(1), oLine2, oDimCoords(1), False, False)"
Here is the full macro code:
Option Explicit
Dim oDoc As PartDocument
Dim oDef As PartComponentDefinition
Dim oApp As Inventor.Application
' CONSTANT SIZES FOR MYLAR CREATION
Const Mylar_X_Length = 80 'mm
Const Mylar_Y_Length = 80 'mm
Const Mylar_Thickness = 20 'mm
Const Mylar_Width = 20 'mm
Const Mylar_Fillet = 6 'mm
Const Mylar_MCAllow = 3 'mm
Public Sub L_Mylar()
Dim oSketch As PlanarSketch
Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject, "Z:\TEMPLATES\INVENTOR\Sheet Metal (mm).ipt", True)
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
Dim oCoords(1 To 8) As Point2d
Dim oDimCoords(1 To 5) As Point2d
Dim oArc As SketchArc
Dim oLine As SketchLine
Dim olines(1 To 6)
Dim oLine2 As SketchLine
Set oDef = oDoc.ComponentDefinition
Set oCoords(1) = oTransGeom.CreatePoint2d(0, 0)
Set oCoords(2) = oTransGeom.CreatePoint2d(0, Mylar_Y_Length / 10)
Set oCoords(3) = oTransGeom.CreatePoint2d(Mylar_X_Length / 10, Mylar_Y_Length / 10)
Set oCoords(4) = oTransGeom.CreatePoint2d(Mylar_X_Length / 10, (Mylar_Y_Length - Mylar_Thickness) / 10)
Set oCoords(5) = oTransGeom.CreatePoint2d((Mylar_Thickness + Mylar_Fillet) / 10, (Mylar_Y_Length - Mylar_Thickness) / 10)
Set oCoords(6) = oTransGeom.CreatePoint2d((Mylar_Thickness + Mylar_Fillet) / 10, (Mylar_Y_Length - Mylar_Thickness - Mylar_Fillet) / 10)
Set oCoords(7) = oTransGeom.CreatePoint2d((Mylar_Thickness) / 10, (Mylar_Y_Length - Mylar_Thickness - Mylar_Fillet) / 10)
Set oCoords(8) = oTransGeom.CreatePoint2d((Mylar_Thickness) / 10, 0)
Set oSketch = oDef.Sketches.Add(oDef.WorkPlanes.Item("XY Plane"))
oSketch.Name = "SK_00 - PROFILE"
oSketch.Edit
Set olines(1) = oSketch.SketchLines.AddByTwoPoints(oCoords(1), oCoords(2))
Set olines(2) = oSketch.SketchLines.AddByTwoPoints(olines(1).EndSk
Set olines(3) = oSketch.SketchLines.AddByTwoPoints(olines(2).EndSk
Set olines(4) = oSketch.SketchLines.AddByTwoPoints(olines(3).EndSk
Set oArc = oSketch.SketchArcs.AddByCenterStartEndPoint(oCoord
Set olines(5) = oSketch.SketchLines.AddByTwoPoints(oArc.EndSketchP
Set olines(6) = oSketch.SketchLines.AddByTwoPoints(olines(5).EndSk
Call oSketch.GeometricConstraints.AddPerpendicular(olin
Call oSketch.GeometricConstraints.AddParallel(olines(1)
Call oSketch.GeometricConstraints.AddParallel(olines(1)
Call oSketch.GeometricConstraints.AddParallel(olines(2)
Call oSketch.GeometricConstraints.AddParallel(olines(2)
Call oSketch.GeometricConstraints.AddTangent(olines(4), oArc)
Call oSketch.GeometricConstraints.AddTangent(olines(5), oArc)
Call oSketch.GeometricConstraints.AddGround(olines(1).S
Call oSketch.GeometricConstraints.AddVertical(olines(1)
Set oDimCoords(1) = oTransGeom.CreatePoint2d(-0.5, oCoords(2).Y / 2)
Set oDimCoords(2) = oTransGeom.CreatePoint2d(oCoords(3).X / 2, oCoords(3).Y + 0.5)
Set oDimCoords(3) = oTransGeom.CreatePoint2d(oCoords(3).X + 0.5, oCoords(3).Y - (Mylar_Thickness / 2) / 10)
Set oDimCoords(4) = oTransGeom.CreatePoint2d(Mylar_Thickness / 10 + 0.5, oCoords(3).Y - (Mylar_Thickness / 2) / 10 - 0.5)
Set oDimCoords(5) = oTransGeom.CreatePoint2d((Mylar_Thickness / 2) / 10, -0.5)
Call oSketch.DimensionConstraints.AddOffset(olines(6), olines(2), oDimCoords(1), False, False)
Call oSketch.DimensionConstraints.AddOffset(olines(1), olines(3), oDimCoords(2), False, False)
Call oSketch.DimensionConstraints.AddOffset(olines(2), olines(4), oDimCoords(3), False, False)
Call oSketch.DimensionConstraints.AddRadius(oArc, oDimCoords(4), False)
Call oSketch.DimensionConstraints.AddOffset(olines(1), olines(5), oDimCoords(5), False, False)
Dim oCollection As ObjectCollection
Set oCollection = ThisApplication.TransientObjects.CreateObjectColle
oCollection.Add olines(1)
oCollection.Add olines(2)
oCollection.Add olines(3)
oCollection.Add olines(4)
oCollection.Add oArc
oCollection.Add olines(5)
oCollection.Add olines(6)
Call oSketch.OffsetSketchEntitiesUsingDistance(oCollect
Set oLine2 = oCollection.Item(1)
Call oSketch.DimensionConstraints.AddOffset(olines(1), oLine2, oDimCoords(1), False, False)
oSketch.ExitEdit
End Sub
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i7-2600 CPU @ 3.40GHz
16.0 GB RAM
Nvidia Quadro 600
Autodesk Inventor 2013 Professional Ultimate Design Suite
Re: Any ideas / advice why this macro does not work
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Rob,
I can help a little. oLine2 = oCollection.Item(1), is refering the your original set of lines, not the offset ones. Therefore you're trying to add a dimension from oLines(1) to oLines(1).
I'm afraid I haven't got any spare time at the moment to look at this further. Hope this gives you a starting point at least.
Kind regards
Jon.
If this post helps you, please give kudos.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Re: Any ideas / advice why this macro does not work
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello Jon,
I realised that after I posted and should probably have deleted the post.
But, Is there any way to iterate the offset group and find the line that matches olines(1) (or oline(2) and so on) so that I can add a dimension?
Thanks for you input.
Regards
Rob
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i7-2600 CPU @ 3.40GHz
16.0 GB RAM
Nvidia Quadro 600
Autodesk Inventor 2013 Professional Ultimate Design Suite
Re: Any ideas / advice why this macro does not work
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
When you said 'offset group', did you meant by 'oCollection' in the code? A collection can be iterated like below:
Dim oEachObj as Object
For Each oEachObj in oCollection
Next
If I misunderstood, please feel free to elaborate your question
Xiaodong Liang
Developer Technical Services
Autodesk Developer Network
