sketch dimension constraints

sketch dimension constraints

Anonymous
Not applicable
549 Views
2 Replies
Message 1 of 3

sketch dimension constraints

Anonymous
Not applicable
Hello,
 
I with this code i create 4 points for make a rectangle, and i add somme constraints.
But i don't understand how add a dimension constraints between 2 points.
and i would add this dimension as function parameters.

 

Sub test()

'Créer une nouvelle piece SHOP
    Dim oApp As Inventor.Application
        Set oApp = ThisApplication
    
    oTemplatesPath = oApp.DesignProjectManager.ActiveDesignProject.TemplatesPath
    oTemplateFile = "piece SHOP.ipt"
    oTemplate = oTemplatesPath & "\" & oTemplateFile
    
    Dim oPartDoc As PartDocument
        Set oPartDoc = oApp.Documents.Add(kPartDocumentObject, oTemplate)

'Créer une esquisse
    ' Create a 2D sketch on the X-Y plane.
    Dim sketch1 As PlanarSketch
        Set sketch1 = oPartDoc.ComponentDefinition.Sketches.Add(oPartDoc.ComponentDefinition.WorkPlanes.Item(3))
    
    Dim oTG As TransientGeometry
        Set oTG = oApp.TransientGeometry
    
    ' Declaration des variable avec dimenssions du tiroir
    Dim Largeur_interieur_tiroir As Integer
    Largeur_interieur_tiroir = 200

    Dim Hauteur_interieur_tiroir As Integer
    Hauteur_interieur_tiroir = 50

    Dim Epaisseur_parois_tiroir As Integer
    Epaisseur_parois_tiroir = 18

' Création base du tiroir
    'Créer des points au dimensions du tioir
    Dim oSkPnts As SketchPoints
        Set oSkPnts = sketch1.SketchPoints
        Call oSkPnts.Add(oTG.CreatePoint2d(Largeur_interieur_tiroir / 2, 0), False)
        Call oSkPnts.Add(oTG.CreatePoint2d((0 - Largeur_interieur_tiroir) / 2, 0), False)
        Call oSkPnts.Add(oTG.CreatePoint2d((0 - Largeur_interieur_tiroir) / 2, Epaisseur_parois_tiroir), False)
        Call oSkPnts.Add(oTG.CreatePoint2d(Largeur_interieur_tiroir / 2, Epaisseur_parois_tiroir), False)
    
    ' Relier les points pour dormer un rectancle
    Dim oLines As SketchLines
        Set oLines = sketch1.SketchLines
    Dim oLine(1 To 4) As SketchLine
        Set oLine(1) = oLines.AddByTwoPoints(oSkPnts(1), oSkPnts(2))
        Set oLine(2) = oLines.AddByTwoPoints(oSkPnts(2), oSkPnts(3))
        Set oLine(3) = oLines.AddByTwoPoints(oSkPnts(3), oSkPnts(4))
        Set oLine(4) = oLines.AddByTwoPoints(oSkPnts(4), oSkPnts(1))

    'Contraindre l'esquisse
        'Horizontal
        Call sketch1.GeometricConstraints.AddHorizontal(oLines(1))
        
        'Parallele
        Call sketch1.GeometricConstraints.AddParallel(oLine(1), oLine(3))
        Call sketch1.GeometricConstraints.AddParallel(oLine(2), oLine(4))
        
        'Perpendiculaire
        Call sketch1.GeometricConstraints.AddPerpendicular(oLines(1), oLines(2))

    oApp.ActiveView.Update

Call sketch1.GeometricConstraints.TwoPointDistanceDimConstraint(oSkPnts(1), oSkPnts(2))

    
End Sub

 

how can i do it?

thank

0 Likes
Accepted solutions (1)
550 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

You were pretty close.  In the last line of code, you should have had 'DimensionConstraints' instead of 'GeometricConstraints', and the method name after that should have been 'AddTwoPointDistance' instead of 'TwoPointDistanceDimConstraint'.  Then that method needed a couple more input variables (dimension orientation and text position).

Here is an example of code to replace that last line of code:

    Dim oTextPoint As Point2d
    Set oTextPoint = oLine(1).Geometry.MidPoint.Copy
    oTextPoint.Y = oTextPoint.Y + 1
    Call sketch1.DimensionConstraints.AddTwoPointDistance(oSkPnts(1), oSkPnts(2), kHorizontalDim, oTextPoint)

 I know that dimension needed to be horizontal, due to the code above that.  And the text point I just tried to place halfway between the two points, and 1 unit above them.

 

 

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

Anonymous
Not applicable

marvellous,

 

thank tou

0 Likes