Textbox

Textbox

andrew_basket05
Explorer Explorer
247 Views
1 Reply
Message 1 of 2

Textbox

andrew_basket05
Explorer
Explorer

Hi guys, 

I have a flatpattern on witch I created a sketch with all the edges and bends project. Here's my code:

Dim partDoc As Document
Set partDoc = ThisApplication.ActiveDocument

Dim UOM As UnitsOfMeasure
Dim eLengthUnits As UnitsTypeEnum

Set UOM = partDoc.UnitsOfMeasure
eLengthUnits = UOM.LengthUnits

Dim partDef As SheetMetalComponentDefinition
Set partDef = partDoc.ComponentDefinition

If partDef.FlatPattern Is Nothing Then
partDef.Unfold

Dim partflat As FlatPattern
Set partflat = partDef.FlatPattern

Set sk = partflat.Sketches.Add(partflat.TopFace, True)
sk.Name = "CTS"

sk.Edit

Dim i As Integer
For i = 1 To sk.SketchEntities.Count
sk.SketchEntities(i).Construction = False
Next

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

Dim oRB As Box2d
Set oRB = oTG.CreateBox2d

Dim oEnt As SketchEntity
For Each oEnt In sk.SketchEntities
Call oRB.Extend(oEnt.RangeBox.MinPoint)
Call oRB.Extend(oEnt.RangeBox.MaxPoint)
Next

 

Set minXminY = oTG.CreatePoint2d(oRB.MinPoint.X, oRB.MinPoint.Y)
Set minXmaxY = oTG.CreatePoint2d(oRB.MinPoint.X, oRB.MaxPoint.Y)
Set maxXminY = oTG.CreatePoint2d(oRB.MaxPoint.X, oRB.MinPoint.Y)
Set maxXmaxY = oTG.CreatePoint2d(oRB.MaxPoint.X, oRB.MaxPoint.Y)

 

this works fine here's the result:

PART.pngFLATPATTERN.png

What I am struggling with is adding the following textbox:

 

MAT'L: PL. 1/8" x 3 1/2" x 11 9/16"

STEEL 44W

ITEM: STPL264-2115-1

QTY: 2

DONE BY: A.R

 

here, I want this textbox to be proportionnal to the rangebox of the flatpattern:

FLATPATTERN II.png

 So Whatever the size of the part, I want the textbox to be positionned as shown (centered, above, font size proportionnal)

 

any ideas? 

 

thanks in advance!

0 Likes
248 Views
1 Reply
Reply (1)
Message 2 of 2

Sergio.D.Suárez
Mentor
Mentor

Hi, do you need something like this? this is in VBA

 

Sub oTextBox()

Dim partDoc As Document
Set partDoc = ThisApplication.ActiveDocument

Dim UOM As UnitsOfMeasure
Dim eLengthUnits As UnitsTypeEnum

Set UOM = partDoc.UnitsOfMeasure
eLengthUnits = UOM.LengthUnits

Dim partDef As SheetMetalComponentDefinition
Set partDef = partDoc.ComponentDefinition

If partDef.FlatPattern Is Nothing Then partDef.Unfold


Dim partflat As FlatPattern
Set partflat = partDef.FlatPattern

Dim osketch As PlanarSketch
For Each osketch In partflat.Sketches
osketch.Delete
Next

Set sk = partflat.Sketches.Add(partflat.TopFace, True)
sk.Name = "CTS"

sk.Edit

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
Dim oRB As Box2d
Set oRB = oTG.CreateBox2d


Dim otext As String
otext = "MATL: PL. 1/8""" & "x 3 1/2""" & "x 11 9/16""" _
& vbLf & "STEEL 44W " _
& vbLf & "QTY: 2" _
& vbLf & "DONE By: A.R "


Dim oCentX As Double
oCentX = ((oRB.MaxPoint.X - oRB.MinPoint.X) / 2) - 1
Dim oCentY As Double
oCentY = (oRB.MaxPoint.Y) + 3

Dim oCenterPt As Point
Set CenterPt = oTG.CreatePoint(oCentX, oCentY, 0)


Dim oTextPt As Point2d
Set oTextPt = sk.ModelToSketchSpace(CenterPt)

'add the textbox
Dim oSketchText As TextBox
Set oSketchText = sk.TextBoxes.AddFitted(oTextPt, otext)

sk.ExitEdit

ThisApplication.ActiveDocument.Rebuild

End Sub

 

then the same in Ilogic

Dim partDoc As Document
partDoc = ThisApplication.ActiveDocument

Dim UOM As UnitsOfMeasure
Dim eLengthUnits As UnitsTypeEnum

UOM = partDoc.UnitsOfMeasure
eLengthUnits = UOM.LengthUnits

Dim partDef As SheetMetalComponentDefinition
partDef = partDoc.ComponentDefinition

If partDef.FlatPattern Is Nothing Then partDef.Unfold


Dim partflat As FlatPattern
partflat = partDef.FlatPattern

For Each osketch As PlanarSketch In partflat.Sketches
osketch.delete
Next

sk = partflat.Sketches.Add(partflat.TopFace, True)
sk.Name = "CTS"

sk.Edit

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim oRB As Box2d
oRB = oTG.CreateBox2d


Dim otext As String = "MATL: PL. 1/8""" & "x 3 1/2""" & "x 11 9/16""" _ 
		& vbLf & "STEEL 44W " _
		& vbLf & "QTY: 2" _
		& vbLf & "DONE By: A.R "

 
Dim oCentX As Double = ((oRB.MaxPoint.X - oRB.MinPoint.X)/2)-1
Dim oCentY As Double = (oRB.MaxPoint.Y)+3

Dim oCenterPt As Point
CenterPt = oTG.CreatePoint(oCentX,oCentY,0)


Dim oTextPt As Point2d
oTextPt = sk.ModelToSketchSpace(CenterPt)

'add the textbox
Dim oSketchText As TextBox
oSketchText = sk.TextBoxes.AddFitted(oTextPt, otext)

sk.ExitEdit


iLogicVb.UpdateWhenDone = True 

 I hope help solve your problem, regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn