Inventor Customization

Active Contributor
Posts: 42
Registered: ‎02-26-2007
Message 1 of 11 (2,937 Views)

Scale in Title Block

2937 Views, 10 Replies
06-13-2008 08:01 AM
Returning to the age-old question: how do you get the scale to show up properly in the title block? I've been searching and finding nothing on this issue, with exception of Autodesk personnel telling users to use the scale display on the views. I know it's not the "Autodesk way" of doing things, but my company has been putting the main view scale in the title block for over 30 years. I'm not gonna change that.

So, anyway, I've been using Patrick de Stobbeleir's "iProperty Collection" utility since Inv11, and it does the job. The thing that bugs me, though, is that I can't figure out how to get the FirstViewScale:x custom properties to work intelligently in my title blocks. And by that, I mean that I just use the property FirstViewScale in my title block, which displays the scale of the first view put matter what the sheet.

Does anyone have any ideas on how I can use the FirstViewScale:x property in title blocks such that x is the sheet number?

So far we just have the first sheet use the FirstViewScale, and then subsequent sheets use a prompted entry (I know it's an ugly work-around).

Any help anyone can provide will be greatly appreciated.

Active Contributor
Posts: 42
Registered: ‎02-26-2007
Message 2 of 11 (2,936 Views)

Re: Scale in Title Block

06-24-2008 10:17 AM in reply to: ggriffiths
To refresh my question: Has anyone had any experience with this? Could someone please tell me if it's possible to code VBA into title blocks? I could probably hack out some code to try to match up the values...though at this point I don't know where to start. Does anyone have any thoughts on this one?

Thanks again,
Valued Contributor
Posts: 95
Registered: ‎06-29-2007
Message 3 of 11 (2,936 Views)

Re: Scale in Title Block

06-26-2008 02:46 PM in reply to: ggriffiths
How about setting the scale of currentsheet.view(1) to the textbox object representing the scale value in the titleblock?
Just a thought..

Ronny Message was edited by: Ruffen
Valued Mentor
Posts: 361
Registered: ‎11-11-2005
Message 4 of 11 (2,936 Views)

Re: Scale in Title Block

07-01-2008 10:22 PM in reply to: ggriffiths
this may help you
Active Contributor
Posts: 42
Registered: ‎02-26-2007
Message 5 of 11 (2,936 Views)

Re: Scale in Title Block

07-07-2008 05:55 AM in reply to: ggriffiths

While I have not tried your suggestion, I think what would happen is that all sheets using the title block will show the same, single scale that the VBA inserted. The catch I run into is that each sheet's title block needs to reference a different variable (that being the FirstViewScale:x variable).

I suppose a real kludgy workaround would be to have the macro auto-generate copies of the title block for each sheet, each one's scale set to reference FirstViewScale:1, then FirstViewScale:2, etc... But that could potentially make a real mess of things when using the "Drawing Resource Transfer Wizard".

Another thing just occurred to me; another kludgy workaround -- it might be possible to write the variable back to the model's custom iProperties. That is something that the title block can pull on a per-sheet basis... hmmm, just might work.

I'll post back here if I come up with anything...

Thanks everyone for your ideas,
Posts: 13
Registered: ‎07-04-2008
Message 6 of 11 (2,936 Views)

Re: Scale in Title Block

07-14-2008 07:25 AM in reply to: ggriffiths
Hi Grant, Can't remember where i got this little snippet from, but it works.

Option Explicit
'Always use X and Y in the Scale display string
'Example HowToDisplayFirstViewScale=[X:Y] will display as [1:2] in the properties
Const HowToDisplayFirstViewScale As String = "X:Y"

'Always use X and Y in the Scale display string
'Example HowToDisplayAllViewScales=X:Y will display as 1:2 in the properties
Const HowToDisplayAllViewScales As String = "X:Y"

'Set the charactor for the All View Scales list separator
'Example ListSparator="," the list will dispaly as [5:1],[1:1]
Const ListSparator As String = " "

'Value that will control if the the First View is excluded from the All View Scales list
'True: Exclude the Scale of the First View from the All View Scales list
'False: All View Scales are included in the list
Const ExcludeFirstInAllScales As Boolean = True

'True: Uses the same display style as inventor, Scale 2.5 is shown as 2.5:1
'False: Always find an integer value for both values, Scale 2.5 is shown as 5:2
Const ShowScaleAsInventor As Boolean = True
Const ShowScaleAsInventorDecimals As Integer = 2

Public Sub AutoSave_View_Scale()
Call ShowFirstViewScale
Call AddRevs
End Sub

Private Sub ShowFirstViewScale()

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim ScaleProp As String

On Error Resume Next

'Find the Scale of the first View on the first Sheet
ScaleProp = ConvScale2Fraction(oDrawDoc.Sheets.Item(1).DrawingViews.Item(1).Scale, True)

'Add a custom property "Scale" with all the view scales
Dim oPropSet As PropertySet

Set oPropSet = ThisApplication.ActiveDocument.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
Call oPropSet.Item("Drawing Scale").Delete
Call oPropSet.Add(ScaleProp, "Drawing Scale")

'Still having some problems that the last property does not update correct
Call RefreshProperties

End Sub

Private Function ConvScale2Fraction(ValScale As Double, FirstView As Boolean) As String

Dim TempStr As String
Dim sx As Long
Dim sy As Long
Dim dsx As Double
Dim dsy As Double

'Convert the deciaml value to a fraction
Call DecToFrac(ValScale, sx, sy)

dsx = sx
dsy = sy

If ShowScaleAsInventor Then
If sx > 1 And sy >= 1 Then
dsx = Round(ValScale, ShowScaleAsInventorDecimals)
dsy = 1
End If
End If

If FirstView Then
TempStr = Replace(UCase(HowToDisplayFirstViewScale), "X", CStr(dsx))
ConvScale2Fraction = Replace(TempStr, "Y", CStr(dsy))
TempStr = Replace(UCase(HowToDisplayAllViewScales), "X", CStr(dsx))
ConvScale2Fraction = Replace(TempStr, "Y", CStr(dsy))
End If

End Function

Private Sub DecToFrac(DecimalNum As Double, Numerator As Long, Denom As Long)

' The BigNumber constant can be adjusted to handle larger fractional parts
Const BigNumber = 1000
Const SmallNumber = 0.0001

Dim Inverse As Double, FractionalPart As Double
Dim WholePart As Long, SwapTemp As Long

Inverse = 1 / DecimalNum
WholePart = Int(Inverse)
FractionalPart = Frac(Inverse)

If 1 / (FractionalPart + SmallNumber) < BigNumber Then
' Notice that DecToFrac is called recursively.
Call DecToFrac(FractionalPart, Numerator, Denom)
Numerator = Denom * WholePart + Numerator

SwapTemp = Numerator
Numerator = Denom
Denom = SwapTemp
Else ' If 1 / (FractionalPart + SmallNumber) > BigNumber
' Recursion stops when the final value of FractionalPart is 0 or
' close enough. SmallNumber is added to prevent division by 0.
Numerator = 1
Denom = Int(Inverse)
End If

End Sub

' This function is used by DecToFrac and DecToProperFact

Private Function Frac(x As Double) As Double
Frac = Abs(Abs(x) - Int(Abs(x)))
End Function

' This additional procedure handles "improper" fractions and returns
' them in mixed form (a b/c) when the numerator is larger than the denominator

Private Sub DecToProperFrac(x As Double, a As Long, b As Long, c As Long)
If x > 1 Then a = Int(x)
If Frac(x) <> 0 Then
Call DecToFrac(Frac(x), b, c)
End If
End Sub

Private Sub RefreshProperties()

Dim oPropSet As PropertySet
Dim oPropSets As PropertySets

Set oPropSet = ThisApplication.ActiveDocument.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
Call oPropSet.Add("", "MyDummy")

Call oPropSets.FlushToFile

End Sub

It creates a custom iProperty, which you can put into a test box in the right location, and updates itself on save.

Hope this helps

Posts: 13
Registered: ‎07-04-2008
Message 7 of 11 (2,936 Views)

Re: Scale in Title Block

07-14-2008 07:57 AM in reply to: ggriffiths
Sorry Grant, should've read your post properly!
I'll get my coat.
Valued Contributor
Posts: 95
Registered: ‎06-29-2007
Message 8 of 11 (2,936 Views)

Re: Scale in Title Block

07-14-2008 01:47 PM in reply to: ggriffiths
Hi, Grant.
I have not tried this myself, but I think each sheets titleblock is independent instances of the titleblock definition, in other words should it be possible to set the value of a textbox in the titleblock on the current sheet...

For Each osheet As Inventor.Sheet In oSheets
oTitleblockDef = osheet.TitleBlock.Definition
For Each textbox As Inventor.TextBox In oTitleblockDef.Sketch.TextBoxes
'Find the texbox
'Insert the scale value

*Expert Elite*
Posts: 4,296
Registered: ‎04-27-2005
Message 9 of 11 (2,936 Views)

Re: Scale in Title Block

08-06-2008 06:32 AM in reply to: ggriffiths
I tried this macro, but it didn't write anything to the custom properties of the idw. I had to comment out the "Call AddRevs" routine. Other than that I did not change anything.

Any ideas?

Posts: 3
Registered: ‎06-14-2013
Message 10 of 11 (1,018 Views)

Re: Scale in Title Block

06-14-2013 06:27 PM in reply to: ggriffiths

Here is the string that I got of another Autodesk Discussion.

It works with Autodesk Inventor 2013.

Format:HTML Format Version:1.0 StartHTML:     165 EndHTML:    7217 StartFragment:     314 EndFragment:    7185 StartSelection: 314 EndSelection:     314
SyntaxEditor Code Snippet

DimodrawdocAsDrawingDocumentodrawdoc=ThisApplication.ActiveDocumentcustomPropertySet=odrawdoc.PropertySets.Item("Inventor User Defined Properties")Fori=1Toodrawdoc.Sheets.CountTryprop=customPropertySet.Item("FirstViewScale"+Str(i))CatchcustomPropertySet.Add("", "FirstViewScale"+Str(i))EndTryTryiProperties.Value("Custom", "FirstViewScale"+Str(i))=odrawdoc.sheets.item(i).DrawingViews.Item(1).ScaleStringCatchEndTryNextiInventorVb.DocumentUpdate()

Another way is using the NXT Dim Tools and simply ticking the 'show first view scale' or something like that box.


Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!