Add 3D annotations in an unfolded sheet metal part with iLogic

Add 3D annotations in an unfolded sheet metal part with iLogic

vpeuvion
Advocate Advocate
1,656 Views
11 Replies
Message 1 of 12

Add 3D annotations in an unfolded sheet metal part with iLogic

vpeuvion
Advocate
Advocate

Hi

I'm working on 3D annotations and I wrote some code to test and understand how it works.
This code works fine on a sheet metal part when it is bent but does not work on the unfolded part.
I don't understand what is blocking on the unfolded part.
Has anyone encountered this problem before? Any help would be appreciated.
Thank you.

vincent.

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oTG As TransientGeometry= ThisApplication.TransientGeometry
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oEdge As Edge
oEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Line1")

Dim oEdge2 As Edge
oEdge2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Line2")

Dim oFace As Face
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Face")

Dim oGeomIntent1 As GeometryIntent
oGeomIntent1 = oPartDoc.ComponentDefinition.CreateGeometryIntent(oEdge)

Dim oGeomIntent2 As GeometryIntent
oGeomIntent2 = oPartDoc.ComponentDefinition.CreateGeometryIntent(oEdge2)

Dim oAnnotationPlaneDef As AnnotationPlaneDefinition
oAnnotationPlaneDef = oPartDoc.ComponentDefinition.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oFace)

Dim oPoint As Point
oPoint = oTG.CreatePoint(0, 0, 0)

Dim LinearModelDimensionDef As LinearModelDimensionDefinition
LinearModelDimensionDef = oCompDef.ModelAnnotations.ModelDimensions.LinearModelDimensions.CreateDefinition(oGeomIntent1, oGeomIntent2, oAnnotationPlaneDef, oPt, DimensionTypeEnum.kAlignedDimensionType)

Dim LinearModelDim As LinearModelDimension
LinearModelDim = oCompDef.ModelAnnotations.ModelDimensions.LinearModelDimensions.Add(LinearModelDimensionDef)
0 Likes
Accepted solutions (1)
1,657 Views
11 Replies
Replies (11)
Message 2 of 12

WCrihfield
Mentor
Mentor
Accepted solution

Hi @vpeuvion.  I noticed that you established a variable near the top of the code for the SheetMetalComponentDefinition.  But then you are not using that in the two 'GeometryIntent' lines, or the AnnotationPlaneDefinition line.  Then you are using it in the last two linens.  Probably not causing a problem, but could help condense the code a bit.  I see that the error is happening on the last line of the code.  I believe I know why this is happening, but it's a bit difficult to explain.  The 'FlatPattern' object of a sheet metal part is like its own different ComponentDefinition.  It has its own CreateGoemetryIntent method, and its own ModelAnnotations property.  So, if you want to create model annotations in the flat pattern of a sheet metal part, you have to get its flat pattern first.  Does that make sense to you?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 12

theo.bot
Collaborator
Collaborator

Hi @vpeuvion , @WCrihfield is right, when you implement his comments it will work in a flatpattern. I also noticed that you defined oPoint, but in the definition you use oPt. So the values of oPoint won't have influence in the position of your dimension text. 

 

Message 4 of 12

vpeuvion
Advocate
Advocate

Hi @WCrihfield ,

Thank you for your reply. I understand better how it works now.

I modified the code and it works. Thank you.

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oTG As TransientGeometry= ThisApplication.TransientGeometry
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

If Not TypeOf ThisApplication.ActiveEditObject Is FlatPattern Then
Try
	If oCompDef.HasFlatPattern = False Then
		oCompDef.Unfold
	Else
		oCompDef.FlatPattern.Edit
	End If
Catch
End Try
End If

Dim oFlatPattern As FlatPattern
oFlatPattern = ThisApplication.ActiveEditObject

Dim oEdge As Edge
oEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Line1")

Dim oEdge2 As Edge
oEdge2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Line2")

Dim oFace As Face
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Face")

Dim oGeomIntent1 As GeometryIntent
oGeomIntent1 = oFlatPattern.CreateGeometryIntent(oEdge)

Dim oGeomIntent2 As GeometryIntent
oGeomIntent2 = oFlatPattern.CreateGeometryIntent(oEdge2)

Dim oAnnotationPlaneDef As AnnotationPlaneDefinition
oAnnotationPlaneDef = oFlatPattern.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oFace)

Dim oPoint As Point
oPoint = oTG.CreatePoint(0, 0, 0)

