Get Sketch Dimension points

<?xml encoding=”UTF-8″>By Adam Nagy

Each type of dimension might provide information in a different way. So the easiest way to get familiar with what’s available is if you select the entity in the UI and investigate it in VBA: Discover object model 

Here is a VBA sample that will highlight all the points available in case of a TwoLineAngleDimConstraint by creating temporary SketchPoints.  

Sub DeletePoints(c As ObjectCollection)
Dim o As Object
For Each o In c
o.Delete
Next
Call c.Clear
End Sub
Sub GetDimensionGeometry()
' The Sketch needs to be active and a
' two line angle dimension constraint needs
' to be selected in the UI
Dim d As TwoLineAngleDimConstraint
Set d = ThisApplication.ActiveDocument.SelectSet(1)
Dim sps As SketchPoints
Set sps = d.Parent.SketchPoints
Dim sp As SketchPoint
Dim c As ObjectCollection
Set c = ThisApplication.TransientObjects.CreateObjectCollection()
' Anchor points (<strong><span>A1..A5</span></strong>)
Dim pt As Point2d
For Each pt In d.AnchorPoints
Call c.Add(sps.Add(pt))
Next
MsgBox ("AnchorPoints")
Call DeletePoints(c)
' LineOne (<strong><span>L1S, L1E</span></strong>)
Call c.Add(sps.Add(d.LineOne.StartSketchPoint.Geometry))
Call c.Add(sps.Add(d.LineOne.EndSketchPoint.Geometry))
MsgBox ("LineOne")
Call DeletePoints(c)
' LineTwo (<strong><span>L2S, L2E</span></strong>)
Call c.Add(sps.Add(d.LineTwo.StartSketchPoint.Geometry))
Call c.Add(sps.Add(d.LineTwo.EndSketchPoint.Geometry))
MsgBox ("LineTwo")
Call DeletePoints(c)
' DimensionCenterPoint (<strong><span>DC</span></strong>)
Call c.Add(sps.Add(d.DimensionCenterPoint))
MsgBox ("DimensionCenterPoint")
Call DeletePoints(c)
' TextPoint (<span><strong>TP</strong></span>)
Call c.Add(sps.Add(d.TextPoint))
MsgBox ("TextPoint")
Call DeletePoints(c)
End Sub

These are all the points showing:

SketchDimension

Once you got these points you could also measure the distance between them or do other calculations using the Inventor API.


Comments

2 responses to “Get Sketch Dimension points”

  1. Leonard Avatar
    Leonard

    So what tools exist to measure distances between points in a Sketch? As far as I know, I have to perform the trig to calculate that distance.

  2. Each SketchPoint has a Geometry property of type Point2d which has a DistanceTo() function accepting another Point2d as input.
    https://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-61A03C4E-2673-4338-969C-F16B9C8DF838

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading