Auto Ordinate Dimensions

Auto Ordinate Dimensions

Anonymous
Not applicable
9,283 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,284 Views
21 Replies
Replies (21)
Message 2 of 22

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please provide sample drawing file to analyse drawing curves? please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 22

Anonymous
Not applicable

Here are the part and drawing documents.

0 Likes
Message 4 of 22

Anonymous
Not applicable

Here is what I have now.

 
Sub Main()
	
	Dim oDrawDoc As DrawingDocument
	oDrawDoc = ThisApplication.ActiveDocument
	
	Dim oActiveSheet As Sheet
	oActiveSheet = oDrawDoc.ActiveSheet
	
	Dim oTG As TransientGeometry
	oTG = ThisApplication.TransientGeometry
	
	Dim oDimIntent As GeometryIntent

	Dim Entity As DrawingCurveSegment
	Entity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a kDrawingCurveSegmentFilter")
	
	' Get all the selected drawing curve segments.
	Dim oDrawingCurve As DrawingCurve
	oDrawingCurve = Entity.Parent
	
	Dim oDrawingView As DrawingView
	oDrawingView = oDrawingCurve.Parent
	
	Dim oDCE As DrawingCurvesEnumerator
	oDCE = oDrawingView.DrawingCurves()
	
	Dim oODS As OrdinateDimensions
	oODS = oActiveSheet.DrawingDimensions.OrdinateDimensions
	
	Dim oOD As OrdinateDimension
	
	Dim j As Integer
	Dim CurveTypeCount(3) As Integer
	CurveTypeCount(1)=0
	CurveTypeCount(2)=0
	CurveTypeCount(3)=0
		
	For j = 1 To oDCE.Count()
	
		oDrawingCurve = oDCE.Item(j)
		
		Select Case oDrawingCurve.ProjectedCurveType()
			Case 5252 'kCircleCurve2d 
				CurveTypeCount(1)=CurveTypeCount(1) + 1
			Case 5253 'kCircularArcCurve2d 
				CurveTypeCount(2)=CurveTypeCount(2) + 1
			Case 5251 'kLineSegmentCurve2d 
				CurveTypeCount(3)=CurveTypeCount(3) + 1
		End Select
		
		If oDrawingCurve.ProjectedCurveType() = 5252  Then'kCircleCurve2d
			
			MessageBox.Show("oDrawingCurve.Type())" & oDrawingCurve.Type(), "kCircleCurve2d") ' kDrawingCurveObject 
			
			oDimIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, oDrawingCurve)

			Dim oTextOrigin1 As Point2d
			oTextOrigin1 = oTG.CreatePoint2d(5, 5)
			MessageBox.Show("oTextOrigin1 initialized")
			
			oOD = oODS.Add( kCenterPointIntent, oTextOrigin1, kHorizontalDimensionType)
			MessageBox.Show("HURRAY IT WORKED!!!!!!!!!!!!")
		End If
	Next
End Sub

 I keep crashing at this line.

oOD = oODS.Add( kCenterPointIntent, oTextOrigin1, kHorizontalDimensionType) 

 I've tried many combinations for theOrdinateDimensions.Add Method.

' Taken from the inventor API
OrdinateDimensions.Add( Intent As GeometryIntent, TextOrigin As Point2d, DimensionType As DimensionTypeEnum, [DimensionStyle] As Variant, [Layer] As Variant ) As OrdinateDimension

 

0 Likes
Message 5 of 22

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Try below iLogic code to automate ordinate dimension.

 

Public Sub Main()
  ' Set a reference to the drawing document.
  ' This assumes a drawing document is active.
  Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

  ' Set a reference to the active sheet.
  Dim oActiveSheet As Sheet
    oActiveSheet = oDrawDoc.ActiveSheet

  '   a reference to the drawing curve segment.
  ' This assumes that a linear drawing curve is selected.
  Dim oDrawingCurveSegment As DrawingCurveSegment
    oDrawingCurveSegment = ThisApplication.CommandManager.Pick(kDrawingCurveSegmentFilter, "Select start line to start ordinate dimension")

  '   a reference to the drawing curve.
  Dim oDrawingCurve As DrawingCurve
    oDrawingCurve = oDrawingCurveSegment.Parent

  If Not oDrawingCurve.CurveType = kLineSegmentCurve Then
    MsgBox ("A linear curve should be selected for this sample.")
    Exit Sub
  End If

  ' Create point intents to anchor the dimension to.
  Dim oDimIntent  As GeometryIntent
    oDimIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, kEndPointIntent)

  '   a reference to the view to which the curve belongs.
  Dim oDrawingView As DrawingView
    oDrawingView = 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.
    oDrawingView.CreateOriginIndicator (oDimIntent)
  End If

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

  Dim oTextOrigin  As Point2d
  Dim DimType As DimensionTypeEnum
  
  ' Selected curve is vertical or at an angle.
  DimType = kHorizontalDimensionType
    
  '   the text points for the 2 dimensions.
    oTextOrigin = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left + 2, oDrawingCurve.StartPoint.Y)
 
  ' Create the first ordinate dimension.
  Call oOrdinateDimensions.Add(oDimIntent, oTextOrigin, DimType)
  
  For Each oDrawingCurve In oDrawingView.DrawingCurves
    If oDrawingCurve.CurveType = kCircleCurve Then
        Dim oIntent As GeometryIntent
          oIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, kCenterPointIntent)
        
        Dim origin As Point2d
          origin = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left + 2, oDrawingCurve.CenterPoint.Y)
        
        Call oOrdinateDimensions.Add(oIntent, origin, DimType)
    End If
  Next
  
    oDrawingCurveSegment = ThisApplication.CommandManager.Pick(kDrawingCurveSegmentFilter, "Select end line to complete ordinate dimension")
  
    oDrawingCurve = oDrawingCurveSegment.Parent
  
  If Not oDrawingCurve.CurveType = kLineSegmentCurve Then
    MsgBox ("A linear curve should be selected for this sample.")
    Exit Sub
  End If
  
    oDimIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, kEndPointIntent)
  
    oTextOrigin = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left + 2, oDrawingCurve.StartPoint.Y)
  
  Call oOrdinateDimensions.Add(oDimIntent, oTextOrigin, DimType)
  
