A crude Where-used to string Solution

A crude Where-used to string Solution

maxim.teleguz
Advocate Advocate
447 Views
7 Replies
Message 1 of 8

A crude Where-used to string Solution

maxim.teleguz
Advocate
Advocate

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

 

0 Likes
448 Views
7 Replies
Replies (7)
Message 2 of 8

maxim.teleguz
Advocate
Advocate

@Curtis_Waguespack any help will be most welcome

0 Likes
Message 3 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @maxim.teleguz 

 

I set up the 2 external rules and ran this on a simple drawing and it crashed Inventor (no worries, I didn't have any unsaved work open). In looking at the code, I see that there are some Vault calls involved. Unfortunately, I don't have a vault set up on this computer at the moment, and therefore I can't really investigate much further. 

 

It looks interesting though! 

 

I'm sure someone else will be able to have a look.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
 

EESignature

Message 4 of 8

maxim.teleguz
Advocate
Advocate

Yes It does need Vault for it to work. Thank you for trying to help. (surprised you dont have vault considering how much you helped the community)

0 Likes
Message 5 of 8

matt_jlt
Collaborator
Collaborator

Hi, i know its probably a bit late but here is a script i wrote to access the vault-where used for a drawing.

It uses the vault api / no send keys stuff and has been very reliable for me. I use it daily on different vaults with no issues. Hopefully it helps you / at least gives you another way to achieve the same task.

 

https://github.com/mattjlt/Inventor-Code-Library/blob/master/Scripts/VAULT_Where%20Used.iLogicVb

 

 

 

Message 6 of 8

maxim.teleguz
Advocate
Advocate

the goal here is to spark some development in this area. We really need a where-used to iproperties function. 

Any research shared is going to eventually lead to some great things for everyone. Thank you!

0 Likes
Message 7 of 8

maxim.teleguz
Advocate
Advocate

would you happen to know what type of error this is:

 

Error on Line 6 : Character is not valid.
Error on Line 63 : Type 'ACW.File' is not defined.
Error on Line 76 : Type 'acw.FileAssocLite' is not defined.
Error on Line 126 : Type 'ACW.File' is not defined.
Error on Line 135 : Type 'ACW.File' is not defined.

0 Likes
Message 8 of 8

matt_jlt
Collaborator
Collaborator

Hi, sorry about the errors. I had only tested that code out on Inventor 2019. Testing it out on 2021 shows there are some issues with it. I will try and fix them soon and will re-post.