API Support to promote model dimensions to 3d annotations and/or position them

API Support to promote model dimensions to 3d annotations and/or position them

guilloryt
Advocate Advocate
2,005 Views
10 Replies
Message 1 of 11

API Support to promote model dimensions to 3d annotations and/or position them

guilloryt
Advocate
Advocate

Morning,

 

Would there be API methods to promote model dimensions to 3d annotations. And also after they have been created (either manually or with code) are there api methods to manipulate the position of the 3d annotations.

 

Thanks

Tony

0 Likes
Accepted solutions (1)
2,006 Views
10 Replies
Replies (10)
Message 2 of 11

YuhanZhang
Autodesk
Autodesk

The API ModelDimensions(for 3DA) are available to use, you can use it to create new 3D dimensions bases on the sketch dimensions/feature dimensions data. Also you can re-position the 3D annotations.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 11

guilloryt
Advocate
Advocate

Morning

 

Could you provide a code snippet on how one might take an existing model dimension and promote it to a 3d annotation.. then position it with code?

 

Thanks

0 Likes
Message 4 of 11

YuhanZhang
Autodesk
Autodesk
Accepted solution

I created a simple sample, like in below document I created a simple extrude and show its feature dimensions:

FeatureDim.png

and then create the 3D annotation for the linear feature dimension:

ModelAnno.png

Below is the VBA code:

Sub CreteModelAnnotationFromFeatureDim()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oDoc.ComponentDefinition.Features.ExtrudeFeatures(1)
    
    Dim oFeatureDim As FeatureDimension
    Set oFeatureDim = oExtrude.FeatureDimensions.Item(1)
    
    Dim oModelDims As ModelDimensions
    Set oModelDims = oDoc.ComponentDefinition.ModelAnnotations.ModelDimensions
    
    Dim oIntentOne As GeometryIntent
    Dim oIntentTwo As GeometryIntent
    Dim oAnnoPlaneDef As AnnotationPlaneDefinition
    Dim oTextPos As Point
    
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
    
    Dim oStartEdge As Edge
    Set oStartEdge = oExtrude.StartFaces(1).Edges(1)
     
    
    Dim oStartFace As Face
    Set oStartFace = oExtrude.StartFaces(1)
    
    Set oIntentOne = oDoc.ComponentDefinition.CreateGeometryIntent(oStartEdge)
    
    Dim oSideFace As Face, oFace As Face
    For Each oFace In oStartEdge.Faces
        If Not (oFace Is oStartFace) Then
            Set oSideFace = oFace
            Exit For
        End If
    Next

    Dim oEdge As Edge
    For Each oEdge In oSideFace.Edges
        If oEdge.Geometry.Direction.IsParallelTo(oStartEdge.Geometry.Direction) And Not (oEdge Is oStartEdge) Then
             
            Set oIntentTwo = oDoc.ComponentDefinition.CreateGeometryIntent(oEdge)
            Exit For
        End If
    Next
    
    Set oAnnoPlaneDef = oDoc.ComponentDefinition.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oSideFace)
    Set oTextPos = oFeatureDim.TextPoint
    
    Dim oModelDimDef As LinearModelDimensionDefinition
    Set oModelDimDef = oModelDims.LinearModelDimensions.CreateDefinition(oIntentOne, oIntentTwo, oAnnoPlaneDef, oTextPos, kAlignedDimensionType)
    
    Dim oModelDim As LinearModelDimension
    Set oModelDim = oModelDims.LinearModelDimensions.Add(oModelDimDef)
End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 5 of 11

Holzethekid
Contributor
Contributor

Hallo 

i have a question to the solution !

Is there any API Function where i can use the 'Promote' function of a selected sketch dimension? 

like the picture ? 

 

Holzethekid_0-1588103427735.png

Thanks in advance

 

Christian

 

0 Likes
Message 6 of 11

YuhanZhang
Autodesk
Autodesk

Hi Christian,

 

Unfortunately we don't have the API for this method at present, please log to Idea Station for this wish.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 7 of 11

Holzethekid
Contributor
Contributor
0 Likes
Message 8 of 11

gharveyMHN58
Contributor
Contributor

If you would like to promote all sketch dimensions to a 3d annotation then the below will achieve this, the annotations will appear with the text in the same position as the sketch dimension text. 

 

Dim partDoc As Inventor.Document
partDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = partDoc.ComponentDefinition
Dim modeldims As ModelDimensions = oCompDef.ModelAnnotations.ModelDimensions

Dim oSelectSet As SelectSet
    oSelectSet = partDoc.SelectSet
    oSelectSet.Clear

'Wrap all in an 'UNDO'
oDoc = ThisDoc.Document
oUndoName = "iLogic Promote 3D Annotations"
Dim UNDO As Transaction 
UNDO = ThisApplication.TransactionManager.StartTransaction(oDoc, oUndoName)
'Code inside UNDO here:
'-------------------------------------------------------------------------------------------------------------------------------------

For Each oSketch In oCompDef.Sketches 'go through each sketch in the model
	
	oSketch.Visible = True 'make the sketch visible
	oSketch.DimensionsVisible = True 'make the dimensions visible

	'select all the dimensions in the sketch
	For Each oDim In oSketch.DimensionConstraints
		oSelectSet.Select(oDim)
	Next

	Call ThisApplication.CommandManager.ControlDefinitions("3daPromoteDimensionCmd").Execute 'promote the dimensions to 3d annotations
	
	'if you dont see annotations try this line below
	'Call ThisApplication.CommandManager.ControlDefinitions("PartVisibilityCtxCmd").Execute 
	
	oSketch.Visible = False 'hide the sketch again
	oSketch.DimensionsVisible = False

Next
'-------------------------------------------------------------------------------------------------------------------------------------
UNDO.End
0 Likes
Message 9 of 11

_KarlH
Enthusiast
Enthusiast

@gharveyMHN58- That 2D Dimension to 3D Annotation iLogic sub is great! Is there a method that can be called that will center the 3D Annotation text? I notice that their value text keeps the same (off-centered) location as their 2D Dimension value.

_KarlH_0-1652915734266.png

 

0 Likes
Message 10 of 11

Holzethekid
Contributor
Contributor

@_KarlH 

this is c# code, but i think you should be able to translate to ilogic.

 

The centerText() method should do the job

  private void SetNewPosition(ModelAnnotation annotation, Point newTextPoint)
        {
            if (annotation is LinearModelDimension lmd)
            {
                lmd.Definition.Text.Position = newTextPoint;
                lmd.CenterText();
            }

            if (annotation is AngularModelDimension amd)
            {
                amd.Definition.Text.Position = newTextPoint;
                amd.CenterText();
            }

 

Message 11 of 11

_KarlH
Enthusiast
Enthusiast

@Holzethekid - yes, through digging around on these forums, I found this example worked well for centering existing 3D Annotation text. 

 

 

 

oDoc = ThisDoc.Document.ComponentDefinition.ModelAnnotations.ModelDimensions.linearmodeldimensions
'center the text for linear dimensions
For Each oLinDim In oDoc
	oLinDim.centertext
Next

 

 

 

I'm looking into methods of adjusting a 3D Annotations distance from a dynamic expanding/shrinking object now - I suspect that will be a challenge! Also thinking on how to parse only dimensions that have been manually renamed, so that d# dimensions aren't projected, but "Width" and "Height" are. 🤔 Open to suggestions!

 

EDIT: Ahh, this example should tie in well! With a bit of trickery, I should be able to only promote certain named dimensions to 3D Annotations.

 

https://clintbrown.co.uk/2020/07/27/ilogic-get-set-user-parameters/

0 Likes