- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am stuck on a code issue. I need a sheet name pushed to a prompted entry in the Titleblock. I have a rule that updates the sheet name from the filename of the baseview item. I have a need to change some of the sheetnames to other names because of a sequencing requirement of the assembly (They are curtain wall window units and a single assembly can be used for multiple unit locations and the sheet name needs to represent that location, or address as it is referred to in the existing code.) The code works great until it gets to the part to push the value to the UpdateUnitAddress Function. If I comment that out, all works prefect without pushing the value. Any help would be appreciated. The text in red is where it halts.
Sub Main() 'Set Number of Addresses for Unit in Overall Assembly Dim NumberOfUnits = InputBox("Enter quantity of Units required:", "Units Required") 'Check that we are in a drawing document. If ThisDoc.Document.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then 'Get a reference to the current drawing. Dim dwgDoc As DrawingDocument = ThisDoc.Document 'Check that we have atleast one view on the sheet. If dwgDoc.ActiveSheet.DrawingViews.Count > 0 Then 'Get a reference to the original model in the view. Dim compDoc As Document = dwgDoc.ActiveSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument 'Get the filename of the replacement model Dim newFileName As String = GetNewReference() 'Sub to show dialog and get file name. 'Open the replacement model. Dim newFile As Document If Not String.IsNullOrEmpty(newFileName) Then 'If Not String.IsNullOrEmpty(compDoc) Then Try newFile = ThisApplication.Documents.Open(newFileName, False) 'newFile = ThisApplication.Documents.Open(compDoc, False) Catch MessageBox.Show("Could not open target file.") End Try 'Check to see if we have valid documents to work with. If Not newFile Is Nothing Then Dim okContinue As Boolean = True If Not newFile.InternalName = compDoc.InternalName Then 'Display warning if inner names of models do not math. msgResult = MessageBox.Show("Warning, files do not match." & vbCrLf & " Results can be unpredictable." & vbCrLf & _ "Do you want To Continue", "Copy/Replace Sheet", MessageBoxButtons.YesNo) If Not msgResult = DialogResult.Yes Then okContinue = False End If End If If okContinue Then Dim newDwg As DrawingDocument Try 'Create the new drawing document. newDwg = ThisApplication.Documents.Add(kDrawingDocumentObject, Nothing, False) 'Copy the active sheet to the new document. Dim newSheet As Sheet = dwgDoc.ActiveSheet.CopyTo(newDwg) 'Replace the model reference on the new sheet with the replacement reference newSheet.DrawingViews(1).ReferencedDocumentDescriptor. _ ReferencedFileDescriptor.ReplaceReference(newFileName) 'rename Active Sheet to Unit Address dwgDoc.ActiveSheet.Name = "_" & InputBox("Enter Unit Address", "Unit Address") UpdateUnitAddress() Dim i As Long = 0 For i = 1 To NumberOfUnits - 1 'Copy the sheet back to the original drawing. Dim copiedSheet As Sheet = newSheet.CopyTo(dwgDoc) copiedSheet.Name = "_" & InputBox("Enter Unit Address", "Unit Address") Next newDwg.Close(True) 'Activate the new sheet. 'copiedSheet.Activate() InventorVb.DocumentUpdate() Catch MessageBox.Show("Error occurred copying sheet.") End Try End If End If End If End If End If iLogicVb.RunRule("ResetSectionViewCallout_Rule") End Sub Function UpdateUnitAddress() As String Dim dwgDoc2 As DrawingDocument = ThisDoc.Document Dim oPromptEntry Dim actSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet ActiveSheet = ThisDrawing.Sheet(actSheet.Name) oTitleBlock=actSheet.TitleBlock oTextBoxes=oTitleBlock.Definition.Sketch.TextBoxes For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes Select oTextBox.Text Case "Unit Address" : oPromptEntry = dwgDoc2.ActiveSheet.Name MessageBox.Show("Phase1.") 'oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry) Call oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry) MessageBox.Show("Phase2.") End Select Next MessageBox.Show("Phase3.") 'actSheet.Activate 'InventorVb.DocumentUpdate() End Function Function GetNewReference() As String ' Create a new FileDialog object. Dim oFileDlg As Inventor.FileDialog Call ThisApplication.CreateFileDialog(oFileDlg) ' Define the filter to select part and assembly files or any file. oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*" ' Define the part and assembly files filter to be the default filter. oFileDlg.FilterIndex = 1 ' Set the title for the dialog. oFileDlg.DialogTitle = "Copy/Replace Sheet - Select Replacement Model" ' Set the initial directory that will be displayed in the dialog. oFileDlg.InitialDirectory = ThisDoc.Path ' Set the flag so an error will be raised if the user clicks the Cancel button. oFileDlg.CancelError = True ' Show the open dialog. The same procedure is also used for the Save dialog. ' The commented code can be used for the Save dialog. Try oFileDlg.ShowOpen Catch 'MessageBox.Show("User cancelled out of dialog", "Replace Reference") Finally If Not oFileDlg.FileName = "" Then 'MessageBox.Show("File " & oFileDlg.FileName & " was selected.", "Replace Reference") GetNewReference = oFileDlg.FileName End If End Try End Function
Scott Hallmark, Design Specialist | Fluor Corporation
Inventor and AutoCAD Certified Professional, Autodesk Certified Instructor | My Plant3D Notes | AU Speaker | ROLL TIDE!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Scott.Hallmark,
It works for me as long as I have a prompted entry in my title block that is labeled Unit Address....
rather than <Unit Address> with carets.
The result I see is the sheet name and the prompted entry are replaced with an underscore ,the Unit Address entered, and the sheet number preceded by a colon, example: _5555:1 , where 5555 is what I entered for unit address.
I see no error, and I don't see it put the selected model name in the sheet name... I'm not certain the expected result, but I'm guessing the result should be Filename_UnitAddress:SheetNumber , such as NG123_5555:1
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I don't get it. It halts and gives me the "Error occurred copying sheet." that I have in my Catch. It hits the "Phase1" message box, then the error message box. no copied sheets and no updated Unit Address. I will keep looking at it. Thank you.
Scott Hallmark, Design Specialist | Fluor Corporation
Inventor and AutoCAD Certified Professional, Autodesk Certified Instructor | My Plant3D Notes | AU Speaker | ROLL TIDE!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working now. For some reason, I had to change my Prompted Entry to <Unit Address> and update the code accordingly. Once that was done, it worked perfectly. Last thing I need to do it remove the :SheetNumber off the end of Prompted Entry in the TB. If you have a quick code, that's great. Otherwise, I will begin my search.
Thanks again for confirming!
Scott Hallmark, Design Specialist | Fluor Corporation
Inventor and AutoCAD Certified Professional, Autodesk Certified Instructor | My Plant3D Notes | AU Speaker | ROLL TIDE!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Looking at the Object Browser Sheet>TitleBlock is read-only... could that have something to do with it? This sounds like a lot of work but could you delete the titleblock and insert a new block with your prompted entry?
Mass Override for Each Model State
Custom Glyph Icon for iMates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Scott.Hallmark,
Something like this will work.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
dwgDoc = ThisDoc.Document
oSheetName = dwgDoc.ActiveSheet.Name
'split the name into a string array using colon
Dim sSplit As String() = oSheetName.Split(New Char() {":"c})
'get the first member of array
oSheetName = sSplit(0)
MessageBox.Show(oSheetName, "SheetName")
'get the second member of array
oSheetNumber = sSplit(1)
MessageBox.Show(oSheetNumber, "SheetNumber")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Looks like you have to edit the titleblock drawing Definition... something like this
Dim dwgDoc2 As DrawingDocument = ThisDoc.Document
Dim oPromptEntry As String
Dim actSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
ActiveSheet = ThisDrawing.Sheet(actSheet.Name)
Dim oTitleBlock As TitleBlock = actSheet.TitleBlock
Dim oBlockSketch As DrawingSketch
oPromptEntry = dwgDoc2.ActiveSheet.Name
Call oTitleBlock.Definition.Edit(oBlockSketch)
oTextBoxes=oBlockSketch.TextBoxes
For Each oTextBox In oTextBoxes
Select oTextBox.Text
Case "Unit Address"
MessageBox.Show("Phase1.")
MessageBox.Show (oPromptEntry)
oOrgText = oTextBox.FormattedText
oNewText = Replace(oOrgText, "Unit Address", oPromptEntry)
oTextBox.FormattedText = oNewText
MessageBox.Show("Phase2.")
End Select
Next
oTitleBlock.Definition.ExitEdit
MessageBox.Show("Phase3.") It needs cleaned up a bit but you seem able
Mass Override for Each Model State
Custom Glyph Icon for iMates