3D model annotation / PMI to 3D model
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All,
I am planning to add 3D annotation to 3D model as Model based definition concept, so for Example i am developing the code into VB .Net to detect the part and add the possible dimensions to my current active parts, below is my code but the dimensional not able to add. could you please check and guide. Thanks
Imports Inventor
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Try
' Connect to an open Inventor session
Dim invApp As Inventor.Application = Marshal.GetActiveObject("Inventor.Application")
' Get the active part document
Dim partDoc As PartDocument = TryCast(invApp.ActiveDocument, PartDocument)
If partDoc Is Nothing Then
Console.WriteLine("No part document is open. Please open a part in Inventor.")
Return
End If
' Call function to add linear dimensions
AddLinearDimension(partDoc)
Console.WriteLine("Linear dimension added successfully.")
Catch ex As Exception
Console.WriteLine("Error: " & ex.Message)
End Try
Console.WriteLine("Press any key to exit...")
Console.ReadKey()
End Sub
Sub AddLinearDimension(ByVal partDoc As PartDocument)
Try
' Get the model annotations object
Dim modelAnnotations As ModelAnnotations = partDoc.ComponentDefinition.ModelAnnotations
' Get the LinearModelDimensions collection
Dim linearDims As LinearModelDimensions = modelAnnotations.LinearModelDimensions
' Get reference geometry (WorkPoints as example)
Dim startWorkPoint As WorkPoint = partDoc.ComponentDefinition.WorkPoints.Item(1)
Dim endWorkPoint As WorkPoint = partDoc.ComponentDefinition.WorkPoints.Item(2)
' Create GeometryIntent for the start and end points
Dim startIntent As GeometryIntent = partDoc.ComponentDefinition.CreateGeometryIntent(startWorkPoint)
Dim endIntent As GeometryIntent = partDoc.ComponentDefinition.CreateGeometryIntent(endWorkPoint)
' Define the annotation plane
Dim annotationPlane As AnnotationPlaneDefinition = modelAnnotations.AnnotationPlanes(1)
' Define the text position (midpoint between start and end work points)
Dim textX As Double = (startWorkPoint.Point.X + endWorkPoint.Point.X) / 2
Dim textY As Double = (startWorkPoint.Point.Y + endWorkPoint.Point.Y) / 2
Dim textZ As Double = (startWorkPoint.Point.Z + endWorkPoint.Point.Z) / 2
Dim textPosition As Point = partDoc.ComponentDefinition.TransientGeometry.CreatePoint(textX, textY, textZ)
' Create the linear dimension definition (Now with correct parameters)
Dim linearDimDef As LinearModelDimensionDefinition = linearDims.CreateDefinition(
startIntent,
endIntent,
annotationPlane,
textPosition,
DimensionTypeEnum.kLinearModelDimensionType
)
' Add the linear dimension to the model
Dim linearDim As LinearModelDimension = linearDims.Add(linearDimDef)
Catch ex As Exception
Console.WriteLine("Error adding dimension: " & ex.Message)
End Try
End Sub
End Module