Initial View Scale with VBA

Initial View Scale with VBA

0x3FA5
Advocate Advocate
1,146 Views
2 Replies
Message 1 of 3

Initial View Scale with VBA

0x3FA5
Advocate
Advocate

Hi,

I tried to find some hints on the Inventor API help webpage, but no real success there..

Please help me to do the following.

 

How do I change this parameter in the drawing:

0x3FA5_0-1687279020047.png

Located here (Title Block):

0x3FA5_1-1687279147044.png

 

To this:

0x3FA5_2-1687279187183.png

Using VBA macro?

 

Thank you!

 

* Update *

After further researching I identified that the Item(55) holds the information required, and came up with the following code:

 

Option Explicit

Sub DrwScale()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Set oSheet = oDoc.ActiveSheet

Dim oTitleBlock As TitleBlock
Set oTitleBlock = oSheet.TitleBlock

oTitleBlock.Definition.Sketch.TextBoxes.Item(55).FormattedText = "<DerivedProperty DerivedID='29707'>Initial View Scale</DerivedProperty>"

End Sub

 

Which produces the following error:

0x3FA5_0-1687289039363.png

I guess, the issue is that I incorrectly filled the FormattedText property.

Please help.

Also, could you provide a reference to the correct format of the FormattedText method?

Thank you!

0 Likes
Accepted solutions (2)
1,147 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

Hi @0x3FA5 

The issue here is that you need to edit the titleblock and then access the sketch, modify and then save on exit. 

 

Option Explicit

Sub DrwScale()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Set oSheet = oDoc.ActiveSheet

Dim oTitleBlock As TitleBlock
Set oTitleBlock = oSheet.TitleBlock

Dim oSketch As Sketch

Call oTitleBlock.Definition.Edit(oSketch)

Dim oTextBox As Inventor.TextBox
For Each oTextBox In oSketch.TextBoxes
    If InStr(oTextBox.FormattedText, "Scale") > 0 Then
        oTextBox.FormattedText = "<DerivedProperty DerivedID='29707'>Initial View Scale</DerivedProperty>"
    End If
Next

Call oTitleBlock.Definition.ExitEdit(True)
End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

0x3FA5
Advocate
Advocate
Accepted solution

Thank you!

The only note, I wouldn't use "For Each", since there are other text boxes on the drawing that include the word "Scale", and I don't want to change all of them.

I figured that the box I need is Item(55).

 

'Macro Buttons
'DrwMod.DrwScale.Large.bmp
'DrwMod.DrwScale.Small.bmp

Option Explicit

Public Sub DrwScale()

    Dim oDrwDoc As DrawingDocument
    Set oDrwDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDrwDoc.ActiveSheet
    
    Dim oTitleBlock As TitleBlock
    Set oTitleBlock = oSheet.TitleBlock
    
    Dim oTitleBlockDef As TitleBlockDefinition
    Set oTitleBlockDef = oTitleBlock.Definition
    
    Dim oSketch As DrawingSketch
    
    Call oTitleBlockDef.Edit(oSketch)
    
    oSketch.TextBoxes.Item(55).FormattedText = _
            "<DerivedProperty DerivedID='29707'>Initial View Scale</DerivedProperty>"
    
    Call oTitleBlockDef.ExitEdit(oSketch)
    
    'oDrwDoc.Save
    'oDrwDoc.Close
    
End Sub