- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I could some assistance with the following code. The program updates all of the views on all sheets properly.
However, I would like the option to process the current sheet only.
Here is my current code.
Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document oModel = ThisDoc.ModelDocument Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView oSheets = oDoc.Sheets If question1=vbNo Then For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews 'make view label visible If oView.ViewType = 10501 Then oView.ShowLabel = True oView.Label.FormattedText = String1 & String2 & "<Br/>" & String4 &"<Br/>" & String3 End If Next Next Else oViews = oSheet.DrawingViews For Each oView In oViews If oView.ViewType = 10501 Then oView.ShowLabel = True oView.Label.FormattedText = String1 & String2 & "<Br/>" & String4 &"<Br/>" & String3 End If Next End If
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I don't see where your question1 is getting it's information from but......below I commented out the lines that you don't need just to show what I changed.
If you only want to work with the current sheet (or active sheet) then you don't need to loop through the Sheets collection. Therefore, I commented out the For / Each loop.
Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document
oModel = ThisDoc.ModelDocument
'Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
'oSheets = oDoc.Sheets
oSheet = oDoc.ActiveSheet
If question1=vbNo Then
' For Each oSheet In oSheets
oViews = oSheet.DrawingViews
For Each oView In oViews
'make view label visible
If oView.ViewType = 10501 Then
oView.ShowLabel = True
oView.Label.FormattedText = String1 & String2 & "<Br/>" & String4 &"<Br/>" & String3
End If
Next
' Next
Else
oViews = oSheet.DrawingViews
For Each oView In oViews
If oView.ViewType = 10501 Then
oView.ShowLabel = True
oView.Label.FormattedText = String1 & String2 & "<Br/>" & String4 &"<Br/>" & String3
End If
Next
End If
Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here's something you can try:
Sub Main
Dim oDoc As DrawingDocument = ThisDoc.Document
oModel = ThisDoc.ModelDocument
Dim oSheets As Sheets
Dim oSheet As Sheet = oDoc.Sheets
Dim oViews As DrawingViews
Dim oView As DrawingView
If MsgBox("All Sheets [Yes] Or ActiveSheet [No]?", vbYesNo + vbQuestion,"") = vbYes Then
For Each oSheet In oSheets
oViews = oSheet.DrawingViews
UpdateLabels(oViews)
Next
Else
oSheet = oDoc.ActiveSheet
oViews = oSheet.DrawingViews
UpdateLabels(oViews)
End If
End Sub
Sub UpdateLabels(oVws As DrawingViews)
For Each oView As DrawingView In oVws
If oView.ViewType = 10501 Then
oView.ShowLabel = True
oView.Label.FormattedText = String1 & String2 & "<Br/>" & String4 &"<Br/>" & String3
End If
Next
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS
or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Randy,
My apologies, I left the code for the question out of my post. I removed the comments and the code works perfectly.
Thank you for the quick response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you as well for posting so quickly. I like your style but for whatever reason, the code errors with the following message.
Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.Sheet'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{206B59AE-22A6-11D4-B7A8-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Here is the code I am using.
Sub Main sFont = "Arial" sFSize1 = 0.3 'font size in cm sFSize2 = 0.3175 'font size in cm String1 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "' Underline='False'> PN: </StyleOverride><StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "' Underline='False'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='43'>PART NUMBER</Property></StyleOverride><StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'> - </StyleOverride>" String3 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'>SCALE: </StyleOverride><StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'><DrawingViewScale/></StyleOverride>" String2 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "' Underline='False'><Property Document='model' PropertySet='Design Tracking Properties' Property='Authority' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='43'>AUTHORITY</Property></StyleOverride><StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'> REQ'D </StyleOverride>" String4 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'><Property Document='model' PropertySet='Design Tracking Properties' Property='Material' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='20'>MATERIAL</Property></StyleOverride><StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'> - </StyleOverride><StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'><Property Document='model' PropertySet='User Defined Properties' Property='G_H' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='7'>G_H</Property></StyleOverride><StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'> THK</StyleOverride>" Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document oModel = ThisDoc.ModelDocument Dim oSheets As Sheets Dim oSheet As Sheet=oDoc.Sheets Dim oViews As DrawingViews Dim oView As DrawingView If MsgBox("All Sheets [Yes] Or ActiveSheet [No]?", vbYesNo + vbQuestion,"") = vbYes Then For Each oSheet In oSheets oViews = oSheet.DrawingViews UpdateLabels(oViews) Next Else oSheet = oDoc.ActiveSheet oViews = oSheet.DrawingViews UpdateLabels(oViews) End If End Sub Sub UpdateLabels(oVws As DrawingViews) For Each oView In oVws If oView.ViewType = 10501 Then oView.ShowLabel = True oView.Label.FormattedText = String1 & String2 & "<Br/>" & String4 &"<Br/>" & String3 End If Next End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You're right. I see it very clearly now this morning. It's right near the top where we are creating the variables. We need to change this:
Dim oSheets As Sheets
Dim oSheet As Sheet=oDoc.Sheets
Dim oViews As DrawingViews
Dim oView As DrawingView
to this:
Dim oSheets As Sheets = oDoc.Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Apparently I accidentally put that Value behind the wrong variable, so it was thinking we were trying to set a Sheet type variable to a Sheets type value, which caused the error. Hopefully that fixes the error and there aren't any others. Sorry about that. ![]()
Wesley Crihfield
(Not an Autodesk Employee)