Inventor iLogic: Auto-Retrieving 3D Annotations from Part Templates into Assembly Drawing Views

Inventor iLogic: Auto-Retrieving 3D Annotations from Part Templates into Assembly Drawing Views

Anthony5375F
Contributor Contributor
762 Views
5 Replies
Message 1 of 6

Inventor iLogic: Auto-Retrieving 3D Annotations from Part Templates into Assembly Drawing Views

Anthony5375F
Contributor
Contributor

Hello all,

 

I am currently working on an iLogic rule in Autodesk Inventor that aims to automatically retrieve and display 3D annotations (specifically dimensions) from part templates when these parts are used within an assembly. These annotations should automatically appear in the drawing views of that assembly.

The goal is to pre-add dimensions in template parts, and when creating a detailed drawing of a model state containing multiple parts, these dimensions should appear automatically.

 

Here is the scenario:

  1. I have template part files with 3D annotations.
  2. These parts are placed into an assembly.
  3. I create a drawing of this assembly.
  4. I want an iLogic rule that, when run, retrieves the 3D annotations from the parts and shows them in the assembly drawing view.

I have tried several iterations of code, but have been facing various challenges related to the API methods I'm trying to use. Here's a snippet of the latest version:

 

Sub Main
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view")

If oView Is Nothing Then Exit Sub

Dim refDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument

If refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPartDoc As PartDocument = refDoc
RetrieveDimensionsFromPart(oPartDoc, oView)
End If
End Sub

Sub RetrieveDimensionsFromPart(oPartDoc As PartDocument, oView As DrawingView)
Dim dimCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

For Each oAnnotation As ModelAnnotation In oPartDoc.ComponentDefinition.ModelAnnotations
If TypeOf oAnnotation Is ModelDimension Then
dimCollection.Add(oAnnotation)
End If
Next

' Retrieve the dimensions into the drawing view
oView.Parent.DrawingDimensions.GeneralDimensions.Retrieve(oView, dimCollection)
End Sub

Errors and issues encountered:

  • Initially, there were type-related errors, such as 'Annotations' not being defined.
  • Following that, I ran into challenges with members like 'DrawingDimensions' and 'ModelDimensions' not being found.
  • Lastly, the rule runs without errors, but no annotations are retrieved/displayed in the drawing view.

I would greatly appreciate any insights, suggestions, or corrections from anyone familiar with this process or who has tackled similar challenges. I'm sure I'm missing something fundamental, or perhaps there's an entirely different approach I should consider.

Thank you in advance for your time and expertise!

 

 

 

 



0 Likes
763 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @Anthony5375F.  The first thing I see within your code that does not look correct to me, is that you are expecting the direct model document type referenced by the view to be a part.  According to your task description, the view should be directly referencing an assembly, not a part.  Then the part should be represented by a component within that assembly (or one of the assemblies referenced documents).  And when that is the case, I would assume that you would first need to get the 'proxy' of the part's ModelDimension that is within the context (3D model coordinate space) of the assembly.  Then you could supply that proxy as the input for retrieving dimensions into the view.  Unfortunately, I do not see a ModelDimensionProxy as a valid object Type within Inventor's API Object Model right now (using Inventor Pro 2024.0.1).  I see proxy Types of some of the other ModelAnnotation related objects, but not that one, for some reason.  It may still be possible by not specifying the specific object Type, but I have not tried it yet myself.

Edit:  I did not look deep enough for the proxy type object.  ModelDimension is a base type for several more specific types, such as AngularModelDimension, DiameterModelDimension, LinearModelDimension, & RadiusModelDimension.  Those do have a proxy version (AngularModelDimensionProxy, DiameterModelDimensionProxyLinearModelDimensionProxy, RadiusModelDimensionProxy).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Anthony5375F
Contributor
Contributor
Firstly, thank you for your insightful comment regarding my issue. I've tried to implement your suggestions and adapt my code accordingly. However, I'm still facing challenges, particularly around the retrieval of ModelDimensions from parts within an assembly. I've encountered an "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))" while attempting to access the Occurrences of the ComponentDefinition.

Given your familiarity with Inventor 2024 Pro's API, do you have any further advice or potential solutions for this issue? Here's a snippet of the current code for your reference:

' Loop through each component in the assembly.
For Each oComponent As ComponentOccurrence In oAssemblyDoc.ComponentDefinition.Occurrences
' ... (rest of the code for brevity)
Next

I'm particularly interested in any insights you might have around the potential absence of a ModelDimensionProxy object type in Inventor's API Object Model, and if there's a workaround or alternative method that I might have overlooked.



Thanks
Anthony5375F
0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

Hi @Anthony5375F.  I've got to leave, so I sort of threw this together at the last minute, but here is an example iLogic rule you can play around with for the task you are trying to achieve.  It is a bit narrow at the moment, because it only attempts to work with part type components, and only linear model dimensions, but all that can be expanded upon later.  I may check back tomorrow.