Dim LinearModelDimensionDef As LinearModelDimensionDefinition
LinearModelDimensionDef = oCompDef.ModelAnnotations.ModelDimensions.LinearModelDimensions.CreateDefinition(oGeomIntent1, oGeomIntent2, oAnnotationPlaneDef, oPoint, DimensionTypeEnum.kAlignedDimensionType)

Dim LinearModelDim As LinearModelDimension
LinearModelDim = oFlatPattern.ModelAnnotations.ModelDimensions.LinearModelDimensions.Add(LinearModelDimensionDef)
0 Likes
Message 5 of 12

vpeuvion
Advocate
Advocate

Hi @theo.bot ,

Thank you for your comments, I have taken them into account.

0 Likes
Message 6 of 12

_KarlH
Enthusiast
Enthusiast

Having a look at your 3D Annotations iLogic project, that's really well put together. Very interesting! May I ask, is there a method to run that centers the dimension value inbetween arrows, and distances them from their dimension target?

0 Likes
Message 7 of 12

theo.bot
Collaborator
Collaborator

There is a center text option that can be used on the dimensions. Inventor 2023 Help | LinearModelDimension Object | Autodesk

 

oDoc = ThisDoc.Document

'center the text for linear dimensions

For Each oLinDim in oDoc.ComponentDefinition.ModelAnnotations.ModelDimensions.linearmodeldimensions

oLindim.centertext

Next

Message 8 of 12

vpeuvion
Advocate
Advocate

Hi thanks. I have no more information than Theo to give you. I hope you can move forward with your solution.

0 Likes
Message 9 of 12

WCrihfield
Mentor
Mentor

Hi @_KarlH.  I see that one of your two questions was answered above, but as for the "distances them from their dimension target" part, that would be in the value you set to the oPoint variable.  Right now the code above is just using 0,0,0, but you can specify a different location there to specify where you want the text of the dimension to be.  This is a 3D point location, but it will get projected onto the same specified AnnotationPlane that the dimension is being created on.  It may be a bit more complicated to specify a simple offset distance than when dealing with regular 2D dimensions on a drawing, but you may be able to use existing model geometry and or create additional transient geometry to help specify a more accurate location for this.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 12

_KarlH
Enthusiast
Enthusiast

Finally had some more time to re-visit this topic @WCrihfield and @theo.bot 

 

I've found the below code centers 3D Annotations on the part, but fails to work on the SheetMetal Flat Pattern 3D Annotations.

 

oDoc = ThisDoc.Document

'Works on Non-Flat Pattern 3D Annotations, but not Flat Pattern 3D Annotations
For Each oLinDim _	
In oDoc.ComponentDefinition.ModelAnnotations.ModelDimensions.linearmodeldimensions
	oLinDim.centertext
Next

 

I've tried adjusting the Component Definition to suit a flat pattern but without luck.

 

I also reviewed the 3D Annotation Offset element - adjusting the oPoint value with an integer does look to hopefully address what I'm attempting to achieve.

 

 

 

 

Dim oPoint As Point
oPoint = oTG.CreatePoint(-5, 5, 5)

 

 

My challenge here is seeing if I can apply this technique to specifically named 2D Sketch dimensions, that then create Centered 3D Annotations at a specified distance.

 

Alternatively, as 3D Annotations projected from 2D Sketch dimensions copy their exact positioning/centering, it might be easier to tackle the dimensions at the 2D Sketch and then simply project them through to 3D Annotations.

 

Half-way there with this idea, I just find coding in iLogic via Inventor IDE so incredibly frustrating/limiting in comparison to more modern languages (Javascript / C#). I'm used to intelisense spoon feeding me on all occasions, but when coding in iLogic - it's like it flips a coin whether it's going to help or not.

0 Likes
Message 11 of 12

theo.bot
Collaborator
Collaborator

@_KarlH 

 

Make sure you use the Flatpattern in you definition to get access to the model annotations:

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oTG As TransientGeometry= ThisApplication.TransientGeometry
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oLinDim As LinearModelDimension

For Each oLinDim In oCompDef.FlatPattern.ModelAnnotations.ModelDimensions.LinearModelDimensions
	oLinDim.CenterText
Next

 

Message 12 of 12

_KarlH
Enthusiast
Enthusiast

Ahh, thank you kindly @theo.bot - I had one object mistyped that was preventing my code from executing. Very grateful for your help.

0 Likes