End Sub

On running above code, it prompts to select 2 lines as shown below.

Start line.pngEnd line.pngResult.PNG

On successful completion of code, Result of iLogic code is shown as above.

 

Note: iLogic code is customized for current drawing.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 22

Anonymous
Not applicable

When I run the rule, I get the error code,

  • The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

and under More Info.

  • System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)
  • at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)  
  • at Inventor.CommandManager.Pick(SelectionFilterEnum Filter, String PromptText)
  • at LmiRuleScript.Main()
  • at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
  • at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Neither prompt comes up. I am running Inventor 2017.

 

 

Changing kDrawingCurveSegmentFilter to SelectionFilterEnum.kDrawingCurveSegmentFilter fixed the previous issue.

Now selecting the bottom line results in the  error message "A linear curve should be selected for this sample."

 

 

0 Likes
Message 7 of 22

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@Anonymous,

 

Try below VBA code instead of iLogic code (working procedure is same). iLogic code is wokring in Inventor 2019 but throwing exception on creating origin indicator in Inventor 2017.

Public Sub Main()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet
    
    '   a reference to the drawing curve segment.
    ' This assumes that a linear drawing curve is selected.
    Dim oDrawingCurveSegment As DrawingCurveSegment
    Set oDrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select start line to start ordinate dimension")
    
    '   a reference to the drawing curve.
    Dim oDrawingCurve As DrawingCurve
    Set oDrawingCurve = oDrawingCurveSegment.Parent
    
    
    If Not oDrawingCurve.CurveType = CurveTypeEnum.kLineSegmentCurve Then
        MsgBox ("A linear curve should be selected for this sample.")
    Exit Sub
    End If
    
    ' Create point intents to anchor the dimension to.
    Dim oDimIntent  As GeometryIntent
    Set oDimIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, kEndPointIntent)
    
    '   a reference to the view to which the curve belongs.
    Dim oDrawingView As DrawingView
    Set oDrawingView = 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
    Set oOrdinateDimensions = oActiveSheet.DrawingDimensions.OrdinateDimensions
    
    Dim oTextOrigin  As Point2d
    Dim DimType As DimensionTypeEnum
    
    ' Selected curve is vertical or at an angle.
    DimType = DimensionTypeEnum.kHorizontalDimensionType
    
    '   the text points for the 2 dimensions.
    Set oTextOrigin = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left + 2, oDrawingCurve.StartPoint.Y)
    
    ' Create the first ordinate dimension.
    Dim oOrdinateDimension1 As OrdinateDimension
    Set oOrdinateDimension1 = oOrdinateDimensions.Add(oDimIntent, oTextOrigin, DimType)

    
    For Each oDrawingCurve In oDrawingView.DrawingCurves
    If oDrawingCurve.CurveType = kCircleCurve Then
        Dim oIntent As GeometryIntent
        Set oIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, kCenterPointIntent)
        
        Dim origin As Point2d
        Set origin = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left + 2, oDrawingCurve.CenterPoint.Y)
        
        Call oOrdinateDimensions.Add(oIntent, origin, DimType)
    End If
    Next
    
    Set oDrawingCurveSegment = ThisApplication.CommandManager.Pick(kDrawingCurveSegmentFilter, "Select end line to complete ordinate dimension")
    
    Set oDrawingCurve = oDrawingCurveSegment.Parent
    
    If Not oDrawingCurve.CurveType = kLineSegmentCurve Then
        MsgBox ("A linear curve should be selected for this sample.")
        Exit Sub
    End If
    
    Set oDimIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, kEndPointIntent)
    
    Set oTextOrigin = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left + 2, oDrawingCurve.StartPoint.Y)
    
    Call oOrdinateDimensions.Add(oDimIntent, oTextOrigin, DimType)
  
