Message 1 of 8
A crude Where-used to string Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am posting this in hopes that the community can share with me a better way.
Goal: to get the where used assembly from whatever is opened in a drawing. the code is launched from the drawing and it gets the information.
how: it is launched from an external Rule. you need two different rules.
first one that you will actually launch, can be named whatever you want that rule to be called. Launch it from a drawing and see how this works:
' opens the model attached
Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = sheet.DrawingViews.Item(1)
Dim refDoc As Document = ThisApplication.Documents.Open(view.ReferencedFile.FullFileName)
Dim oFileName As String = ThisDoc.ModelDocument.FullFileName
Dim oFInfo As New IO.FileInfo(oFileName)
If oFInfo.IsReadOnly Then
MsgBox("File is ReadOnly check out all the Models before attempting")
refDoc.Close()
Exit Sub
End If
Try
' runs a rule inside the model
iLogicVb.RunExternalRule(refDoc.DisplayName, "where-used-to-custom-property")
Catch
iLogicVb.RunExternalRule("where-used-to-custom-property")
End Try
' saves and closes the model
refDoc.Save()
refDoc.Close()
Dim myparam As String
myparam = iProperties.Value("Custom", "WHERE-USED")
myparam = (Mid(myparam, 10, 9)).Trim
If myparam = "" Then Exit Sub
'pushes value from .idw to .ipt or .iam or vice versa (anything before = is what is being populated)
iProperties.Value("Custom", "Next Assy 1") = myparam
'iProperties.Value("Custom", "WHERE-USED") = "" 'keeping for debug purposes for now.
If iProperties.Value("Custom", "Next Assy 1") = iProperties.Value("Project", "Part Number") Then
MsgBox("Next Assembly cant be same part number, check again and run code again")
End If
'refresh/update
InventorVb.DocumentUpdate()
second rule name it like this: where-used-to-custom-property
Imports System.Windows.Forms
Sub Main()
Dim fso As Object
Dim tabCtl As TabControl
Dim ctlCurrent As Control
Dim intPageNum As Integer
fso = CreateObject("Scripting.FileSystemObject")
ThisApplication.UserInterfaceManager.UserInteractionDisabled = False
p = "WHERE-USED"
Try : x = iProperties.Value("Custom", p) : Catch : iProperties.Value("Custom", p) = "" : End Try
'Line1 :
ThisApplication.CommandManager.ControlDefinitions.Item("VaultShowDetailsTop").Execute2(False)
'vault1 = ThisApplication.CommandManager.ControlDefinitions.Item("VaultShowDetailsTop").Parent.ActiveCommand
'System.Windows.Forms.form.ActiveForm.Activate
'Dim afName As String = Form.ActiveForm.Name
'With vault1
'SendKeys.SendWait("{END}" & "{TAB}" & "{TAB}" & "{TAB}" & "{TAB}" & "{DOWN}" & "^c" & "% " & "{up}" & "{enter}")
SendKeys.SendWait("{END}" & "+{TAB}" & "{DOWN}" & "^c" & "% " & "{up}" & "{enter}")
'control.ActivateTab "Where Used"
'SelectTab = 1
'MsgBox(selectedtab)
' List all controls on the tab control in the Debug window.
iProperties.Value("Custom", p) = Clipboard.GetText
'End With
a = iProperties.Value("Custom", p)
'If Clipboard.ContainsText Then
' Exit Sub
'End If
'GoTo Line1
Dim TXT2Find As String = "File Name Folder Path"
Dim NewTXT As String = ""
If a Like NewTXT Then
MsgBox("nothing changed")
Exit Sub
Else
a = Replace(a, TXT2Find, NewTXT)
'a = Replace(a, subjectString, vbCrLf)
'inputbox(replace$(subjectString, vbCrLf & vbCrLf, vbCrLf))
iProperties.Value("Custom", p) = a
End If
ThisApplication.CommandManager.StopActiveCommand
'iLogicVb.RunExternalRule("esc")
SendKeys.SendWait("{ESC}")
End Sub