hi @psaarloos,
I expect that you want to do this in a folded sheetmetal part. Hopefully this iLogic rule helps you with the first part of your question.
Dim doc As PartDocument = ThisDoc.Document
Dim oTg As TransientGeometry = ThisApplication.TransientGeometry
Dim highLight As HighlightSet
If (doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
highLight = doc.HighlightSets.Add()
highLight.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
Dim smDocDef As SheetMetalComponentDefinition = doc.ComponentDefinition
For Each def As ASideDefinition In smDocDef.ASideDefinitions
For Each aFace As Face In def.Faces
highLight.AddItem(aFace)
Next
Next
End If
Dim sketch As PlanarSketch
Dim line1 As SketchLine
Dim line2 As SketchLine
Dim edge1 As Edge
Dim edge2 As Edge
' when you do this in a user control then you would not need ask this in a msgbox
' but would it be an option on the user control
Dim res As Windows.Forms.DialogResult = Windows.Forms.MessageBox.Show(
"do you want to seletc the lines?",
"how to select.", Windows.Forms.MessageBoxButtons.YesNo)
Dim face As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "select a face")
If (res = Windows.Forms.DialogResult.Yes) Then
sketch = doc.ComponentDefinition.Sketches.Add(face, False)
edge1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Select edge 1")
edge2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Select edge 2")
line1 = sketch.AddByProjectingEntity(edge1)
line2 = sketch.AddByProjectingEntity(edge2)
Else
sketch = doc.ComponentDefinition.Sketches.Add(face, True)
line1 = sketch.SketchLines.Item(1)
line2 = sketch.SketchLines.Item(2)
End If
Dim textBox As TextBox = sketch.TextBoxes.AddFitted(oTg.CreatePoint2d(1, 1), " ")
Dim dimension1 As DimensionConstraint = sketch.DimensionConstraints.AddOffset(
line1, textBox.OriginSketchPoint, oTg.CreatePoint2d(0.5, 0.5), False)
Dim dimension2 As DimensionConstraint = sketch.DimensionConstraints.AddOffset(
line2, textBox.OriginSketchPoint, oTg.CreatePoint2d(0.5, 0.5), False)
' this input boxes would normaly be textboxes on a user control
Dim newText As String = InputBox("Set text:")
Dim newDim1 As String = InputBox("Set Dimension 1:")
Dim newDim2 As String = InputBox("Set Dimension 2:")
' here is how you would set the dimensions and text
textBox.Text = newText
dimension1.Parameter.Expression = newDim1
dimension2.Parameter.Expression = newDim2
doc.Update()
Its not perfect. For example the text is not guaranteed to be on the face. When the text is created its placed near the origin not on the face.
For the second part of your question ("would be nice to create this feature in a panel") you would need to be more specific on what you need to know.
Anyway let me know if you have more questions.
met vriendelijke groet,
jelte
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com