Auto Ordinate Dimensions

Auto Ordinate Dimensions

Anonymous
Not applicable
9,753 Views
21 Replies
Message 1 of 22

Auto Ordinate Dimensions

Anonymous
Not applicable

I'm trying to use iLogic or VBA to add ordinate dimensions to a drawing. This picture explains it.help.png

 

Here is the code I'm working with so far.

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oActiveSheet As Sheet
oActiveSheet = oDrawDoc.ActiveSheet

Dim oIntentCollection As ObjectCollection
oIntentCollection = ThisApplication.TransientObjects.CreateObjectCollection

' Get all the selected drawing curve segments.
Dim oDrawingCurveSegment As DrawingCurveSegment
Dim oDrawingCurve As DrawingCurve

For Each oDrawingCurveSegment In oDrawDoc.SelectSet
    
    ' Set a reference to the drawing curve.
    oDrawingCurve = oDrawingCurveSegment.Parent
    
    Dim oDimIntent As GeometryIntent
    oDimIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)
    
    Call oIntentCollection.Add(oDimIntent)
Next

' Set a reference to the view to which the curve belongs.
Dim oDrawingView As DrawingView
oDrawingView = oDrawingCurve.Parent

'  a reference to the ordinate dimensions collection.
Dim oOrdinateDimensions As OrdinateDimensions
oOrdinateDimensions = oActiveSheet.DrawingDimensions.OrdinateDimensions

' Determine the placement point
Dim oPlacementPoint As Point2d
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left - 5, oDrawingView.Center.Y)

' Create a vertical ordinate set dimension.
Dim oOrdinateSet As OrdinateDimensionSet
oOrdinateSet = OrdinateDimensionSet.AddMember(oIntentCollection)


 

 

Any help is appreciated.

0 Likes
Accepted solutions (2)
9,754 Views
21 Replies
Replies (21)
Message 21 of 22

mbaltazarJTZL6
Explorer
Explorer

Hello,

I've tried to use lines instead of drill holes, but it doesn't work. Do you know how to change it so it's done in lines, something like this one I'm attaching?

0 Likes
Message 22 of 22

BM_Ashraf
Advocate
Advocate
Accepted solution

Hi, 

The previous script is a VBA Code and you are using it in ilogic. 

Here is the iLogic one

Public Sub Main()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
    
    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
    
    Dim oDoc As Document = oActiveSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument
    
    If oDoc.DocumentType = kAssemblyDocumentObject Then
    
        '   a reference to the drawing curve segment.
        ' This assumes that a linear drawing curve is selected.
        Dim oDrawingCurveSegment As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select start line to find occurrence")
        
        '   a reference to the drawing curve.
        Dim oDrawingCurve As DrawingCurve = oDrawingCurveSegment.Parent
        
        Dim oReferDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
        
        Dim pt As WorkPoint = oReferDef.WorkPoints.Item(1)
        
        Call oActiveSheet.DrawingViews.Item(1).SetIncludeStatus(pt, True)
        
        If Not oDrawingCurve.CurveType = CurveTypeEnum.kLineSegmentCurve Then
            MsgBox ("A linear curve should be selected for this sample.")
            Exit Sub
        End If
        
        Dim oCenterMark As Centermark = oActiveSheet.Centermarks.Item(oActiveSheet.Centermarks.Count)
        ' Create point intents to anchor the dimension to.
        Dim oDimIntent  As GeometryIntent = oActiveSheet.CreateGeometryIntent(oCenterMark, kCenterPointIntent)
        
        '   a reference to the view to which the curve belongs.
        Dim oDrawingView As DrawingView= oDrawingCurve.Parent
        
        ' If origin indicator has not been already created, create it first.
        If Not oDrawingView.HasOriginIndicator Then
            ' The indicator will be located at the start point of the selected curve.
            Call oDrawingView.CreateOriginIndicator(oDimIntent)
        End If
        
        '   a reference to the ordinate dimensions collection.
        Dim oOrdinateDimensions As OrdinateDimensions = oActiveSheet.DrawingDimensions.OrdinateDimensions
        
        Dim oTextOrigin  As Point2d
        Dim DimType As DimensionTypeEnum
        
        ' Selected curve is vertical or at an angle.
        DimType = DimensionTypeEnum.kVerticalDimensionType
        
        '   the text points for the 2 dimensions.
        
         oTextOrigin = ThisApplication.TransientGeometry.CreatePoint2d(oCenterMark.Position.X, oCenterMark.Position.Y - 2)
        
        ' Create the first ordinate dimension.
        Dim oOrdinateDimension1 As OrdinateDimension = oOrdinateDimensions.Add(oDimIntent, oTextOrigin, DimType)
        
        Dim LArray() As String
        LArray = Split(oDrawingCurve.ModelGeometry.ContainingOccurrence.Name, ":")
        
        Dim occ As ComponentOccurrence
        For Each occ In oReferDef.Occurrences
            Dim occName() As String
            occName = Split(occ.Name, ":")
            If occName(0) = LArray(0) Then
                 pt = occ.Definition.WorkPoints.Item(1)
                
                Dim oProxy As WorkPointProxy
                Call occ.CreateGeometryProxy(pt, oProxy)
                
                Call oActiveSheet.DrawingViews.Item(1).SetIncludeStatus(oProxy, True)
                
                 oCenterMark = oActiveSheet.Centermarks.Item(oActiveSheet.Centermarks.Count)
                
                Dim oIntent As GeometryIntent
                 oIntent = oActiveSheet.CreateGeometryIntent(oCenterMark, kCenterPointIntent)
                
                Dim origin As Point2d
                 origin = ThisApplication.TransientGeometry.CreatePoint2d(oCenterMark.Position.X, oCenterMark.Position.Y - 2)
                
                Call oOrdinateDimensions.Add(oIntent, origin, DimType)
            End If
        Next
         
    
    Else
        MsgBox ("Referenced document is not an assembly document")
    End If
  
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!