Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Inventor Api: find Connection between Sketch Dimension(DimensionConstraint) and Model Dimension(LinearModelDimension)

Holzethekid
Contributor

Inventor Api: find Connection between Sketch Dimension(DimensionConstraint) and Model Dimension(LinearModelDimension)

Holzethekid
Contributor
Contributor

Hallo, 

since Inventor 22 it is possible to promote SketchDimensions via code. See here

Holzethekid_2-1635603755987.pngvia UI 

 

The Model Dimensions promoted via 'Inventor' has the great feature that if i change an value in the sketch the value in the Model Value will change to.

Manuell created Model Dimensions do not have this feature.

 

I Assume that the Sketch Dimension (DimensionConstaint) and the Model Dimension (ModelDimension) are somehow connected. 

 

Holzethekid_0-1635603447044.pngHolzethekid_1-1635603460503.png

 

I was checking the documentation, but i did not find any connection between the two objects.

Can somebody help me to find the connection between these objects, or how can i find out if one DimensionConstraint is already promoted and get the object ?!

 

Thanks in Advance

 

Christian

 

 

 

 

0 Likes
Reply
Accepted solutions (1)
468 Views
3 Replies
Replies (3)

theo.bot
Collaborator
Collaborator

Within the Modeldimensiondefinition you can find the promoted parameter. But for some reason i can't get the parameter. It results in a "not implemented" message. Maybe someone else knows how to deal with this.

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
    
Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition

Dim oModelDim As ModelDimension

For Each oModelDim In oDef.ModelAnnotations.ModelDimensions
Dim oModelDef As ModelDimensionDefinition
Dim oPara As Inventor.Parameter
oModelDef = oModelDim.Definition
oPara = oModelDef.PromoteParameter
Logger.Info(oPara.Name)
Next

 

theobot_0-1635756635702.png

 

0 Likes

Holzethekid
Contributor
Contributor

Hall Theo,

thanks for the anwer. But as you mentioned the 'PromoteParameter' does not work.

I 'found' a  really sketchy solution how to identify a annotation depending on a DimensionConstraint.

 

I guess that this solution will be very easy to break, and if the other objects 

- RadiusModelDimensions

- DiameterModelDimensions

- AngularModelDimensions

will work the same way ?? I don't know

 

 

  public ModelAnnotation GetConnectedAnnotation(DimensionConstraint constraint)
        {
            logger.Debug($"GetConnectedAnnotation");

            var annotations = applicationService.GetDocumentAnnotations();

            foreach (var md in annotations.ModelDimensions)
            {
                if (md is LinearModelDimension modelDimension)
                {
                    if (modelDimension.Definition is LinearModelDimensionDefinition lmdd)
                    {
                        if (lmdd.IntentOne.Geometry is SketchPoint sp)
                        {
                            foreach (var point in constraint.AnchorPoints)
                            {
                                if (point is Point2d point2d)
                                {
                                    if (sp.Geometry.IsEqualTo(point2d))
                                    {
                                        if (Math.Abs(constraint._DisplayValue - modelDimension.ModelValue) <= 0)
                                        {
                                            logger.Debug($"found constraint : {constraint.Parameter.Name} Value:'{constraint.Parameter.Expression}' | modelDimesnion{modelDimension.Name} Value :'{modelDimension.ModelValue}'");
                                            return md as ModelAnnotation;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return null;
        }

 

0 Likes

theo.bot
Collaborator
Collaborator
Accepted solution

With Inventor 2022.2 update it's now possible to use "Promoteparameter". tested it and it works fine :slightly_smiling_face:

 

theobot_0-1636611328857.png