i have simple problem with this ilogic Rule
Can anybody suggest me with this
i have a drawing Template which has many Title Blocks
Title Block has Many text objects which has derived from Model Custom Properties
i want to change a particular text for FIT TEXT JUSTIFICATION
Has anybody got solution for this
Try something like this:
'get the reference to the text box Dim oTextBox As TextBox Set oTextBox = oSketch.TextBoxes.Item(3) 'fit text oTextBox.SingleLineText = True Dim k As Double k = oTextBox.Width / oTextBox.FittedTextWidth oTextBox.WidthScale = k
cheers,
Thanks For your Response
This Code Works For Some Extent
but it seems not Defined Fully
SyntaxEditor Code Snippet
Imports Inventor.UnitsTypeEnum Sub Main() Dim oDoc As Document oDoc = ThisApplication.ActiveDocument If oDoc Is Nothing Then MessageBox.Show("No Active Document", "Title") oDoc = Nothing Exit Sub End If If oDoc.DocumentType <> kDrawingDocumentObject Then MessageBox.Show("Not a drawing document", "Title") oDoc = Nothing Exit Sub End If Dim oDrawDoc As DrawingDocument oDrawDoc = oDoc Dim callTitleBlockDefs As TitleBlockDefinitions callTitleBlockDefs = oDrawDoc.TitleBlockDefinitions Dim objTitleBlockDef As TitleBlockDefinition For Each objTitleBlockDef In callTitleBlockDefs If objTitleBlockDef.Name = "GENERAL" Then 'we have the title blk we want Exit For End If Next objTitleBlockDef If objTitleBlockDef.Name <> "GENERAL" Then MessageBox.Show("GENERAL TitleBlockDefinition not found!", "Title") oDrawDoc = Nothing callTitleBlockDefs = Nothing objTitleBlockDef = Nothing Exit Sub End If ' Get the title block sketch and make it active Dim oSketch As DrawingSketch Call objTitleBlockDef.Edit(oSketch) Dim callTextBoxes As TextBoxes callTextBoxes = oSketch.TextBoxes ' Dim oTextBox As TextBox' oTextBox = oSketch.TextBoxes.Item(3) For Each oTextBox In callTextBoxes If oTextBox.Text = "<TITLE1>" Then oTextBox.SingleLineText = True Dim k As Double k = oTextBox.Width / oTextBox.FittedTextWidth oTextBox.WidthScale = k Exit For End If Next oTextBox Call objTitleBlockDef.ExitEdit(True) End Sub
I may suggest the following workaround.
Here is the VBA code:
Sub Fit_Text_in_Textbox() Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry Dim oDoc As DrawingDocument Set oDoc = ThisApplication.ActiveDocument Dim oSheet As Sheet Set oSheet = oDoc.ActiveSheet Dim oTB As TitleBlock Set oTB = oSheet.TitleBlock Dim oDef As TitleBlockDefinition Set oDef = oTB.Definition 'property name Dim Name As String Name = "TITLE1" 'get property object Dim oProps As Inventor.PropertySet Set oProps = oDoc.PropertySets.Item("User Defined Properties") Dim oProp As Inventor.Property Set oProp = oProps.Item(Name) 'get property value Dim St As String St = oProp.value 'open sketch in edit mode Dim oSketch As DrawingSketch Call oDef.Edit(oSketch) Dim oTextBoxes As TextBoxes Set oTextBoxes = oSketch.TextBoxes ' "SWITCH FILTER ASSEMBLY(SFA)-R 118" Dim oBox As TextBox For Each oBox In oTextBoxes If oBox.Text = "<" & Name & ">" Then ' = "<TITLE1>" Dim oStyle As TextStyle Set oStyle = oBox.Style St = "<StyleOverride FontSize='0,39878'>" & St & "</StyleOverride>" 'temporary textbox to get text full width Dim oTempBox As TextBox Set oTempBox = oTextBoxes.AddFitted(oTG.CreatePoint2d(1, 1), St, oStyle) Dim FullWidth As Double FullWidth = oTempBox.Width oTempBox.Delete 'now we may delete it 'scale text width <-> oBox.WidthScale = oBox.Width / FullWidth 'exit edit mode saving changes Call oDef.ExitEdit(True) Exit For End If Next Beep End Sub
Results with your drawing.
TextBox before:
TextBox after:
Hope this could help you.
i just copied at pasted in Vba Editor
it showing me these Errors
Can someone could help me debugging this code
Please its urgent
Hi Ravi,
I've double checked the vba sample. It works fine with your drawing 21390065-00.idw.
We definitly need more information to help you.
Do you get this error with the 21390065-00.idw or with another drawing?
What are the values of the local variables, etc.
Best regards,
Could u send me the code again in atext File
i was getting these errors continously
i have changed this line
FROM
St = "<StyleOverride FontSize='0,39878'>" & St & "</StyleOverride>"
TO
St = "<StyleOverride.FontSize='0,39878'>" & St & "</StyleOverride>"
BUT THE RESULT WAS NOT SAME AS U SHOWN IN THE ABOVE IMAGE
TITLEBLOCKBEFORE
TITLEBLOCKAFTER
Thanks A Lot For Ur Response
Just an idea:
try 0,39878 and 0.39878 - if this is a dot / comma problem?
Could you make a quick test?
Just Tried
But same Results
Hi Ravi,
Please clarify – what did you do to avoid Run-time error ‘5’ ?
FROM
St = "<StyleOverride FontSize='0,39878'>" & St & "</StyleOverride>"
TO
St = "<StyleOverride.FontSize='0,39878'>" & St & "</StyleOverride>"
i have added only a dot instead of space
in between StyleOveride and FontSize
As Fontsize is a member of Styles
This dot gives you an error. Could you please look at the "XML Tags for FormattedText" section in the Inventor API Help.
XML Tags for FormattedText - Autodesk Inventor Object Library
Style Override <StyleOverride>
The StyleOverride tag defines all text style information. The various style options are defined within the tag using attributes. These attributes are described below.
Font – Sets which font to use. The input to this attribute is the name of the font.
FontSize – Sets the size of the font. The input to this attribute is the size in centimeters.
Bold – Allows you to turn bolding on or off. The input to this attribute is the String "True" or "False".
Italic – Allows you to turn italics on or off. The input to this attribute is the String "True" or "False".
Underline – Allows you to turn underlining on or off. The input to this attribute is the String "True" or "False".
Example:
"<StyleOverride Font='Arial' Bold='True'>Notice</StyleOverride>: All holes larger than 0.500 <StyleOverride Font='AIGDT'>n</StyleOverride> are to be checked."
This results in the following text: Notice: All holes larger than 0.500 nare to be checked.
The first StyleOverride tag defines the font to be Arial and Bold. This is applied to the text “Notice” since that is what is between the opening and closing tags for this style override. The second StyleOverride just changes the font, but uses the font AIGDT which contains some common mechanical drafting symbols. In this example it uses the character “n” which corresponds to the diameter symbol in this font.
cheers,