End Sub

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 8 of 22

Anonymous
Not applicable

This works! Thank you very much for your help.

 

Its interesting how the same code will only work in one environment. The three options between the iLogic rule environment, the iLogic rule environment with Straight VB code selected and the VBA editor environment.

 

So the iLogic environment uses VB.NET and the VBA editor uses VBA?

0 Likes
Message 9 of 22

Anonymous
Not applicable

it is possible to drop the command and select a line automatically because it is always the same. Or place zero and start from there? I have to place the dimensions on some supports. those coming from a configurator so the number and the distances are different

Knipsel.PNG

Point A is always the same plane and is always in the same place on the drawing

Point B is always the same part so can I use a work surface or a work point in my part?


is this possible I am completely stuck on this problem 🙂

0 Likes
Message 10 of 22

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous 

 

Can you please share non confidential Inventor drawing to check the feasibility?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 22

Anonymous
Not applicable

hello

 

attached the modified code without the command. Now it is only the intention to replace the centers with faces with a certain to atribute ... But I get stuck on the 2nd part from  the  for instruction

 

thank you

0 Likes
Message 12 of 22

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

It looks like old drawing is attached in the previous post.

HolesFeature.PNG

Can you please provide non confidential drawing with support?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 13 of 22

Anonymous
Not applicable

no I have changed the code but use it as a test. If you run rule1 you will see ... but I cannot upload my Assembly i can only upload 2 files...  

0 Likes
Message 14 of 22

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Actually, iLogic code is customized to work on particular drawing. If you can provide non confidential full assembly, I can investigate on that.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 15 of 22

Anonymous
Not applicable

Best

in attachment you can see the assembly. I made an example of how it should be on the 2d drawing

 

 

thanks

 

 

 

 

0 Likes
Message 16 of 22

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Sorry for late reply,

 

Attachment downloaded and investigated, it is found that it is series of assembly origin and subsequent origins are belongs to parts. So, ordinate dimension is required for this series of origins.

 

Can you please confirm the requirement to implement the code?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 17 of 22

Anonymous
Not applicable

Yes the intention is that the origin starts at the left corner and between the 2 corners it is the same part and I always need the origin of these parts.

 

thank you very much

0 Likes
Message 18 of 22

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Try below VBA code to create ordinate dimension.On running code, ask to select a line to find out occurrence in assembly document as shown in below image.

 

Selection.png

Public Sub Main()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet
    
    Dim oDoc As Document
    Set oDoc = 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
        Set oDrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select start line to find occurrence")
        
        '   a reference to the drawing curve.
        Dim oDrawingCurve As DrawingCurve
        Set oDrawingCurve = oDrawingCurveSegment.Parent
        
        Dim oReferDef As AssemblyComponentDefinition
        Set oReferDef = oDoc.ComponentDefinition
        
        Dim pt As WorkPoint
        Set pt = 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
        Set oCenterMark = oActiveSheet.Centermarks.Item(oActiveSheet.Centermarks.Count)
        ' Create point intents to anchor the dimension to.
        Dim oDimIntent  As GeometryIntent
        Set oDimIntent = oActiveSheet.CreateGeometryIntent(oCenterMark, kCenterPointIntent)
        
        '   a reference to the view to which the curve belongs.
        Dim oDrawingView As DrawingView
        Set oDrawingView = 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
        Set oOrdinateDimensions = 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.
        
        Set oTextOrigin = ThisApplication.TransientGeometry.CreatePoint2d(oCenterMark.Position.X, oCenterMark.Position.Y - 2)
        
        ' Create the first ordinate dimension.
        Dim oOrdinateDimension1 As OrdinateDimension
        Set oOrdinateDimension1 = 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
                Set pt = occ.Definition.WorkPoints.Item(1)
                
                Dim oProxy As WorkPointProxy
                Call occ.CreateGeometryProxy(pt, oProxy)
                
                Call oActiveSheet.DrawingViews.Item(1).SetIncludeStatus(oProxy, True)
                
                Set oCenterMark = oActiveSheet.Centermarks.Item(oActiveSheet.Centermarks.Count)
                
                Dim oIntent As GeometryIntent
                Set oIntent = oActiveSheet.CreateGeometryIntent(oCenterMark, kCenterPointIntent)
                
                Dim origin As Point2d
                Set 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

Thanks and regards,

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 19 of 22

Anonymous
Not applicable

Best

 

 

thank you very much I have adjusted the code so that it now works with atributes and I no longer have to select the line. Thanks again 🙂

0 Likes
Message 20 of 22

andygleis
Explorer
Explorer

Is their an updated version of this code? I keep getting an error with it

andygleis_0-1740005368041.png

 

 

0 Likes