Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Chnage the Text Definition using Ilogic

13 REPLIES 13
Reply
Message 1 of 14
ravikmb5
1951 Views, 13 Replies

Chnage the Text Definition using Ilogic

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

 

Change Text Definition 2.png

Change Text Definition 1.png

 

Change Text Definition 3.png

 

 

 

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Tags (1)
13 REPLIES 13
Message 2 of 14
ravikmb5
in reply to: ravikmb5

Has anybody got solution for this

 

 

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 3 of 14
Vladimir.Ananyev
in reply to: ravikmb5

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

 Fit Text.PNG

cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 4 of 14
ravikmb5
in reply to: Vladimir.Ananyev

Thanks For your Response

 

 

This Code Works For Some Extent

 

but it seems not Defined Fully

 

Change Text Definition 5.png

 

 

 

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

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 5 of 14
Vladimir.Ananyev
in reply to: ravikmb5

I may suggest the following workaround.

  1. Read the string value of the user defined property TITLE1
  2. Open the title block sketch for edit
  3. Find the text box that is linked to the property <TITLE1>
  4. Calculate the full length of one-line text using temporary created text box (not saved)
  5. Apply new WidthScale value to the target text box.
  6. Exit edit mode.

 

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:                                                                           

1.PNG

 

TextBox after:

2.PNG

 

Hope this could help you.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 6 of 14
ravikmb5
in reply to: Vladimir.Ananyev

i just copied at pasted in Vba Editor

 

it showing me these Errors

 

Invalid Debug.png

 

Error_Debug.png

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 7 of 14
ravikmb5
in reply to: ravikmb5

Can someone could help me debugging this code

 

Please its urgent

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 8 of 14
Vladimir.Ananyev
in reply to: ravikmb5

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,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 9 of 14
ravikmb5
in reply to: Vladimir.Ananyev

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

 

TitleblockBefore.png

 

TITLEBLOCKAFTER

 

TitleblockAfter.png

 

 

Thanks A Lot For Ur Response

 

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 10 of 14
Vladimir.Ananyev
in reply to: ravikmb5

Just an idea:

try  0,39878  and  0.39878  -  if this is a dot / comma problem?

Could you make a quick test?


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 11 of 14
ravikmb5
in reply to: Vladimir.Ananyev

Just Tried

 

But same Results

 

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 12 of 14
Vladimir.Ananyev
in reply to: ravikmb5

Hi Ravi,

Please clarify – what did you do to avoid Run-time error ‘5’ ?


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 13 of 14
ravikmb5
in reply to: Vladimir.Ananyev

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

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 14 of 14
Vladimir.Ananyev
in reply to: ravikmb5

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,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report