Add Scale to Titleblock for first view on each drawing sheet on single .idw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to develop a rule to ad the scale from the 1st view on each drawing sheet in a single .idw to the titleblock. I typically have up to 8 sheets per .idw so I made the rule go up to 10 sheets. I have the 1st part working if I suppress the rule where the sheets don't exist. The 1st part of the rule is going to create an custom iProperty called Scale1, Scale2, etc..the number will match the sheet number.
How would I correct the code so that it will work correctly if there are sheets that don't exist.
Public Sub Main()
On Error Resume Next
'Get the drawing document
Dim oDrawingDoc As Inventor.DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
'Dim oErrResponse As VbMsgBoxResult
If Err.number <> 0 Then
MsgBox("Active document must be a drawing", vbExclamation, "Error")
Exit Sub
End If
'Sheet 1 - get scale from 1st view
Dim oSheet1 As Inventor.Sheet
oSheet1 = oDrawingDoc.Sheets.Item(1)
'Sheet 1 - Get the first view
Dim oView1 As Inventor.DrawingView
oView1 = oSheet1.DrawingViews.Item(1)
If Err.number <> 0 Then
Resume Next
Exit Sub
End If
'Sheet 1 - Get the view scale string
Dim sScaleText1 As String
sScaleText1 = oView1.ScaleString
'Sheet 2 - get scale from 1st view
Dim oSheet2 As Inventor.Sheet
oSheet2 = oDrawingDoc.Sheets.Item(2)
'Sheet 2 - Get the first view
Dim oView2 As Inventor.DrawingView
oView2 = oSheet2.DrawingViews.Item(1)
If Err.number <> 0 Then
Resume Next
Exit Sub
End If
'Sheet - 2 Get the view scale string
Dim sScaleText2 As String
sScaleText2 = oView2.ScaleString
'Sheet 3 - get scale from 1st view
Dim oSheet3 As Inventor.Sheet
oSheet3 = oDrawingDoc.Sheets.Item(3)
'Sheet 3 - Get the first view
Dim oView3 As Inventor.DrawingView
oView3 = oSheet3.DrawingViews.Item(1)
If Err.number <> 0 Then
Resume Next
Exit Sub
End If
'Sheet - 3 Get the view scale string
Dim sScaleText3 As String
sScaleText3 = oView3.ScaleString
'Sheet 4 - get scale from 1st view
Dim oSheet4 As Inventor.Sheet
oSheet4 = oDrawingDoc.Sheets.Item(4)
'Sheet 4 - Get the first view
Dim oView4 As Inventor.DrawingView
oView4 = oSheet4.DrawingViews.Item(1)
If Err.number <> 0 Then
Resume Next
Exit Sub
End If
'Sheet - 4 Get the view scale string
Dim sScaleText4 As String
sScaleText4 = oView4.ScaleString
'Sheet 5 - get scale from 1st view
Dim oSheet5 As Inventor.Sheet
oSheet5 = oDrawingDoc.Sheets.Item(5)
'Sheet 5 - Get the first view
Dim oView5 As Inventor.DrawingView
oView5 = oSheet5.DrawingViews.Item(1)
If Err.number <> 0 Then
Resume Next
Exit Sub
End If
'Sheet - 5 Get the view scale string
Dim sScaleText5 As String
sScaleText5 = oView5.ScaleString
'Sheet 6 - get scale from 1st view
Dim oSheet6 As Inventor.Sheet
oSheet6 = oDrawingDoc.Sheets.Item(6)
'Sheet 6 - Get the first view
Dim oView6 As Inventor.DrawingView
oView6 = oSheet6.DrawingViews.Item(1)
If Err.number <> 0 Then
Resume Next
Exit Sub
End If
'Sheet - 6 Get the view scale string
Dim sScaleText6 As String
sScaleText6 = oView6.ScaleString
' 'Sheet 7 - get scale from 1st view
' Dim oSheet7 As Inventor.Sheet
' oSheet7 = oDrawingDoc.Sheets.Item(7)
'
' 'Sheet 7 - Get the first view
' Dim oView7 As Inventor.DrawingView
' oView7 = oSheet7.DrawingViews.Item(1)
' If Err.number <> 0 Then
' Resume Next
' Exit Sub
' End If
'
' 'Sheet - 7 Get the view scale string
' Dim sScaleText7 As String
' sScaleText7 = oView7.ScaleString
'
' 'Sheet 8 - get scale from 1st view
' Dim oSheet8 As Inventor.Sheet
' oSheet8 = oDrawingDoc.Sheets.Item(8)
'
' 'Sheet 8 - Get the first view
' Dim oView8 As Inventor.DrawingView
' oView8 = oSheet8.DrawingViews.Item(1)
' If Err.number <> 0 Then
' Resume Next
' Exit Sub
' End If
'
' 'Sheet - 8 Get the view scale string
' Dim sScaleText8 As String
' sScaleText8 = oView8.ScaleString
'
' 'Sheet 9 - get scale from 1st view
' Dim oSheet9 As Inventor.Sheet
' oSheet9 = oDrawingDoc.Sheets.Item(9)
'
' 'Sheet 9 - Get the first view
' Dim oView9 As Inventor.DrawingView
' oView9 = oSheet9.DrawingViews.Item(1)
' If Err.number <> 0 Then
' Resume Next
' Exit Sub
' End If
'
' 'Sheet - 9 Get the view scale string
' Dim sScaleText9 As String
' sScaleText9 = oView9.ScaleString
'
' 'Sheet 10 - get scale from 1st view
' Dim oSheet10 As Inventor.Sheet
' oSheet10 = oDrawingDoc.Sheets.Item(10)
'
' 'Sheet 10 - Get the first view
' Dim oView10 As Inventor.DrawingView
' oView10 = oSheet10.DrawingViews.Item(1)
' If Err.number <> 0 Then
' Resume Next
' Exit Sub
' End If
'
' 'Sheet - 10 Get the view scale string
' Dim sScaleText10 As String
' sScaleText10 = oView10.ScaleString
'Get the custom propertyset
Dim oCustomPropSet As Inventor.PropertySet
oCustomPropSet = oDrawingDoc.PropertySets.Item("Inventor User Defined Properties")
'Get the "Scale" custom iproperty. If it doesn't exist, we'll create it
Dim oScaleProp1 As Inventor.Property
oScaleProp1 = oCustomPropSet.Item("Scale1")
If Err.number <> 0 Then
oScaleProp1 = oCustomPropSet.Add("", "Scale1")
End If
oScaleProp1.Value = sScaleText1
Dim oScaleProp2 As Inventor.Property
oScaleProp2 = oCustomPropSet.Item("Scale2")
If Err.number <> 0 Then
oScaleProp2 = oCustomPropSet.Add("", "Scale2")
End If
oScaleProp2.Value = sScaleText2
Dim oScaleProp3 As Inventor.Property
oScaleProp3 = oCustomPropSet.Item("Scale3")
If Err.number <> 0 Then
oScaleProp3 = oCustomPropSet.Add("", "Scale3")
End If
oScaleProp3.Value = sScaleText3
Dim oScaleProp4 As Inventor.Property
oScaleProp4 = oCustomPropSet.Item("Scale4")
If Err.number <> 0 Then
oScaleProp4 = oCustomPropSet.Add("", "Scale4")
End If
oScaleProp4.Value = sScaleText4
Dim oScaleProp5 As Inventor.Property
oScaleProp5 = oCustomPropSet.Item("Scale5")
If Err.number <> 0 Then
oScaleProp5 = oCustomPropSet.Add("", "Scale5")
End If
oScaleProp5.Value = sScaleText5
Dim oScaleProp6 As Inventor.Property
oScaleProp6 = oCustomPropSet.Item("Scale6")
If Err.number <> 0 Then
oScaleProp6 = oCustomPropSet.Add("", "Scale6")
End If
oScaleProp6.Value = sScaleText6
Dim oScaleProp7 As Inventor.Property
oScaleProp7 = oCustomPropSet.Item("Scale7")
If Err.number <> 0 Then
oScaleProp7 = oCustomPropSet.Add("", "Scale7")
End If
oScaleProp7.Value = sScaleText7
Dim oScaleProp8 As Inventor.Property
oScaleProp8 = oCustomPropSet.Item("Scale8")
If Err.number <> 0 Then
oScaleProp8 = oCustomPropSet.Add("", "Scale8")
End If
oScaleProp8.Value = sScaleText8
Dim oScaleProp9 As Inventor.Property
oScaleProp9 = oCustomPropSet.Item("Scale9")
If Err.number <> 0 Then
oScaleProp9 = oCustomPropSet.Add("", "Scale9")
End If
oScaleProp9.Value = sScaleText9
Dim oScaleProp10 As Inventor.Property
oScaleProp10 = oCustomPropSet.Item("Scale10")
If Err.number <> 0 Then
oScaleProp10 = oCustomPropSet.Add("", "Scale10")
End If
oScaleProp10.Value = sScaleText10
'Update the drawing. This will update the title block scale
oDrawingDoc.Update
End Sub
Once this part is fixed, I will be implementing this rule found here, replace a text box in the titlebock with iProperty. It will be a tad tricky as I will have to write it so that the drawing sheet number will grab the correct custom iProperty then insert it into the titleblock. ( drawingsheet:3 will grab iProp Scale3 etc....)
thanks!
Product Designer at Teksign Inc.
Inventor 2016 SP1
Dell Precision 3660
i7-12700 @ 2.40GHz-4.90GHz
32GB DDR5 4400MHz RAM
NIVDIA RTX A2000 6GB