D.S

adndevblog.typepad.com

Inventor API: Create constraints for 3D Sketch - Manufacturing DevBlog

Inventor API: Create constraints for 3D Sketch - Manufacturing DevBlog Manufacturing DevBlog The resource for software developers working with Design, Lifecycle and Simulation technologies from Autodesk. Home Subscribe Follow Useful Links Autodesk About this Blog « Inventor API: Change the mirrored state of a derived part | Main | Inventor API: Check Visibility of Components in Drawing View » 07/30/2013 Inventor API: Create constraints for 3D Sketch by Vladimir Ananyev Q: I need an example of creating constraints for Sketch3D entities, and I also need to control these entities through parameters. How can this be done using the API? A: Constraints and dimensions of Sketch3D are similar to those of Sketch 2D. Here is a VBA example. The code will add a new Sketch3D object to an existing Part, then create two lines, add a parallel constraint between them and finally add a length constraint to one of the lines. You can then use the parameter of the length constraint to drive programmatically the dimension of the constrained line. Note: a part document needs to be the active.   Sub AddSketch3DConstraints()     Dim oDoc As PartDocument   Set oDoc = ThisApplication.ActiveDocument     Dim oCompDef As PartComponentDefinition   Set oCompDef = oDoc.ComponentDefinition     'Add a new Sketch3D   Dim oSketch3d As Sketch3D   Set oSketch3d = oCompDef.Sketches3D.Add     Dim oTG As TransientGeometry   Set oTG = ThisApplication.TransientGeometry     'Add two lines to the sketch   Dim oLine1 As SketchLine3D   Dim oLine2 As SketchLine3D     Set oLine1 = oSketch3d.SketchLines3D _     .AddByTwoPoints(oTG.CreatePoint(0, 0, 0), _                     oTG.CreatePoint(10, 10, 10))   Set oLine2 = oSketch3d.SketchLines3D _     .AddByTwoPoints(oTG.CreatePoint(0, 10, 0), _                     oTG.CreatePoint(10, 15, 15))      ' Create a parallel constraint between the lines   Dim oParallelConstr3D   As ParallelConstraint3D   Set oParallelConstr3D = oSketch3d _     .GeometricConstraints3D.AddParallel(oLine1, oLine2)     ' Create length constraint for line 1   Dim oLineLengthConstr3D As LineLengthDimConstraint3D   Set oLineLengthConstr3D = oSketch3d _     .DimensionConstraints3D.AddLineLength(oLine1)     ' Set Driven Property to False so we are sure   ' Parameter is a ModelParameter   oLineLengthConstr3D.Driven = False     Dim oModelParam As ModelParameter   Set oModelParam = oLineLengthConstr3D.Parameter     'set new value in base units (cm)   oModelParam.value = 15#     End Sub Posted at 01:48 AM in Inventor , Vladimir Ananyev | Permalink | | | Comments Inventor API: Create constraints for 3D Sketch by Vladimir Ananyev Q: I need an example of creating constraints for Sketch3D entities, and I also need to control these entities through parameters. How can this be done using the API? A: Constraints and dimensions of Sketch3D are similar to those of Sketch 2D. Here is a VBA example. The code will add a new Sketch3D object to an existing Part, then create two lines, add a parallel constraint between them and finally add a length constraint to one of the lines. You can then use the parameter of the length constraint to drive programmatically the dimension of the constrained line. Note: a part document needs to be the active.   Sub AddSketch3DConstraints()     Dim oDoc As PartDocument   Set oDoc = ThisApplication.ActiveDocument     Dim oCompDef As PartComponentDefinition   Set oCompDef = oDoc.ComponentDefinition     'Add a new Sketch3D   Dim oSketch3d As Sketch3D   Set oSketch3d = oCompDef.Sketches3D.Add     Dim oTG As TransientGeometry   Set oTG = ThisApplication.TransientGeometry     'Add two lines to the sketch   Dim oLine1 As SketchLine3D   Dim oLine2 As SketchLine3D     Set oLine1 = oSketch3d.SketchLines3D _     .AddByTwoPoints(oTG.CreatePoint(0, 0, 0), _                     oTG.CreatePoint(10, 10, 10))   Set oLine2 = oSketch3d.SketchLines3D _     .AddByTwoPoints(oTG.CreatePoint(0, 10, 0), _                     oTG.CreatePoint(10, 15, 15))      ' Create a parallel constraint between the lines   Dim oParallelConstr3D   As ParallelConstraint3D   Set oParallelConstr3D = oSketch3d _     .GeometricConstraints3D.AddParallel(oLine1, oLine2)     ' Create length constraint for line 1   Dim oLineLengthConstr3D As LineLengthDimConstraint3D   Set oLineLengthConstr3D = oSketch3d _     .DimensionConstraints3D.AddLineLength(oLine1)     ' Set Driven Property to False so we are sure   ' Parameter is a ModelParameter   oLineLengthConstr3D.Driven = False     Dim oModelParam As ModelParameter   Set oModelParam = oLineLengthConstr3D.Parameter     'set new value in base units (cm)   oModelParam.value = 15#     End Sub View the entire comment thread. Please enable JavaScript if you would like to comment on this blog. Search Submit Mfg DevBloggers Adam Nagy Augusto Goncalves Balaji Ramamoorthy Daniel Du Philippe Leefsma Vladimir Ananyev Wayne Brill Xiaodong Liang November 2016 Sun Mon Tue Wed Thu Fri Sat     1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22