Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dimensional Constraint between sketchblocks

1 REPLY 1
Reply
Message 1 of 2
taher.basha
137 Views, 1 Reply

Dimensional Constraint between sketchblocks

I want to create dimensional constraint between two sketchblocks as shown below pic using VB.Net or C#

and assign the userparameter to it. attaching the sample file

cons.PNG

1 REPLY 1
Message 2 of 2

If you want to create dimension constraint between two blocks, you need to get appropriate geometry within the sketch. For this purpose there is a function GetObject. But you need to know which line it is in block definition.

 

Create dimension constraint sample

 

Sub AddDimensionConstraint()

    Dim activeSketch As PlanarSketch = ThisApplication.ActiveEditObject
    Dim blockA As SketchBlock = activeSketch.SketchBlocks(1)
    Dim blockB As SketchBlock = activeSketch.SketchBlocks(2)

    Dim line1Def As SketchLine = blockA.Definition.SketchLines(14) 'Use IndexOfLine to get this number
    Dim line1 = blockA.GetObject(line1Def)

    Dim line2Def As SketchLine = blockB.Definition.SketchLines(14) 'Use IndexOfLine to get this number
    Dim line2 = blockB.GetObject(line2Def)


    Dim textPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)

    activeSketch.DimensionConstraints.AddOffset(line1, line2, textPoint, False)
End Sub

 

 

Here is sample code how to get index of line in block definition sketch.

This code snippet expects you are in block definition sketch environment.

 

Sub IndexOfLine()
    Dim block As SketchBlockDefinition = ThisApplication.ActiveEditObject
    Dim pickedLine As SketchLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "sk line")
    Dim i = 1
    For Each skLine As SketchLine In pickedLine.Parent.SketchLines
        If (skLine Is pickedLine) Then
            Logger.Debug(i)
            Return
        End If
        i += 1
    Next
    Logger.Debug("not found")
End Sub

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report