Toggle Textbox Option In Format Text Window Using iLogic

Toggle Textbox Option In Format Text Window Using iLogic

gareth.butlerS9R7M
Advocate Advocate
560 Views
5 Replies
Message 1 of 6

Toggle Textbox Option In Format Text Window Using iLogic

gareth.butlerS9R7M
Advocate
Advocate

Hi All,

I have cobbled together some iLogic code which formats text, sets justification etc in part (.IPT) sketches.

I can't seem to get any of the code to toggle on or off the textbox button.

How can I add to / vary the code sample below to either enable or disable the textbox button?

 

Dim oPartDoc As PartDocument
oPartDoc = ThisDoc.Document
Dim oCd As ComponentDefinition
oCd = oPartDoc.ComponentDefinition
Dim oTextbox As TextBox
Dim oSketch As PlanarSketch
Dim oColor As Color = ThisApplication.TransientObjects.CreateColor(128, 0, 128)

For Each oSketch In oCd.Sketches
For Each oTextbox In oSketch.TextBoxes
'write formatted text
oText = oTextbox.Text
oTextbox.Color = oColor
oTextbox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
oTextbox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
oTextbox.WidthScale = 1
oTextbox.FormattedText = "<StyleOverride Font='Tahoma' FontSize='0.35' Bold='False' Italic='False' Underline='False'>" & oText & "</StyleOverride>"

Next
Next

iLogicVb.UpdateWhenDone = True

 

Any help or advice greatly appreciated!

 

Many thanks,

Gareth 😀

0 Likes
Accepted solutions (2)
561 Views
5 Replies
Replies (5)
Message 2 of 6

frederic.vandenplas
Collaborator
Collaborator
Accepted solution

There is no API available for that, but you can allways use the native command for that

In this example i preselected the text, and executed the code below (vba)

If you run it a second time the textbox wil revert in the previous state.

You can check with the textbox.Fitted property if you need to convert your textbox.

Here you can find all the information you need

 

    ' Get the CommandManager object.
    Dim oCommandMgr As CommandManager
    Set oCommandMgr = ThisApplication.CommandManager

    ' Get control definition for the line command.
    Dim oControlDef As ControlDefinition
    Set oControlDef = oCommandMgr.ControlDefinitions.Item( _
                                                 "SketchTextAddDelBoxGeomCmd")
    ' Execute the command.
    Call oControlDef.Execute

 

 

 

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 3 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi guys.  I believe there is actually a way to do this by API, instead of needing to select it then execute a command on it.  But first things first.  In your original code here, you would need to change your

Dim oTextbox As TextBox

to this:

Dim oTextbox As Inventor.TextBox

...because it gets confused with the System.Windows.Forms.TextBox object.

Next, the Inventor.TextBox object has a couple properties we can use for this task.

TextBox.ShowBoundaries (Read/Write Boolean - like the 'TextBox' button in the dialog)

TextBox.BoundaryGeometry (ReadOnly - SketchEntitiesEnumerator type value)

That first property is like the TextBox button in the editor dialog, while that second one provides a way to get a reference to the actual geometry objects (SketchLine objects) that make up its border, so you can apply sketch level constraints to them.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 6

gareth.butlerS9R7M
Advocate
Advocate

@frederic.vandenplas @WCrihfield

 

I changed the code to that below by adding in the oTextbox.ShowBoundaries line and it now does what I need it to.

 

During the iLogic execution, the text is automatically converted to textbox toggled 'on' because the boundary has been set to show.

 

oCd = oPartDoc.ComponentDefinition
Dim oTextbox As Inventor.TextBox
Dim oSketch As PlanarSketch
Dim oColor As Color = ThisApplication.TransientObjects.CreateColor(128, 0, 128)

For Each oSketch In oCd.Sketches
For Each oTextbox In oSketch.TextBoxes
'write formatted text
oTextbox.ShowBoundaries() = True
oText = oTextbox.Text
oTextbox.Color = oColor
oTextbox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
oTextbox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
oTextbox.WidthScale = 1
oTextbox.FormattedText = "<StyleOverride Font='Tahoma' FontSize='0.35' Bold='False' Italic='False' Underline='False'>" & oText & "</StyleOverride>"

Next
Next

iLogicVb.UpdateWhenDone = True

 

Brilliant work and thanks for all your help, it is greatly appreciated! 😀👍

0 Likes
Message 5 of 6

frederic.vandenplas
Collaborator
Collaborator

@WCrihfield 

I've overlooked that property, sorry for that!

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

No need for apologies.  You were just trying to help.  I'm sure I have done the same or worse many times before.  Some of this stuff can be tricky.  The tooltip for the button says 'Text Box', but the property is named 'ShowBoundaries', so they do not seem like the same thing on first glance.  Sometimes these little details just stick better in our head once we have been tripped up by them before.  The process of trial & error is a very effective teacher.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)