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
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
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
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.