Sub Main
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Drawing View.")
	If IsNothing(oObj) OrElse (TypeOf oObj Is DrawingView = False) Then Exit Sub
	Dim oView As DrawingView = oObj
	Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	If oModelDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
	Dim oADoc As AssemblyDocument = oModelDoc
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	If oOccs.Count = 0 Then Exit Sub
	Dim oObjColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.Suppressed Then Continue For
		If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Continue For
		If TypeOf oOcc.Definition Is WeldsComponentDefinition Then Continue For
		Dim oOccDoc As Document = oOcc.Definition.Document
		If oOccDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
		Dim oOccPDoc As PartDocument = oOccDoc
		Dim oMAs As ModelAnnotations = oOccPDoc.ComponentDefinition.ModelAnnotations
		If oMAs.Count = 0 Then Continue For
		Dim oMDs As ModelDimensions = oMAs.ModelDimensions
		If oMDs.Count = 0 Then Continue For
		For Each oMD As ModelDimension In oMDs
			If oMD.Type = ObjectTypeEnum.kLinearModelDimensionObject Then
				Dim oLMD As LinearModelDimension = oMD
				Dim oLMDProxy As LinearModelDimensionProxy = Nothing
				oOcc.CreateGeometryProxy(oLMD, oLMDProxy)
				'now the oLMDProxy object is in the context of this component's parent assembly
				oObjColl.Add(oLMDProxy)
			End If
		Next 'oMD
	Next 'oOcc
	Dim oSheet As Inventor.Sheet = oView.Parent
	Dim oGDims As GeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
	oGDims.Retrieve(oView, oObjColl)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

Anthony5375F
Contributor
Contributor

Hi @WCrihfield 

 

Thank you for taking the time to share your iLogic rule. I've been trying to work with it and appreciate the foundation it provides. I noticed your mention of the code being a bit narrow, focusing on LinearModelDimension objects. Based on that hint, I attempted to adapt the rule to consider all dimensions by iterating through ModelDimensions. Here's what I tried:

Sub Main
' Prompt user to pick a drawing view
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Drawing View.")

' Check if a valid view is selected
If IsNothing(oObj) OrElse (TypeOf oObj Is DrawingView = False) Then Exit Sub

Dim oView As DrawingView = oObj

' Retrieve the document associated with the drawing view
Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument

' Check if the document is an assembly type
If oModelDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub

Dim oADoc As AssemblyDocument = oModelDoc

' Get all component occurrences in the assembly
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences

' Exit if no components are found
If oOccs.Count = 0 Then Exit Sub

' Create a collection to hold dimension proxies
Dim oObjColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

' Loop through each component occurrence in the assembly
For Each oOcc As ComponentOccurrence In oOccs

' Skip suppressed components
If oOcc.Suppressed Then Continue For

' Skip virtual and weld components
If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Continue For
If TypeOf oOcc.Definition Is WeldsComponentDefinition Then Continue For

' Get the document associated with the component occurrence
Dim oOccDoc As Document = oOcc.Definition.Document

' Continue only if the component document is a part type
If oOccDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For

Dim oOccPDoc As PartDocument = oOccDoc

' Get all annotations in the part
Dim oMAs As ModelAnnotations = oOccPDoc.ComponentDefinition.ModelAnnotations

' Skip components with no annotations
If oMAs.Count = 0 Then Continue For

' Loop through each model dimension in the part's annotations
For Each oMD As ModelDimension In oMAs.ModelDimensions

' If the dimension is linear type, create a proxy in the assembly context
If oMD.Type = ObjectTypeEnum.kLinearModelDimensionObject Then
Dim oLMD As LinearModelDimension = oMD
Dim oLMDProxy As LinearModelDimensionProxy = Nothing
oOcc.CreateGeometryProxy(oLMD, oLMDProxy)
' Add the proxy object to the collection
oObjColl.Add(oLMDProxy)
End If
Next 'oMD
Next 'oOcc

' Retrieve dimensions into the drawing view from the collection
Dim oSheet As Inventor.Sheet = oView.Parent
Dim oGDims As GeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
oGDims.Retrieve(oView, oObjColl)
End Sub


  1. Have you faced any issues with the oGDims.Retrieve method, or do you know of constraints that might cause this error?
  2. Any best practices or insights when working with model dimensions in Inventor, especially within assembly documents, would be invaluable.

    To give a clearer picture of the issue and setup, I've added images for reference. You can see both the part level and assembly, as well as drawing images.

 Thank you very much and speak soon 

0 Likes
Message 6 of 6

Anthony5375F
Contributor
Contributor

Hi @WCrihfield,

Thanks for the initial assistance on the iLogic rule. I've been trying to expand upon the rule you provided, but I'm still encountering a few issues. I attached some images in my previous post that might help clarify the situation. Could you possibly take another look when you have some time?

Appreciate your expertise on this matter.

Thank you 

0 Likes