Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Scale in Title Block

12 REPLIES 12
Reply
Message 1 of 13
ggriffiths
4536 Views, 12 Replies

Scale in Title Block

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 down...no 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.

Thanks,
Grant
12 REPLIES 12
Message 2 of 13
ggriffiths
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,
Grant
Message 3 of 13
Ruffen07
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
Message 4 of 13

this may help you

http://mfgcommunity.autodesk.com/discussions/browse/?dUrl=thread.jspa%3FmessageID%3D5721733
Message 5 of 13
ggriffiths
in reply to: ggriffiths

Ronny,

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,
Grant
Message 6 of 13
Anonymous
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))
Else
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")
oPropSet.Item("MyDummy").Delete

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

Jon
Message 7 of 13
Anonymous
in reply to: ggriffiths

Sorry Grant, should've read your post properly!
I'll get my coat.
Message 8 of 13
Ruffen07
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
Next
Next

Ronny
Message 9 of 13
karthur1
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?

Thanks,
Kirk
Message 10 of 13
swaveck.keller
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.

 

Message 11 of 13
swaveck.keller
in reply to: Anonymous

Using this method is better than using Ilogic as the first view scale and subsequent view scales can be shown and changed automatically.

Message 12 of 13
k14348
in reply to: swaveck.keller

Sub Main()
      Dim drawingDoc As DrawingDocument = TryCast(ThisDoc.Document, DrawingDocument)

      For Each sheetX As Sheet In drawingDoc.Sheets
            Dim titleBlockX As TitleBlock = sheetX.TitleBlock
            If (titleBlockX Is Nothing) Then Continue For
            Dim scaleTextBox As TextBox = GetScaleTextBox(titleBlockX.Definition)
            If (scaleTextBox Is Nothing) Then Continue For
            Dim scaleString As String = String.Empty
            For Each viewX As DrawingView In sheetX.DrawingViews
                  If (Not String.IsNullOrEmpty(viewX.ScaleString)) Then
                        scaleString = viewX.ScaleString
                        Exit For
                  End If
            Next
            titleBlockX.SetPromptResultText(scaleTextBox, scaleString)
      Next
End Sub

Function GetScaleTextBox(ByVal titleDef As TitleBlockDefinition) As TextBox
     For Each defText As TextBox In titleDef.Sketch.TextBoxes
            If (defText.Text = "<Scale>" Or defText.Text = "Scale") Then
                  Return defText
            End If
      Next
      Return Nothing
End Function
Message 13 of 13
swaveck.keller
in reply to: k14348

INVENTOR 2018 Has this, do you know if they imbed this script and run it with external triggers? Or is it part of the new 2018 code?

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

Post to forums  

Autodesk Design & Make Report