Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

ACCESSING Dimension Intersection with VBA

inulobo
Advocate

ACCESSING Dimension Intersection with VBA

inulobo
Advocate
Advocate

When I need to do an intersection dimension I usually click dimension then select the first line, right-click and select intersection, select the second line, then select the third line to dimension off of. How do I automate this. I have found similar ideas but they are a little more complex than what I wanted to do. See the image below for what I mean by the intersection option. Also trying to do this specifically with a macro and not an ilogic rule.

 

inulobo_0-1606878241649.png

 

0 Likes
Reply
Accepted solutions (1)
725 Views
3 Replies
Replies (3)

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @inulobo 

What you need to do is to create a geometry intent for the intersection point between the two drawing curves.

Here's an example:

Sub IntersectionDimExample()

'Get the active sheet
Dim oSheet As Sheet
Set oSheet = ThisApplication.ActiveDocument.ActiveSheet

'Get the curves for intersection point
Dim oCurve1 As DrawingCurve
Set oCurve1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick first intersection curve").Parent
Dim oCurve2 As DrawingCurve
Set oCurve2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick second intersection curve").Parent

'Create GeometryIntent for intersection
Dim oIntersectionIntent As GeometryIntent
Set oIntersectionIntent = oSheet.CreateGeometryIntent(oCurve1, oCurve2)

'Get curve to set dimension to
Dim oCurve3 As DrawingCurve
Set oCurve3 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick curve to dimension to").Parent

'Create Geometry intent for that curve
Dim oCurveIntent As GeometryIntent
Set oCurveIntent = oSheet.CreateGeometryIntent(oCurve3)

'Create a text origin point for dimension
Dim oPt As Point2d
Set oPt = oIntersectionIntent.PointOnSheet
Dim oVector As Vector2d
Set oVector = oPt.VectorTo(oCurve3.MidPoint)
Call oVector.ScaleBy(1 / 2)
Call oPt.TranslateBy(oVector)

'Create the dimension
Dim oDim As LinearGeneralDimension
Set oDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPt, oIntersectionIntent, oCurveIntent)

'Arrange the dimension
Dim oCol As ObjectCollection
Set oCol = ThisApplication.TransientObjects.CreateObjectCollection
Call oCol.Add(oDim)
Call oSheet.DrawingDimensions.Arrange(oCol)

End Sub

 The macro will ask you to first pick the two curves that you want to get the intersection point of. Then pick a third curve that you want to create the dimension from the intersection point to.

 

Notice how I create the intersectionpoint geometry intent by calling CreateGeometryIntent using the two curves as arguments :slightly_smiling_face:

inulobo
Advocate
Advocate

Hey, thank you for explaining it to me. I was struggling to get it to work the way I needed to prior. I have used it a few times now. I noticed that sometimes the dimension is thrown all the way to the other side of the part when I do an intersection on the left side of the part view. Why does it do that. See image below.

 

inulobo_0-1606920930957.png

 

0 Likes

JhoelForshav
Mentor
Mentor

@inulobo 

Yeah, I just wrote you an example to get the intersection point. This code places the dimension text exactly between the intersectionpoint and the midpoint of the curve we set the dimension to. Then it calls the ordinate method which will just move the dimension text somewhere outside of the view at an appropriate distance...

0 Likes